2006-09-10 03:07:10 +02:00
|
|
|
#!/usr/bin/python
|
2006-09-10 11:57:41 +02:00
|
|
|
|
2006-10-09 13:28:01 +02:00
|
|
|
from sugar.oldsimulator import Bot
|
|
|
|
from sugar.oldsimulator import ShareActivityAction
|
2006-10-04 00:55:20 +02:00
|
|
|
from sugar.graphics.iconcolor import IconColor
|
2006-09-21 22:43:51 +02:00
|
|
|
import os, random, gobject
|
2006-09-10 11:57:41 +02:00
|
|
|
|
2006-09-21 22:43:51 +02:00
|
|
|
class KiuBot(Bot):
|
|
|
|
def __init__(self):
|
|
|
|
Bot.__init__(self, 'kiu', IconColor('#5E4505,#0F8A0F'))
|
2006-09-25 05:12:09 +02:00
|
|
|
self._olpc_chat_service = None
|
|
|
|
self._web_activity_service = None
|
2006-09-21 22:43:51 +02:00
|
|
|
self._activity_switch_timeout = None
|
2006-09-25 03:31:48 +02:00
|
|
|
self._curact = None
|
2006-09-10 13:50:22 +02:00
|
|
|
|
2006-09-21 22:43:51 +02:00
|
|
|
action = ShareActivityAction('OLPC channel',
|
|
|
|
'_GroupChatActivity_Sugar_redhat_com._udp',
|
2006-09-25 05:12:09 +02:00
|
|
|
self.__share_olpc_chat_cb)
|
2006-09-21 22:43:51 +02:00
|
|
|
self.add_action(action, 10)
|
2006-09-10 13:50:22 +02:00
|
|
|
|
2006-09-25 05:12:09 +02:00
|
|
|
action = ShareActivityAction('All About Giraffes',
|
|
|
|
'_BrowserActivity_Sugar_redhat_com._udp',
|
|
|
|
self.__share_web_activity_cb)
|
2006-09-21 22:43:51 +02:00
|
|
|
self.add_action(action, 20)
|
2006-09-10 13:50:22 +02:00
|
|
|
|
2006-09-25 11:35:30 +02:00
|
|
|
curdir = os.path.abspath(os.path.dirname(__file__))
|
2006-10-09 13:20:39 +02:00
|
|
|
self._icon_file = os.path.join(curdir, '../data/kiu.jpg')
|
2006-09-21 22:43:51 +02:00
|
|
|
|
|
|
|
def __activity_switch_cb(self):
|
|
|
|
self._activity_switch_timeout = None
|
|
|
|
which = random.randint(1, 2)
|
|
|
|
if which == 1:
|
2006-09-25 05:12:09 +02:00
|
|
|
actid = self._olpc_chat_activity.get_id()
|
2006-09-21 22:43:51 +02:00
|
|
|
elif which == 2:
|
2006-09-25 05:12:09 +02:00
|
|
|
actid = self._web_activity.get_id()
|
2006-09-21 22:43:51 +02:00
|
|
|
else:
|
|
|
|
raise RuntimeError("WTF? unexpected value")
|
2006-09-25 03:31:48 +02:00
|
|
|
if actid != self._curact:
|
|
|
|
print "KIU: now setting current activity to %s" % actid
|
|
|
|
self._owner.set_current_activity(actid)
|
|
|
|
self._curact = actid
|
2006-09-25 13:35:44 +02:00
|
|
|
self._schedule_activity_switch_timeout()
|
2006-09-21 22:43:51 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
def _schedule_activity_switch_timeout(self):
|
|
|
|
if self._activity_switch_timeout:
|
|
|
|
return
|
2006-09-21 23:03:18 +02:00
|
|
|
interval = random.randint(10000, 20000)
|
2006-09-21 22:43:51 +02:00
|
|
|
self._activity_switch_timeout = gobject.timeout_add(interval,
|
|
|
|
self.__activity_switch_cb)
|
|
|
|
|
2006-09-25 05:12:09 +02:00
|
|
|
def __share_olpc_chat_cb(self, sim_activity, service):
|
|
|
|
self._olpc_chat_service = service
|
|
|
|
self._olpc_chat_activity = sim_activity
|
2006-09-21 22:43:51 +02:00
|
|
|
self._schedule_activity_switch_timeout()
|
|
|
|
|
2006-09-25 05:12:09 +02:00
|
|
|
def __share_web_activity_cb(self, sim_activity, service):
|
|
|
|
self._web_activity_service = service
|
|
|
|
self._web_activity = sim_activity
|
2006-09-21 22:43:51 +02:00
|
|
|
self._schedule_activity_switch_timeout()
|
|
|
|
|
|
|
|
def main():
|
|
|
|
bot = KiuBot()
|
|
|
|
bot.start()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|