Add timelined actions
This commit is contained in:
parent
5b31e2b134
commit
f43b97a202
@ -37,10 +37,35 @@ class _ShellOwner(object):
|
|||||||
def _handle_invite(self, issuer, bundle_id, activity_id):
|
def _handle_invite(self, issuer, bundle_id, activity_id):
|
||||||
return ''
|
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:
|
class Bot:
|
||||||
def __init__(self, nick, color):
|
def __init__(self, nick, color):
|
||||||
self._nick = nick
|
self._nick = nick
|
||||||
self._color = color
|
self._color = color
|
||||||
|
self._timeline = _Timeline(0.01)
|
||||||
|
|
||||||
os.environ['SUGAR_NICK_NAME'] = self._nick
|
os.environ['SUGAR_NICK_NAME'] = self._nick
|
||||||
|
|
||||||
@ -57,15 +82,13 @@ class Bot:
|
|||||||
|
|
||||||
gtk.main()
|
gtk.main()
|
||||||
|
|
||||||
|
def add_action(self, action, minutes):
|
||||||
|
self._timeline.add(action, minutes)
|
||||||
|
|
||||||
def _real_start(self):
|
def _real_start(self):
|
||||||
pservice = PresenceService.get_instance()
|
pservice = PresenceService.get_instance()
|
||||||
|
|
||||||
if not pservice.get_owner().get_color():
|
if not pservice.get_owner().get_color():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
activity = _SimulatedActivity()
|
|
||||||
properties = { 'title' : 'OLPC' }
|
|
||||||
activity_type = '_GroupChatActivity_Sugar_redhat_com._udp'
|
|
||||||
service = pservice.share_activity(activity, activity_type, properties)
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -1,7 +1,17 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
from sugar.simulator import Bot
|
from sugar.simulator import Bot
|
||||||
|
from sugar.simulator import ShareActivityAction
|
||||||
from sugar.canvas.IconColor import IconColor
|
from sugar.canvas.IconColor import IconColor
|
||||||
|
|
||||||
bot = Bot('kiu', IconColor('#5E4505,#0F8A0F'))
|
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()
|
bot.start()
|
||||||
|
Loading…
Reference in New Issue
Block a user