From f43b97a2029946e2338924cda9a8843143a09b6d Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 10 Sep 2006 13:50:22 +0200 Subject: [PATCH] Add timelined actions --- sugar/simulator.py | 33 ++++++++++++++++++++++++++++----- tests/simulator/kiu.py | 10 ++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/sugar/simulator.py b/sugar/simulator.py index 4f97fb3c..b304bc47 100644 --- a/sugar/simulator.py +++ b/sugar/simulator.py @@ -37,10 +37,35 @@ class _ShellOwner(object): def _handle_invite(self, issuer, bundle_id, activity_id): return '' +class _Timeline: + def __init__(self, time_factor): + self._time_factor = time_factor + + def add(self, action, minutes): + gobject.timeout_add(int(1000 * 60 * minutes * self._time_factor), + self._execute_action_cb, action) + + def _execute_action_cb(self, action): + action.execute() + return False + +class ShareActivityAction: + def __init__(self, title, activity_type): + self._title = title + self._type = activity_type + + def execute(self): + activity = _SimulatedActivity() + properties = { 'title' : self._title } + + pservice = PresenceService.get_instance() + pservice.share_activity(activity, self._type, properties) + class Bot: def __init__(self, nick, color): self._nick = nick self._color = color + self._timeline = _Timeline(0.01) os.environ['SUGAR_NICK_NAME'] = self._nick @@ -57,15 +82,13 @@ class Bot: gtk.main() + def add_action(self, action, minutes): + self._timeline.add(action, minutes) + def _real_start(self): pservice = PresenceService.get_instance() if not pservice.get_owner().get_color(): return True - activity = _SimulatedActivity() - properties = { 'title' : 'OLPC' } - activity_type = '_GroupChatActivity_Sugar_redhat_com._udp' - service = pservice.share_activity(activity, activity_type, properties) - return False diff --git a/tests/simulator/kiu.py b/tests/simulator/kiu.py index 26eee4f0..af4166dd 100755 --- a/tests/simulator/kiu.py +++ b/tests/simulator/kiu.py @@ -1,7 +1,17 @@ #!/usr/bin/python from sugar.simulator import Bot +from sugar.simulator import ShareActivityAction from sugar.canvas.IconColor import IconColor bot = Bot('kiu', IconColor('#5E4505,#0F8A0F')) + +action = ShareActivityAction('OLPC channel', + '_GroupChatActivity_Sugar_redhat_com._udp') +bot.add_action(action, 10) + +action = ShareActivityAction('Sugar channel', + '_GroupChatActivity_Sugar_redhat_com._udp') +bot.add_action(action, 20) + bot.start()