Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-10-09 16:29:54 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-10-09 16:29:54 (GMT)
commitb309da53f6eb52484ae69139d5dc0d70ec0ce05c (patch)
tree9333faa00e0f2192799cb2515b07509f40d08f3f
parentc9b5381c16fce563307379aa8b52a5b902a7cc98 (diff)
Add activity change
-rw-r--r--sugar/simulator.py24
-rw-r--r--tests/simulator/demo/chaitanya.py2
-rw-r--r--tests/simulator/demo/others.py4
-rw-r--r--tests/simulator/demo/penelope.py3
4 files changed, 24 insertions, 9 deletions
diff --git a/sugar/simulator.py b/sugar/simulator.py
index b1cd561..e130ae8 100644
--- a/sugar/simulator.py
+++ b/sugar/simulator.py
@@ -1,11 +1,11 @@
import random
import gobject
+import dbus
from sugar.presence import PresenceService
from sugar.graphics.iconcolor import IconColor
from sugar.p2p import Stream
-from sugar import util
_PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp"
@@ -42,11 +42,19 @@ class _BotService(object):
def set_current_activity(self, activity_id):
self._service.set_published_value('curact', dbus.String(activity_id))
+class _ChangeActivityAction(object):
+ def __init__(self, bot, activity_id):
+ self._bot = bot
+ self._activity_id = activity_id
+
+ def execute(self):
+ self._bot._service.set_current_activity(self._activity_id)
+
class _ShareChatAction(object):
- def __init__(self, bot, title):
+ def __init__(self, bot, activity_id, title):
self._bot = bot
self._title = title
- self._id = util.unique_id()
+ self._id = activity_id
def execute(self):
name = "%s [%s]" % (self._bot.name, self._id)
@@ -70,7 +78,7 @@ class _WaitAction(object):
class Bot(object):
def __init__(self):
- self.name = _nick_names[int(len(_nick_names) * random.random())]
+ self.name = _nick_names[random.randint(0, len(_nick_names))]
self.color = IconColor()
self.icon = None
@@ -80,8 +88,12 @@ class Bot(object):
action = _WaitAction(self, seconds)
self._queue.append(action)
- def share_chat(self, title):
- action = _ShareChatAction(self, title)
+ def share_chat(self, activity_id, title):
+ action = _ShareChatAction(self, activity_id, title)
+ self._queue.append(action)
+
+ def change_activity(self, activity_id):
+ action = _ChangeActivityAction(self, activity_id)
self._queue.append(action)
def start(self):
diff --git a/tests/simulator/demo/chaitanya.py b/tests/simulator/demo/chaitanya.py
index 95798c7..09423cb 100644
--- a/tests/simulator/demo/chaitanya.py
+++ b/tests/simulator/demo/chaitanya.py
@@ -3,6 +3,6 @@ from sugar.simulator import Bot
bot = Bot()
bot.name = 'chaitanya'
-bot.share_chat('All About Giraffes')
+bot.share_chat('giraffes', 'All About Giraffes')
bot.start()
diff --git a/tests/simulator/demo/others.py b/tests/simulator/demo/others.py
index 3b1218f..455794c 100644
--- a/tests/simulator/demo/others.py
+++ b/tests/simulator/demo/others.py
@@ -2,4 +2,8 @@ from sugar.simulator import Bot
for i in range(0, 10):
bot = Bot()
+
+ bot.wait(5)
+ bot.change_activity('giraffes')
+
bot.start()
diff --git a/tests/simulator/demo/penelope.py b/tests/simulator/demo/penelope.py
index 90f9d35..4841566 100644
--- a/tests/simulator/demo/penelope.py
+++ b/tests/simulator/demo/penelope.py
@@ -3,7 +3,6 @@ from sugar.simulator import Bot
bot = Bot()
bot.name = 'penelope'
-bot.wait(20)
-bot.share_chat('Nekkhamma')
+bot.share_chat('nekkhamma', 'Nekkhamma')
bot.start()