Skip to content

Commit

Permalink
2.3.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
salabim committed Sep 1, 2018
1 parent a23d3f8 commit 560a42b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 31 deletions.
11 changes: 5 additions & 6 deletions Demo queue animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def animation_objects(self, id):
any other value represents the colour
'''
if id == 'text':
ao0 = sim.AnimateText(text=self.name(), textcolor='fg', text_anchor='nw')
ao0 = sim.AnimateText(text=self.name(), textcolor='fg', text_anchor='nw', offsetx=-20)
return 0, 16, ao0
else:
ao0 = sim.AnimateRectangle((-20, 0, 20, 20),
Expand All @@ -40,10 +40,10 @@ def process(self):

q = sim.Queue('queue')

qa0 = sim.AnimateQueue(q, x=100, y=50, title='queue, normal', direction='e', id='blue')
qa1 = sim.AnimateQueue(q, x=100, y=250, title='queue, maximum 6 components', direction='e', max_length=6, id='red')
qa2 = sim.AnimateQueue(q, x=100, y=150, title='queue, reversed', direction='e', reverse=True, id='green')
qa3 = sim.AnimateQueue(q, x=100, y=440, title='queue, text only', direction='s', id='text')
qa0 = sim.AnimateQueue(q, x=100, y=25, title='queue, normal', direction='e', id='blue')
qa1 = sim.AnimateQueue(q, x=100, y=75, title='queue, reversed', direction='e', reverse=True, id='green')
qa2 = sim.AnimateQueue(q, x=100, y=125, title='queue, maximum 6 components', direction='e', max_length=6, id='red')
qa3 = sim.AnimateQueue(q, x=100, y=350, title='queue, text only', direction='s', id='text')

sim.AnimateMonitor(q.length, x=10, y=450, width=480, height=100, horizontal_scale=5, vertical_scale=5)

Expand All @@ -59,4 +59,3 @@ def process(self):
env.animate(True)
env.modelname('Demo queue animation')
env.run()

26 changes: 26 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
salabim changelog

version 2.3.3.2 2018-08-25
===========================
Changed functionality
---------------------
If Environment.run() is given a till or a duration, main will become active at the specified time.
If not, main will become active when there are no more events on the event list. This will be shown
in the trace with 'ends on no events left'.
So, if you don't want a simulation to stop at the moment the event list becomes empty, issue
env.run(sim.inf)
This can particularly be useful if you don't want to stop an animation when there are no events left.


The placement of the title of AnimateQueue() and Queue.animate() when the direction is 'n' or 's' has
been changed. Now the title is always displayed horizontally.


Implementation note
-------------------
Error reporting for AnimateEntry on Pythonista now only when actually animating.


Big fix
-------
On Pythonista, setting env.video parameter without animating, caused a crash. Fixed.


version 2.3.3.1 2018-08-23
===========================
Expand All @@ -15,6 +40,7 @@ supported when running animated. Fixed.

Sometimes an animation object was not removed correctly (under tkinter). Fixed.


version 2.3.3 2018-08-22
=========================
New functionality
Expand Down
69 changes: 44 additions & 25 deletions salabim.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import print_function # compatibility with Python 2.x
from __future__ import division # compatibility with Python 2.x

__version__ = '2.3.3.1'
__version__ = '2.3.3.2'

import heapq
import random
Expand Down Expand Up @@ -2398,6 +2398,8 @@ def draw(self):
ux = uio.x + env.xy_anchor_to_x(uio.xy_anchor, screen_coordinates=True)
uy = uio.y + env.xy_anchor_to_y(uio.xy_anchor, screen_coordinates=True)

if uio.type == 'entry':
raise SalabimError('AnimateEntry not supported on Pythonista')
if uio.type == 'button':
linewidth = uio.linewidth

Expand Down Expand Up @@ -3682,6 +3684,7 @@ def __init__(self, trace=False, random_seed=None, name=None,
self._animate = False
self.running = False
self.t = 0
self.video_t = 0
self._synced = True
self._step_pressed = False
self.stopped = False
Expand Down Expand Up @@ -3832,9 +3835,12 @@ def step(self):
if self._event_list:
(t, _, c) = heapq.heappop(self._event_list)
else:
t = self.env._now
c = self._main
self.print_trace('', '', 'run ended', 'no more events', s0=c.lineno_txt())
if self.end_on_empty_eventlist:
t = self.env._now
self.print_trace('', '', 'run ended', 'no events left', s0=c.lineno_txt())
else:
t = inf
c._on_event_list = False
self.env._now = t

Expand Down Expand Up @@ -4055,7 +4061,7 @@ def animation_parameters(self,

if use_toplevel is not None:
self.use_toplevel = use_toplevel

if animate is None:
animate = self._animate # no change
else:
Expand Down Expand Up @@ -4175,7 +4181,6 @@ def video_close(self):
self._video_out.release()
self._video_out = None
self._video = ''


def uninstall_uios(self):
for uio in self.ui_objects:
Expand Down Expand Up @@ -4548,7 +4553,10 @@ def peek(self):
if self._event_list:
return self._event_list[0][0]
else:
return self._now # here the event list is empty, so return last event time
if self.end_on_empty_eventlist:
return self._now
else:
return inf

def main(self):
'''
Expand Down Expand Up @@ -4677,11 +4685,19 @@ def run(self, duration=None, till=None, urgent=False):

