Add a wait method to the bot
This commit is contained in:
parent
994b337709
commit
386dbe7123
@ -58,6 +58,14 @@ class _ShareChatAction(object):
|
|||||||
pservice = PresenceService.get_instance()
|
pservice = PresenceService.get_instance()
|
||||||
pservice.register_service(name, stype, properties, address)
|
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):
|
class Bot(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = util.unique_id()
|
self.name = util.unique_id()
|
||||||
@ -66,6 +74,10 @@ class Bot(object):
|
|||||||
|
|
||||||
self._queue = []
|
self._queue = []
|
||||||
|
|
||||||
|
def wait(self, seconds):
|
||||||
|
action = _WaitAction(self, seconds)
|
||||||
|
self._queue.append(action)
|
||||||
|
|
||||||
def share_chat(self, title):
|
def share_chat(self, title):
|
||||||
action = _ShareChatAction(self, title)
|
action = _ShareChatAction(self, title)
|
||||||
self._queue.append(action)
|
self._queue.append(action)
|
||||||
@ -74,12 +86,23 @@ class Bot(object):
|
|||||||
self._service = _BotService(self)
|
self._service = _BotService(self)
|
||||||
self._service.announce()
|
self._service.announce()
|
||||||
|
|
||||||
gobject.idle_add(self._idle_cb)
|
self._start_queue()
|
||||||
|
|
||||||
def _idle_cb(self):
|
def _idle_cb(self):
|
||||||
self._next_action()
|
self._next_action()
|
||||||
return True
|
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):
|
def _next_action(self):
|
||||||
if len(self._queue) > 0:
|
if len(self._queue) > 0:
|
||||||
action = self._queue.pop(0)
|
action = self._queue.pop(0)
|
||||||
|
@ -3,4 +3,7 @@ from sugar.simulator import Bot
|
|||||||
bot = Bot()
|
bot = Bot()
|
||||||
bot.name = 'penelope'
|
bot.name = 'penelope'
|
||||||
|
|
||||||
|
bot.wait(20)
|
||||||
|
bot.share_chat('Nekkhamma')
|
||||||
|
|
||||||
bot.start()
|
bot.start()
|
||||||
|
Loading…
Reference in New Issue
Block a user