Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-02-09 10:23:32 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-02-09 10:23:32 (GMT)
commitda1df8da094da605786faeb2fa6d7ba5ab6b4928 (patch)
tree52828aba3232a7c585c8398bd7175d18dd089666 /activity.py
parentc1954705fa0123dc91265098b3e375b4919572de (diff)
Add collab code
Diffstat (limited to 'activity.py')
-rw-r--r--activity.py309
1 files changed, 94 insertions, 215 deletions
diff --git a/activity.py b/activity.py
index b272763..c00f2b8 100644
--- a/activity.py
+++ b/activity.py
@@ -12,17 +12,12 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-from sugar.activity import activity
-from sugar.presence import presenceservice
-from sugar.presence.tubeconn import TubeConnection
-import telepathy
-import telepathy.client
-from dbus import Interface
-from dbus.service import method, signal
-from dbus.gobject_service import ExportedGObject
+import gtk
from gettext import gettext as _
-from sugar.activity.activity import get_activity_root
+from sugar.graphics.toolbutton import ToolButton
+from sugar.graphics.toggletoolbutton import ToggleToolButton
+from sugar.activity.activity import ActivityToolbox
import montage
import lessons
@@ -30,25 +25,21 @@ import document
import char
import ground
import sound
-from toolbars import *
+from shared import SharedActivity
+from messenger import Messenger, SERVICE
+from utils import *
-SERVICE = 'org.freedesktop.Telepathy.Tube.Connect'
-IFACE = SERVICE
-PATH = '/org/freedesktop/Telepathy/Tube/Connect'
-
-#TMPDIR = os.path.join(get_activity_root(), 'tmp')
-
-class CartoonBuilderActivity(activity.Activity):
+class CartoonBuilderActivity(SharedActivity):
def __init__(self, handle):
- activity.Activity.__init__(self,handle)
-
self.notebook = gtk.Notebook()
+ SharedActivity.__init__(self, self.notebook, SERVICE, handle)
+
+ self.connect('init', self._init_cb)
+ self.connect('tube', self._tube_cb)
+
self.notebook.show()
self.notebook.props.show_border = False
self.notebook.props.show_tabs = False
- # XXX do it after(possible) read_file() invoking
- # have to rely on calling read_file() from map_cb in sugar-toolkit
- self.notebook.connect_after('map', self._map_cb)
self.montage = montage.View()
self.notebook.append_page(self.montage)
@@ -56,7 +47,7 @@ class CartoonBuilderActivity(activity.Activity):
self.lessons.show()
self.notebook.append_page(self.lessons)
- toolbox = activity.ActivityToolbox(self)
+ toolbox = ActivityToolbox(self)
toolbox.show()
toolbox.connect('current-toolbar-changed', self._toolbar_changed_cb)
self.set_toolbox(toolbox)
@@ -70,35 +61,6 @@ class CartoonBuilderActivity(activity.Activity):
toolbox.add_toolbar(_('Lessons'), lessons_bar)
toolbox.set_current_toolbar(1)
- self.set_canvas(self.notebook)
-
- """
- # mesh stuff
- self.pservice = presenceservice.get_instance()
- owner = self.pservice.get_owner()
- self.owner = owner
- try:
- name, path = self.pservice.get_preferred_connection()
- self.tp_conn_name = name
- self.tp_conn_path = path
- self.conn = telepathy.client.Connection(name, path)
- except TypeError:
- pass
- self.initiating = None
-
- #sharing stuff
- self.game = None
- self.connect('shared', self._shared_cb)
- if self._shared_activity:
- # we are joining the activity
- self.connect('joined', self._joined_cb)
- if self.get_shared():
- # oh, OK, we've already joined
- self._joined_cb()
- else:
- # we are creating the activity
- pass
- """
def read_file(self, filepath):
document.load(filepath)
@@ -109,177 +71,94 @@ class CartoonBuilderActivity(activity.Activity):
def write_file(self, filepath):
document.save(filepath)
- def _map_cb(self, widget):
+ def _init_cb(self, widget):
self.montage.restore()
+ def _tube_cb(self, activity, tube_conn, initiating):
+ self.messenger = Messenger(tube_conn, initiating, self.montage)
+
def _toolbar_changed_cb(self, widget, index):
if index == 2:
self.notebook.set_current_page(1)
else:
self.notebook.set_current_page(0)
-
-
-
-
-
-
- def _shared_cb(self,activity):
- self.initiating = True
- self._setup()
- id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube(
- SERVICE, {})
- #self.app.export.set_label('Shared Me')
-
- def _joined_cb(self,activity):
- if self.game is not None:
- return
-
- if not self._shared_activity:
- return
-
- #for buddy in self._shared_activity.get_joined_buddies():
- # self.buddies_panel.add_watcher(buddy)
-
- #logger.debug('Joined an existing Connect game')
- #self.app.export.set_label('Joined You')
- self.initiating = False
- self._setup()
-
- #logger.debug('This is not my activity: waiting for a tube...')
- self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].ListTubes(
- reply_handler=self._list_tubes_reply_cb,
- error_handler=self._list_tubes_error_cb)
-
- def _setup(self):
- if self._shared_activity is None:
+class MontageToolbar(gtk.Toolbar):
+ def __init__(self):
+ gtk.Toolbar.__init__(self)
+
+ self.playButton = ToggleToolButton('media-playback-start')
+ self.playButton.connect('toggled', self._play_cb)
+ self.insert(self.playButton, -1)
+ self.playButton.set_tooltip(_('Play / Pause'))
+
+ # Play button Image
+ self.playButtonImg = gtk.Image()
+ self.playButtonImg.show()
+ self.playButtonImg.set_from_icon_name('media-playback-start', gtk.ICON_SIZE_LARGE_TOOLBAR)
+
+ # Pause button Image
+ self.pauseButtonImg = gtk.Image()
+ self.pauseButtonImg.show()
+ self.pauseButtonImg.set_from_icon_name('media-playback-pause', gtk.ICON_SIZE_LARGE_TOOLBAR)
+
+ tempo = TempoSlider(0, 10)
+ tempo.adjustment.connect("value-changed", self._tempo_cb)
+ tempo.set_size_request(250, -1)
+ tempo.set_value(5)
+ tempo_item = gtk.ToolItem()
+ tempo_item.add(tempo)
+ self.insert(tempo_item, -1)
+
+ separator = gtk.SeparatorToolItem()
+ self.insert(separator,-1)
+
+ clear_tape = ToolButton('sl-reset')
+ clear_tape.connect('clicked', self._clear_tape_cb)
+ clear_tape.set_tooltip(_(''))
+ self.insert(clear_tape, -1)
+
+ self.show_all()
+
+ def _clear_tape_cb(self, widget):
+ montage.clear_tape()
+
+ def _tempo_cb(self, widget):
+ montage.set_tempo(widget.value)
+
+ def _play_cb(self, widget):
+ if widget.get_active():
+ widget.set_icon_widget(self.pauseButtonImg)
+ sound.play()
+ montage.play()
+ else:
+ widget.set_icon_widget(self.playButtonImg)
+ sound.stop()
+ montage.stop()
+
+class LessonsToolbar(gtk.Toolbar):
+ def __init__(self):
+ gtk.Toolbar.__init__(self)
+ self._mask = False
+
+ for lesson in lessons.THEMES:
+ button = gtk.ToggleToolButton()
+ button.set_label(lesson.name)
+ button.connect('clicked', self._lessons_cb, lesson)
+ self.insert(button, -1)
+
+ self.get_nth_item(0).set_active(True)
+ self.show_all()
+
+ def _lessons_cb(self, widget, lesson):
+ if self._mask:
return
+ self._mask = True
- bus_name, conn_path, channel_paths = self._shared_activity.get_channels()
-
- # Work out what our room is called and whether we have Tubes already
- room = None
- tubes_chan = None
- text_chan = None
- for channel_path in channel_paths:
- channel = telepathy.client.Channel(bus_name, channel_path)
- htype, handle = channel.GetHandle()
- if htype == telepathy.HANDLE_TYPE_ROOM:
- #logger.debug('Found our room: it has handle#%d "%s"',
- # handle, self.conn.InspectHandles(htype, [handle])[0])
- room = handle
- ctype = channel.GetChannelType()
- if ctype == telepathy.CHANNEL_TYPE_TUBES:
- #logger.debug('Found our Tubes channel at %s', channel_path)
- tubes_chan = channel
- elif ctype == telepathy.CHANNEL_TYPE_TEXT:
- #logger.debug('Found our Text channel at %s', channel_path)
- text_chan = channel
-
- if room is None:
- #logger.error("Presence service didn't create a room")
- return
- if text_chan is None:
- #logger.error("Presence service didn't create a text channel")
- return
+ for i, j in enumerate(lessons.THEMES):
+ if j != lesson:
+ self.get_nth_item(i).set_active(False)
- # Make sure we have a Tubes channel - PS doesn't yet provide one
- if tubes_chan is None:
- #logger.debug("Didn't find our Tubes channel, requesting one...")
- tubes_chan = self.conn.request_channel(telepathy.CHANNEL_TYPE_TUBES,
- telepathy.HANDLE_TYPE_ROOM, room, True)
-
- self.tubes_chan = tubes_chan
- self.text_chan = text_chan
-
- tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('NewTube',
- self._new_tube_cb)
-
- def _list_tubes_reply_cb(self, tubes):
- for tube_info in tubes:
- self._new_tube_cb(*tube_info)
-
- def _list_tubes_error_cb(self, e):
- #logger.error('ListTubes() failed: %s', e)
- pass
-
- def _new_tube_cb(self, id, initiator, type, service, params, state):
- #logger.debug('New tube: ID=%d initator=%d type=%d service=%s '
- # 'params=%r state=%d', id, initiator, type, service,
- # params, state)
-
- if (self.game is None and type == telepathy.TUBE_TYPE_DBUS and
- service == SERVICE):
- if state == telepathy.TUBE_STATE_LOCAL_PENDING:
- self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].AcceptDBusTube(id)
-
- tube_conn = TubeConnection(self.conn,
- self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES],
- id, group_iface=self.text_chan[telepathy.CHANNEL_INTERFACE_GROUP])
- self.game = ConnectGame(tube_conn, self.initiating, self)
-
-class ConnectGame(ExportedGObject):
- def __init__(self,tube, is_initiator, activity):
- super(ConnectGame,self).__init__(tube,PATH)
- self.tube = tube
- self.is_initiator = is_initiator
- self.entered = False
- self.activity = activity
-
- self.ordered_bus_names=[]
- self.tube.watch_participants(self.participant_change_cb)
-
- def participant_change_cb(self, added, removed):
- if not self.entered:
- if self.is_initiator:
- self.add_hello_handler()
- else:
- self.Hello()
- self.entered = True
-
- @signal(dbus_interface=IFACE,signature='')
- def Hello(self):
- """Request that this player's Welcome method is called to bring it
- up to date with the game state.
- """
-
- @method(dbus_interface=IFACE, in_signature='s', out_signature='')
- def Welcome(self, sdata):
- #sdata is the zip file contents
- #self.activity.app.lessonplans.set_label('got data to restore')
- self.activity.app.restore(str(sdata))
-
- def add_hello_handler(self):
- self.tube.add_signal_receiver(self.hello_cb, 'Hello', IFACE,
- path=PATH, sender_keyword='sender')
-
- def hello_cb(self, sender=None):
- self.tube.get_object(sender, PATH).Welcome(self.activity.app.getsdata(),dbus_interface=IFACE)
-
-"""
- def getsdata(self):
- #self.lessonplans.set_label('getting sdata')
- # THE BELOW SHOULD WORK BUT DOESN'T
- #zf = StringIO.StringIO()
- #self.savetozip(zf)
- #zf.seek(0)
- #sdata = zf.read()
- #zf.close()
- # END OF STUFF THAT DOESN'T WORK
- sdd = {}
- tmpbgpath = os.path.join(TMPDIR,'back.png')
- self.bgpixbuf.save(tmpbgpath,'png')
- sdd['pngdata'] = file(tmpbgpath).read()
- os.remove(tmpbgpath)
- sdd['fgpixbufpaths'] = self.fgpixbufpaths
- #sdd['fgpixbufs'] = []
- #count = 1
- #for pixbuf in self.fgpixbufs:
- # filename = '%02d.png' % count
- # filepath = os.path.join(TMPDIR,filename)
- # pixbuf.save(filepath,'png')
- # sdd['fgpixbufs'].append(file(filepath).read())
- # os.remove(filepath)
- # count += 1
- return pickle.dumps(sdd)
-"""
+ widget.props.active = True
+ lesson.change()
+ self._mask = False