From 386dbe71232110c8177ab1833f77f42c32c85283 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 09 Oct 2006 14:35:36 +0000 Subject: Add a wait method to the bot --- (limited to 'sugar/simulator.py') 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) -- cgit v0.9.1