diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-10-09 14:35:36 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-10-09 14:35:36 (GMT) |
commit | 386dbe71232110c8177ab1833f77f42c32c85283 (patch) | |
tree | 4a4c9d7af582a325a9029c34d4f3a70ea20c9801 /sugar/simulator.py | |
parent | 994b337709383dc7858ae4c8d67870858d4fd120 (diff) |
Add a wait method to the bot
Diffstat (limited to 'sugar/simulator.py')
-rw-r--r-- | sugar/simulator.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/sugar/simulator.py b/sugar/simulator.py index 38603fc..1e48229 100644 --- a/sugar/simulator.py +++ b/sugar/simulator.py @@ -58,6 +58,14 @@ class _ShareChatAction(object): pservice = PresenceService.get_instance() pservice.register_service(name, stype, properties, address) +class _WaitAction(object): + def __init__(self, bot, seconds): + self._bot = bot + self._seconds = seconds + + def execute(self): + self._bot._pause_queue(self._seconds) + class Bot(object): def __init__(self): self.name = util.unique_id() @@ -66,6 +74,10 @@ class Bot(object): self._queue = [] + def wait(self, seconds): + action = _WaitAction(self, seconds) + self._queue.append(action) + def share_chat(self, title): action = _ShareChatAction(self, title) self._queue.append(action) @@ -74,12 +86,23 @@ class Bot(object): self._service = _BotService(self) self._service.announce() - gobject.idle_add(self._idle_cb) + self._start_queue() def _idle_cb(self): self._next_action() return True + def _pause_done_cb(self): + self._start_queue() + return False + + def _start_queue(self): + self._queue_sid = gobject.idle_add(self._idle_cb) + + def _pause_queue(self, seconds): + gobject.source_remove(self._queue_sid) + gobject.timeout_add(int(seconds * 1000), self._pause_done_cb) + def _next_action(self): if len(self._queue) > 0: action = self._queue.pop(0) |