salabim 24.0.9.post0__py3-none-any.whl → 24.0.10.post0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
salabim/salabim.py CHANGED
@@ -1,13 +1,13 @@
1
- # _ _ _ ____ _ _ ___ ___
2
- # ___ __ _ | | __ _ | |__ (_) _ __ ___ |___ \ | || | / _ \ / _ \
3
- # / __| / _` || | / _` || '_ \ | || '_ ` _ \ __) || || |_ | | | | | (_) |
4
- # \__ \| (_| || || (_| || |_) || || | | | | | / __/ |__ _| _ | |_| | _ \__, |
5
- # |___/ \__,_||_| \__,_||_.__/ |_||_| |_| |_| |_____| |_| (_) \___/ (_) /_/
1
+ # _ _ _ ____ _ _ ___ _ ___
2
+ # ___ __ _ | | __ _ | |__ (_) _ __ ___ |___ \ | || | / _ \ / | / _ \
3
+ # / __| / _` || | / _` || '_ \ | || '_ ` _ \ __) || || |_ | | | | | || | | |
4
+ # \__ \| (_| || || (_| || |_) || || | | | | | / __/ |__ _| _ | |_| | _ | || |_| |
5
+ # |___/ \__,_||_| \__,_||_.__/ |_||_| |_| |_| |_____| |_| (_) \___/ (_)|_| \___/
6
6
  # discrete event simulation
7
7
  #
8
8
  # see www.salabim.org for more information, the documentation and license information
9
9
 
10
- __version__ = "24.0.9"
10
+ __version__ = "24.0.10"
11
11
 
12
12
  import heapq
13
13
  import random
@@ -59,7 +59,7 @@ Windows = sys.platform.startswith("win")
59
59
  PyDroid = sys.platform == "linux" and any("pydroid" in v for v in os.environ.values())
60
60
  PyPy = platform.python_implementation() == "PyPy"
61
61
  Chromebook = "penguin" in platform.uname()
62
- PythonInExcel = not ("__file__" in globals())
62
+ PythonInExcel = not ("__file__" in globals()) or ("REF" in globals()) # REF is for AnacondaCode
63
63
 
64
64
 
65
65
  def a_log(*args):
@@ -445,10 +445,8 @@ class Monitor:
445
445
  *args,
446
446
  **kwargs,
447
447
  ):
448
- if env is None:
449
- self.env = g.default_env
450
- else:
451
- self.env = env
448
+ self.env = _set_env(env)
449
+
452
450
  if isinstance(self.env, Environment):
453
451
  _set_name(name, self.env._nameserializeMonitor, self)
454
452
  else:
@@ -855,8 +853,10 @@ class Monitor:
855
853
  else:
856
854
  stop += self.env._offset
857
855
  stop_action = "b" # non inclusive
858
-
859
- stop = min(stop, self.env._now - self.env._offset) # not self.now() in order to support frozen monitors
856
+ if self.env._animate:
857
+ stop=min(stop,self.env._t)
858
+ else:
859
+ stop = min(stop, self.env._now - self.env._offset) # not self.now() in order to support frozen monitors
860
860
  actions.append((start, "a", 0, 0))
861
861
  actions.append((stop, stop_action, 0, 0))
862
862
  else:
@@ -888,8 +888,33 @@ class Monitor:
888
888
  new._x.append(curx)
889
889
 
890
890
  enabled = False
891
+ if self.env._animate:
892
+ _x=self._x[:]
893
+ _t=self._t[:]
894
+ if self._x:
895
+ _x.append(self._x[-1])
896
+ _t.append(self.env._t)
897
+ if isinstance(self._weight,bool):
898
+ _weight=self._weight
899
+ else:
900
+ _weight=self._weight[:]
901
+ _weight.append(self._weight[-1])
902
+ else:
903
+ _x=self._x
904
+ _t=self._t
905
+ _weight=self._weight
906
+
907
+
908
+ if self.env._animate:
909
+ if self._x:
910
+ _x.append(_x[-1])
911
+ _t.append(self.env._t)
912
+ try:
913
+ _weight.append(self.weight[-1])
914
+ except AttributeError:
915
+ ... # ignore if bool
891
916
  for t, type, x, weight in heapq.merge(
892
- actions, zip(self._t, itertools.repeat("c"), self._x, self._weight if (self._weight and not self._level) else (1,) * len(self._x))
917
+ actions, zip(self._t, itertools.repeat("c"), _x, _weight if (_weight and not self._level) else (1,) * len(_x))
893
918
  ):
