Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sugar/simulator.py25
-rw-r--r--tests/simulator/bots/penelope.py3
2 files changed, 27 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)
diff --git a/tests/simulator/bots/penelope.py b/tests/simulator/bots/penelope.py
index 30774ae..90f9d35 100644
--- a/tests/simulator/bots/penelope.py
+++ b/tests/simulator/bots/penelope.py
@@ -3,4 +3,7 @@ from sugar.simulator import Bot
bot = Bot()
bot.name = 'penelope'
+bot.wait(20)
+bot.share_chat('Nekkhamma')
+
bot.start()