From 3f792924ddf4dba301d06e496ac6e29296fbd4e9 Mon Sep 17 00:00:00 2001 From: flavio Date: Fri, 09 Nov 2012 23:58:22 +0000 Subject: Gtk 3 Port Base --- (limited to 'toolkit/activity.py') diff --git a/toolkit/activity.py b/toolkit/activity.py index 1512610..29c848a 100644 --- a/toolkit/activity.py +++ b/toolkit/activity.py @@ -16,14 +16,15 @@ """Extend sugar-toolkit activity class""" -import gtk import logging import telepathy -import gobject +import gi +from gi.repository import Gtk +from gi.repository import Gdk -from sugar.activity import activity -from sugar.presence.sugartubeconn import SugarTubeConnection -from sugar.graphics.alert import ConfirmationAlert, NotifyAlert +from sugar3.activity import activity +from sugar3.presence.sugartubeconn import SugarTubeConnection +from sugar3.graphics.alert import ConfirmationAlert, NotifyAlert _NEW_INSTANCE = 0 @@ -40,9 +41,11 @@ class CursorFactory: self.__dict__ = self.__shared_state def get_cursor(self, cur_type): + if not self.cursors.has_key(cur_type): - cur = gtk.gdk.Cursor(cur_type) + cur = Gdk.Cursor(cur_type) self.cursors[cur_type] = cur + return self.cursors[cur_type] @@ -76,7 +79,7 @@ class Activity(activity.Activity): Subclass should implement this method to save activity data. """ raise NotImplementedError - + def on_save_instance(self, cb, *args): """ Register callback which will be invoked before save_instance """ self.__on_save_instance.append((cb, args)) @@ -99,22 +102,28 @@ class Activity(activity.Activity): pass def set_toolbar_box(self, toolbox): + if hasattr(activity.Activity, 'set_toolbar_box'): activity.Activity.set_toolbar_box(self, toolbox) + else: self.set_toolbox(toolbox) def get_toolbar_box(self): + if hasattr(activity.Activity, 'get_toolbar_box'): return activity.Activity.get_toolbar_box(self) + else: return self.get_toolbox() toolbar_box = property(get_toolbar_box, set_toolbar_box) def get_shared_activity(self): + if hasattr(activity.Activity, 'get_shared_activity'): return activity.Activity.get_shared_activity(self) + else: return self._shared_activity @@ -135,7 +144,7 @@ class Activity(activity.Activity): def response(alert, response_id, self, cb, *cb_args): self.remove_alert(alert) - if response_id is gtk.RESPONSE_OK: + if response_id is Gtk.ResponseType.OK: cb(*cb_args) alert.connect('response', response, self, cb, *cb_args) @@ -146,12 +155,13 @@ class Activity(activity.Activity): return self._cursor def set_cursor(self, cursor): - if not isinstance(cursor, gtk.gdk.Cursor): + + if not isinstance(cursor, Gdk.Cursor): cursor = CursorFactory().get_cursor(cursor) if self._cursor != cursor: self._cursor = cursor - self.window.set_cursor(self._cursor) + self.get_property('window').set_cursor(self._cursor) def __init__(self, canvas, handle): """ @@ -168,6 +178,7 @@ class Activity(activity.Activity): if handle.object_id: self.__state = _NEW_INSTANCE + else: self.__state = _NEW_INSTANCE @@ -176,14 +187,15 @@ class Activity(activity.Activity): self.__on_save_instance = [] self._cursor = None - self.set_cursor(gtk.gdk.LEFT_PTR) + self.set_cursor(Gdk.CursorType.LEFT_PTR) # XXX do it after(possible) read_file() invoking # have to rely on calling read_file() from map_cb in sugar-toolkit - canvas.connect_after('map', self.__map_canvasactivity_cb) + #canvas.connect_after('map', self.__map_canvasactivity_cb) self.set_canvas(canvas) - + def __instance(self): + logging.debug('Activity.__instance') if self.__resume_filename: @@ -193,6 +205,7 @@ class Activity(activity.Activity): for i in self.__postponed_share: self.share_instance(*i) + self.__postponed_share = [] self.__state = _POST_INSTANCE @@ -205,6 +218,7 @@ class Activity(activity.Activity): if self.__state == _NEW_INSTANCE: self.__state = _PRE_INSTANCE + elif self.__state == _PRE_INSTANCE: self.__instance(); @@ -212,30 +226,37 @@ class Activity(activity.Activity): """Subclass should not override this method""" for cb, args in self.__on_save_instance: cb(*args) + self.save_instance(filepath) def __map_canvasactivity_cb(self, widget): + logging.debug('Activity.__map_canvasactivity_cb state=%s' % \ self.__state) if self.__state == _NEW_INSTANCE: self.__instance() + elif self.__state == _NEW_INSTANCE: self.__state = _PRE_INSTANCE + elif self.__state == _PRE_INSTANCE: self.__instance(); return False def _share(self, tube_conn, initiator): + logging.debug('Activity._share state=%s' % self.__state) if self.__state == _NEW_INSTANCE: self.__postponed_share.append((tube_conn, initiator)) self.__state = _PRE_INSTANCE + elif self.__state == _PRE_INSTANCE: self.__postponed_share.append((tube_conn, initiator)) - self.__instance(); + self.__instance() + elif self.__state == _POST_INSTANCE: self.share_instance(tube_conn, initiator) @@ -265,14 +286,16 @@ class SharedActivity(Activity): self.connect('shared', self._shared_cb) # Owner.props.key - if self._shared_activity: + if self.shared_activity: # We are joining the activity self.connect('joined', self._joined_cb) + if self.get_shared(): # We've already joined self._joined_cb() def _shared_cb(self, activity): + logging.debug('My activity was shared') self.__initiator = True self._sharing_setup() @@ -282,7 +305,8 @@ class SharedActivity(Activity): self.service, {}) def _joined_cb(self, activity): - if not self._shared_activity: + + if not self.shared_activity: return logging.debug('Joined an existing shared activity') @@ -296,17 +320,20 @@ class SharedActivity(Activity): error_handler=self._list_tubes_error_cb) def _sharing_setup(self): - if self._shared_activity is None: + + if self.shared_activity is None: logging.error('Failed to share or join activity') return - self._conn = self._shared_activity.telepathy_conn - self._tubes_chan = self._shared_activity.telepathy_tubes_chan - self._text_chan = self._shared_activity.telepathy_text_chan + + self._conn = self.shared_activity.telepathy_conn + self._tubes_chan = self.shared_activity.telepathy_tubes_chan + self._text_chan = self.shared_activity.telepathy_text_chan self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal( - 'NewTube', self._new_tube_cb) + 'NewTube', self._new_tube_cb) def _list_tubes_reply_cb(self, tubes): + for tube_info in tubes: self._new_tube_cb(*tube_info) @@ -314,15 +341,17 @@ class SharedActivity(Activity): logging.error('ListTubes() failed: %s', e) def _new_tube_cb(self, id, initiator, type, service, params, state): + logging.debug('New tube: ID=%d initator=%d type=%d service=%s ' - 'params=%r state=%d', id, initiator, type, service, - params, state) + 'params=%r state=%d', id, initiator, type, service, + params, state) if (type == telepathy.TUBE_TYPE_DBUS and - service == self.service): + service == self.service): + if state == telepathy.TUBE_STATE_LOCAL_PENDING: self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES] \ - .AcceptDBusTube(id) + .AcceptDBusTube(id) tube_conn = SugarTubeConnection(self._conn, self._tubes_chan[telepathy.CHANNEL_TYPE_TUBES], id, -- cgit v0.9.1