894
919
  if new._level:
895
920
  if type == "a":
@@ -4293,10 +4318,8 @@ class Queue:
4293
4318
  """
4294
4319
 
4295
4320
  def __init__(self, name: str = None, monitor: Any = True, fill: Iterable = None, capacity: float = inf, env: "Environment" = None, *args, **kwargs) -> None:
4296
- if env is None:
4297
- self.env = g.default_env
4298
- else:
4299
- self.env = env
4321
+ self.env = _set_env(env)
4322
+
4300
4323
  _set_name(name, self.env._nameserializeQueue, self)
4301
4324
  self._head = Qmember()
4302
4325
  self._tail = Qmember()
@@ -5819,7 +5842,8 @@ class Animate3dBase(DynamicClass):
5819
5842
  self, visible: bool = True, keep: bool = True, arg: Any = None, layer: float = 0, parent: "Component" = None, env: "Environment" = None, **kwargs
5820
5843
  ) -> None:
5821
5844
  super().__init__()
5822
- self.env = g.default_env if env is None else env
5845
+ self.env = _set_env(env)
5846
+
5823
5847
  self.visible = visible
5824
5848
  self.keep = keep
5825
5849
  self.arg = self if arg is None else arg
@@ -7063,10 +7087,8 @@ class Component:
7063
7087
  env: "Environment" = None,
7064
7088
  **kwargs,
7065
7089
  ):
7066
- if env is None:
7067
- self.env = g.default_env
7068
- else:
7069
- self.env = env
7090
+ self.env = _set_env(env)
7091
+
7070
7092
  _set_name(name, self.env._nameserializeComponent, self)
7071
7093
  self._qmembers = {}
7072
7094
  self._process = None
@@ -14673,7 +14695,7 @@ class Environment:
14673
14695
  if self._last_animate != self._animate or self._last_paused != self._paused:
14674
14696
  for key in self._ui_window.key_dict:
14675
14697
  field = self._ui_window[key]
14676
- if type(field) != sg.PySimpleGUI.HorizontalSeparator:
14698
+ if type(field) != sg.HorizontalSeparator:
14677
14699
  if self._paused:
14678
14700
  field.update(visible=True)
14679
14701
  else:
@@ -14850,9 +14872,10 @@ class Animate2dBase(DynamicClass):
14850
14872
  screen_coordinates = locals_["screen_coordinates"]
14851
14873
  over3d = locals_["over3d"]
14852
14874
 
14853
- self.env = g.default_env if env is None else env
14875
+ self.env = _set_env(env)
14876
+
14854
14877
  self.sequence = self.env.serialize()
14855
- self.arg = self if arg in (None, object) else arg
14878
+ self.arg = self if arg in (None, object) else arg
14856
14879
  self.over3d = _default_over3d if over3d is None else over3d
14857
14880
  self.screen_coordinates = screen_coordinates
14858
14881
  self.attached_to = attached_to
@@ -15930,7 +15953,8 @@ class Animate:
15930
15953
  animation_to: float = inf,
15931
15954
  env: "Environment" = None,
15932
15955
  ):
15933
- self.env = g.default_env if env is None else env
15956
+ self.env = _set_env(env)
15957
+
15934
15958
  self._image_ident = None # denotes no image yet
15935
15959
  self._image = None
15936
15960
  self._image_x = 0
@@ -17052,7 +17076,8 @@ class AnimateEntry:
17052
17076
  env: "Environment" = None,
17053
17077
  xy_anchor: str = "sw",
17054
17078
  ):
17055
- self.env = g.default_env if env is None else env
17079
+ self.env = _set_env(env)
17080
+
17056
17081
  self.env.ui_objects.append(self)
17057
17082
  self.type = "entry"
17058
17083
  self.value = value
@@ -17197,7 +17222,8 @@ class AnimateButton:
17197
17222
  env: "Environment" = None,
17198
17223
  xy_anchor: str = "sw",
17199
17224
  ):
17200
- self.env = g.default_env if env is None else env
17225
+ self.env = _set_env(env)
17226
+
17201
17227
  self.type = "button"
17202
17228
  self.t0 = -inf
17203
17229
  self.t1 = inf
@@ -17378,7 +17404,7 @@ class AnimateSlider:
17378
17404
  labelcolor: ColorType = None, # only for backward compatibility
17379
17405
  layer: float = None, # only for backward compatibility
17380
17406
  ):
17381
- self.env = g.default_env if env is None else env
17407
+ self.env = _set_env(env)
17382
17408
  n = round((vmax - vmin) / resolution) + 1
17383
17409
  self.vmin = vmin
17384
17410
  self.vmax = vmin + (n - 1) * resolution
@@ -22640,10 +22666,7 @@ class State:
22640
22666
  """