Note
----
if neither till nor duration is specified, the main component will be reactivated at
the time there are no more events on the eventlist, i.e. usualy not at inf. |n|
if you want to run till inf, issue run(sim.inf) |n|
only issue run() from the main level
'''

self.end_on_empty_eventlist = False
extra = ''
if till is None:
if duration is None:
scheduled_time = inf
self.end_on_empty_eventlist = True
extra = '*'
else:
if duration == inf:
scheduled_time = inf
Expand All @@ -4694,7 +4710,7 @@ def run(self, duration=None, till=None, urgent=False):
raise SalabimError('both duration and till specified')

self._main.frame = _get_caller_frame()
self._main._reschedule(scheduled_time, urgent, 'run')
self._main._reschedule(scheduled_time, urgent, 'run', extra=extra)

self.running = True
while self.running:
Expand All @@ -4720,7 +4736,7 @@ def do_simulate_and_animate(self):
self.root.mainloop()

def simulate_and_animate_loop(self):

while True:
tick_start = time.time()

Expand Down Expand Up @@ -4809,7 +4825,7 @@ def simulate_and_animate_loop(self):
g.canvas.delete(co)
g.canvas_objects.remove(co)
co = next(canvas_objects_iter, None)

for uio in self.ui_objects:
if not uio.installed:
uio.install()
Expand Down Expand Up @@ -7119,8 +7135,6 @@ class AnimateEntry(object):
'''
def __init__(self, x=0, y=0, number_of_chars=20, value='',
fillcolor='fg', color='bg', text='', action=None, env=None, xy_anchor='sw'):
if Pythonista:
raise SalabimError('AnimateEntry not supported under Pythonista')
self.env = g.default_env if env is None else env
self.env.ui_objects.append(self)
self.type = 'entry'
Expand All @@ -7132,7 +7146,7 @@ def __init__(self, x=0, y=0, number_of_chars=20, value='',
self.fillcolor = self.env.colorspec_to_tuple(fillcolor)
self.color = self.env.colorspec_to_tuple(color)
self.action = action
self.xy_anchor = xy_anchor
self.xy_anchor = xy_anchor
self.installed = False

def install(self):
Expand All @@ -7151,24 +7165,22 @@ def install(self):
x, self.env._height - y,
anchor=tkinter.SW, window=self.entry)
self.entry.insert(0, self.value)
self.installed = True

self.installed = True

def on_enter(self, ev):
if self.action is not None:
self.action()

def get(self):
'''
get the current value of the entry

Returns
-------
Current value of the entry : str
'''
return(self.entry.get())


def remove(self):
'''
removes the entry object. |n|
Expand All @@ -7180,7 +7192,8 @@ def remove(self):
if self.installed:
self.entry.destroy()
self.installed = False



class AnimateButton(object):
'''
defines a button
Expand Down Expand Up @@ -7641,14 +7654,14 @@ def update(self, t):
self.vangle = 0
elif direction == 'n':
self.vx = x + (-25 if titleoffsetx is None else titleoffsetx)
self.vy = y + (25if self.titleoffsety is None else titleoffsety)
self.vanchor='se'
self.vangle = 90
self.vy = y + (-25 - self.vtitlefontsize if self.titleoffsety is None else titleoffsety)
self.vanchor = 'sw'
self.vangle = 0
elif direction == 's':
self.vx = x + (-25 if titleoffsetx is None else titleoffsetx)
self.vy = y + (-25if self.titleoffsety is None else titleoffsety)
self.vanchor='se'
self.vangle = 90
self.vy = y + (25if self.titleoffsety is None else titleoffsety)
self.vanchor = 'sw'
self.vangle = 0

factor_x, factor_y = \
{'w': (-1, 0), 'n': (0, 1), 'e': (1, 0), 's': (0, -1)}[direction.lower()]
Expand Down Expand Up @@ -9411,10 +9424,15 @@ def _reschedule(self, scheduled_time, urgent, caller, extra='', s0=None):
self._push(scheduled_time, urgent)
self._status = scheduled
if self.env._trace:
if extra == '*':
scheduled_time_str = 'ends on no events left '
extra = ' '
else:
scheduled_time_str = 'scheduled for {:10.3f}'.format(scheduled_time - self.env._offset)
self.env.print_trace(
'', '', self.name() + ' ' + caller,
merge_blanks(
'scheduled for {:10.3f}'.format(scheduled_time - self.env._offset) +
scheduled_time_str +
_urgenttxt(urgent) + '@' + self.lineno_txt(),
_modetxt(self._mode),
extra),
Expand Down Expand Up @@ -13824,6 +13842,7 @@ def requesting():
def waiting():
return 'waiting'


def random_seed(seed, randomstream=None):
'''
Reseeds a randomstream
Expand Down

0 comments on commit 560a42b

Please sign in to comment.