Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDan Williams <dcbw@localhost.localdomain>2006-09-21 20:43:51 (GMT)
committer Dan Williams <dcbw@localhost.localdomain>2006-09-21 20:43:51 (GMT)
commit66a15398958f24273ee07f382ee9103c9f7e8058 (patch)
tree1e07b8dec4576e50b2bf4586e40508e3385578bf /tests
parentf9012b88f60f8e4ac96cb55aea763edc74ad586e (diff)
Let Kiu change activities randomly
Diffstat (limited to 'tests')
-rwxr-xr-xtests/simulator/kiu.py63
1 files changed, 55 insertions, 8 deletions
diff --git a/tests/simulator/kiu.py b/tests/simulator/kiu.py
index af4166d..ac07453 100755
--- a/tests/simulator/kiu.py
+++ b/tests/simulator/kiu.py
@@ -3,15 +3,62 @@
from sugar.simulator import Bot
from sugar.simulator import ShareActivityAction
from sugar.canvas.IconColor import IconColor
+import os, random, gobject
-bot = Bot('kiu', IconColor('#5E4505,#0F8A0F'))
+class KiuBot(Bot):
+ def __init__(self):
+ Bot.__init__(self, 'kiu', IconColor('#5E4505,#0F8A0F'))
+ self._olpc_channel_service = None
+ self._sugar_channel_service = None
+ self._activity_switch_timeout = None
-action = ShareActivityAction('OLPC channel',
- '_GroupChatActivity_Sugar_redhat_com._udp')
-bot.add_action(action, 10)
+ action = ShareActivityAction('OLPC channel',
+ '_GroupChatActivity_Sugar_redhat_com._udp',
+ self.__share_olpc_channel_cb)
+ self.add_action(action, 10)
-action = ShareActivityAction('Sugar channel',
- '_GroupChatActivity_Sugar_redhat_com._udp')
-bot.add_action(action, 20)
+ action = ShareActivityAction('Sugar channel',
+ '_GroupChatActivity_Sugar_redhat_com._udp',
+ self.__share_sugar_channel_cb)
+ self.add_action(action, 20)
-bot.start()
+ self._icon_file = os.path.abspath("kiu.jpg")
+
+ def __activity_switch_cb(self):
+ self._activity_switch_timeout = None
+ which = random.randint(1, 2)
+ if which == 1:
+ actid = self._olpc_channel_activity.get_id()
+ elif which == 2:
+ actid = self._sugar_channel_activity.get_id()
+ else:
+ raise RuntimeError("WTF? unexpected value")
+ print "KIU: now setting current activity to %s" % actid
+ self._owner.set_current_activity(actid)
+ self._schedule_activity_switch_timeout()
+ return False
+
+ def _schedule_activity_switch_timeout(self):
+ if self._activity_switch_timeout:
+ return
+ interval = random.randint(1000, 20000)
+ self._activity_switch_timeout = gobject.timeout_add(interval,
+ self.__activity_switch_cb)
+
+ def __share_olpc_channel_cb(self, sim_activity, service):
+ self._olpc_channel_service = service
+ self._olpc_channel_activity = sim_activity
+ self._schedule_activity_switch_timeout()
+
+ def __share_sugar_channel_cb(self, sim_activity, service):
+ self._sugar_channel_service = service
+ self._sugar_channel_activity = sim_activity
+ self._schedule_activity_switch_timeout()
+
+def main():
+ bot = KiuBot()
+ bot.start()
+
+
+if __name__ == "__main__":
+ main()