22641
22667
 
22642
22668
  def __init__(self, name: str = None, value: Any = False, type: str = "any", monitor: bool = True, env: "Environment" = None, *args, **kwargs):
22643
- if env is None:
22644
- self.env = g.default_env
22645
- else:
22646
- self.env = env
22669
+ self.env = _set_env(env)
22647
22670
  _set_name(name, self.env._nameserializeState, self)
22648
22671
  self._value = value
22649
22672
  with self.env.suppress_trace():
@@ -23118,11 +23141,7 @@ class Resource:
23118
23141
  *args,
23119
23142
  **kwargs,
23120
23143
  ):
23121
- if env is None:
23122
- self.env = g.default_env
23123
- else:
23124
- self.env = env
23125
-
23144
+ self.env = _set_env(env)
23126
23145
  if initial_claimed_quantity != 0:
23127
23146
  if not anonymous:
23128
23147
  raise ValueError("initial_claimed_quantity != 0 only allowed for anonymous resources")
@@ -23651,10 +23670,8 @@ class PeriodMonitor:
23651
23670
 
23652
23671
  def __init__(self, parent_monitor: "Monitor", periods: Iterable = None, period_monitor_names: Iterable = None, env: "Environment" = None):
23653
23672
  self.pc = _PeriodComponent(pm=self, skip_standby=True, suppress_trace=True)
23654
- if env is None:
23655
- self.env = g.default_env
23656
- else:
23657
- self.env = env
23673
+ self.env = _set_env(env)
23674
+
23658
23675
  if periods is None:
23659
23676
  periods = 24 * [1]
23660
23677
  self.periods = periods
@@ -26931,6 +26948,21 @@ def reset() -> None:
26931
26948
  random_seed() # always start with seed 1234567
26932
26949
 
26933
26950
 
26951
+ def _set_env(env):
26952
+ """
26953
+ returns g._default_env if env is None
26954
+ returns env, otherwise
26955
+
26956
+ will raise a ValueError if g.default_env is None (nit initialized)
26957
+ """
26958
+
26959
+ if env is None:
26960
+ if g.default_env is None:
26961
+ raise ValueError("no default environment. Did yout forget to call sim.Environment()?")
26962
+ return g.default_env
26963
+ return env
26964
+
26965
+
26934
26966
  App = Environment
26935
26967
 
26936
26968
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: salabim
3
- Version: 24.0.9.post0
3
+ Version: 24.0.10.post0
4
4
  Summary: salabim - discrete event simulation in Python
5
5
  Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
6
6
  Project-URL: Homepage, https://salabim.org
@@ -46,11 +46,11 @@ In contrast to some other Python DES packages, salabim does not require the use
46
46
  ### Features and documentation
47
47
 
48
48
  - Cross-platform support: salabim runs on Windows, macOS, Linux, iOS/iPadOS (Pythonista), and can even be used with "Python In Excel".
49
- - Comprehensive documentation: Visit https://www.salabim.org/manual for detailed documentation.
49
+ - Comprehensive documentation: Visit [www.salabim.org/manual](www.salabim.org/manual) for detailed documentation.
50
50
 
51
51
  ### Resources
52
52
 
53
- The salabim package can be found on GitHub: https://www.github.com/salabim/salabim
53
+ The salabim package can be found on GitHub: www.github.com/salabim/salabim
54
54
 
55
55
  And on PyPI: https://pypi.org/project/salabim/
56
56
 
@@ -0,0 +1,10 @@
1
+ salabim/DejaVuSansMono.ttf,sha256=Z_oIXp5yp1Zaw2y2p3vaxwHhjHpG0MFbmwhxSh4aIEI,335068
2
+ salabim/LICENSE.txt,sha256=qHlBa-POyexatCxDTjSKMlYtkBFQDn9lu-YV_1L6V0U,1106
3
+ salabim/__init__.py,sha256=r7qPLvlmX0dkZDyjuTo8Jo3ex3sD1L4pmK6K5ib9vyw,56
4
+ salabim/calibri.ttf,sha256=RWpf8Uo31RfvGGNaSt9-2sXSuN87AVE_NFMRsV3LhBk,1330156
5
+ salabim/mplus-1m-regular.ttf,sha256=EuFHr90BJjuAn_r5MleJFN-WfkeWJ4tf7DweI5zr8tU,289812
6
+ salabim/salabim.py,sha256=yxxH3U1Bjvv44M4mmmvgt1WSc_XFUG6IBKkfHwq8Xuc,1097141
7
+ salabim-24.0.10.post0.dist-info/METADATA,sha256=eyCfM0Zj0M8Jd0f-YE3Of8J7Qs7jtAnxGYgMIbh1_ng,3456
8
+ salabim-24.0.10.post0.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
9
+ salabim-24.0.10.post0.dist-info/top_level.txt,sha256=UE6zVlbi3F6T5ma1a_5TrojMaF21GYKDt9svvm0U4cQ,8
10
+ salabim-24.0.10.post0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.3.0)
2
+ Generator: setuptools (72.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- salabim/DejaVuSansMono.ttf,sha256=Z_oIXp5yp1Zaw2y2p3vaxwHhjHpG0MFbmwhxSh4aIEI,335068
2
- salabim/LICENSE.txt,sha256=qHlBa-POyexatCxDTjSKMlYtkBFQDn9lu-YV_1L6V0U,1106
3
- salabim/__init__.py,sha256=r7qPLvlmX0dkZDyjuTo8Jo3ex3sD1L4pmK6K5ib9vyw,56
4
- salabim/calibri.ttf,sha256=RWpf8Uo31RfvGGNaSt9-2sXSuN87AVE_NFMRsV3LhBk,1330156
5
- salabim/mplus-1m-regular.ttf,sha256=EuFHr90BJjuAn_r5MleJFN-WfkeWJ4tf7DweI5zr8tU,289812
6
- salabim/salabim.py,sha256=q-JgqFxQnIoPg87Ajl1gHGVIFgOurphTsFi1pTSIBeE,1096452
7
- salabim-24.0.9.post0.dist-info/METADATA,sha256=UZ5-iS_aUBGMa3841kRvFZo0xiuNPXrFzSyjH4zoiHY,3445
8
- salabim-24.0.9.post0.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
9
- salabim-24.0.9.post0.dist-info/top_level.txt,sha256=UE6zVlbi3F6T5ma1a_5TrojMaF21GYKDt9svvm0U4cQ,8
10
- salabim-24.0.9.post0.dist-info/RECORD,,