Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sugar/activity/activity.py57
-rw-r--r--src/sugar/datastore/datastore.py18
-rw-r--r--src/sugar/graphics/palette.py114
-rw-r--r--src/sugar/presence/presenceservice.py3
-rw-r--r--src/sugar/presence/tubeconn.py4
5 files changed, 92 insertions, 104 deletions
diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py
index 73eeea7..f34553d 100644
--- a/src/sugar/activity/activity.py
+++ b/src/sugar/activity/activity.py
@@ -192,7 +192,7 @@ class ActivityToolbar(gtk.Toolbar):
self._activity.metadata['title_set_by_user'] = '1'
self._activity.save()
- shared_activity = self._activity._shared_activity
+ shared_activity = self._activity.shared_activity
if shared_activity:
shared_activity.props.name = title
@@ -470,7 +470,7 @@ class Activity(Window, gtk.Container):
self._active = False
self._activity_id = handle.activity_id
self._pservice = presenceservice.get_instance()
- self._shared_activity = None
+ self.shared_activity = None
self._share_id = None
self._join_id = None
self._preview = _sugarext.Preview()
@@ -519,15 +519,15 @@ class Activity(Window, gtk.Container):
# There's already an instance on the mesh, join it
logging.debug("*** Act %s joining existing mesh instance %r",
self._activity_id, mesh_instance)
- self._shared_activity = mesh_instance
- self._shared_activity.connect('notify::private',
- self.__privacy_changed_cb)
- self._join_id = self._shared_activity.connect(
- "joined", self.__joined_cb)
- if not self._shared_activity.props.joined:
- self._shared_activity.join()
+ self.shared_activity = mesh_instance
+ self.shared_activity.connect('notify::private',
+ self.__privacy_changed_cb)
+ self._join_id = self.shared_activity.connect("joined",
+ self.__joined_cb)
+ if not self.shared_activity.props.joined:
+ self.shared_activity.join()
else:
- self.__joined_cb(self._shared_activity, True, None)
+ self.__joined_cb(self.shared_activity, True, None)
elif share_scope != SCOPE_PRIVATE:
logging.debug("*** Act %s no existing mesh instance, but used to " \
"be shared, will share" % self._activity_id)
@@ -552,8 +552,8 @@ class Activity(Window, gtk.Container):
self._jobject.metadata['keep'] = '0'
self._jobject.metadata['preview'] = ''
self._jobject.metadata['share-scope'] = SCOPE_PRIVATE
- if self._shared_activity is not None:
- icon_color = self._shared_activity.props.color
+ if self.shared_activity is not None:
+ icon_color = self.shared_activity.props.color
else:
icon_color = profile.get_color().to_string()
self._jobject.metadata['icon-color'] = icon_color
@@ -743,9 +743,9 @@ class Activity(Window, gtk.Container):
return preview_data
def _get_buddies(self):
- if self._shared_activity is not None:
+ if self.shared_activity is not None:
buddies = {}
- for buddy in self._shared_activity.get_joined_buddies():
+ for buddy in self.shared_activity.get_joined_buddies():
if not buddy.props.owner:
buddy_id = sha1(buddy.props.key).hexdigest()
buddies[buddy_id] = [buddy.props.nick, buddy.props.color]
@@ -824,7 +824,7 @@ class Activity(Window, gtk.Container):
def __joined_cb(self, activity, success, err):
"""Callback when join has finished"""
- self._shared_activity.disconnect(self._join_id)
+ self.shared_activity.disconnect(self._join_id)
self._join_id = None
if not success:
logging.debug("Failed to join activity: %s" % err)
@@ -832,13 +832,13 @@ class Activity(Window, gtk.Container):
self.present()
self.emit('joined')
- self.__privacy_changed_cb(self._shared_activity, None)
+ self.__privacy_changed_cb(self.shared_activity, None)
def get_shared(self):
"""Returns TRUE if the activity is shared on the mesh."""
- if not self._shared_activity:
+ if not self.shared_activity:
return False
- return self._shared_activity.props.joined
+ return self.shared_activity.props.joined
def __share_cb(self, ps, success, activity, err):
self._pservice.disconnect(self._share_id)
@@ -853,11 +853,11 @@ class Activity(Window, gtk.Container):
activity.props.name = self._jobject.metadata['title']
- self._shared_activity = activity
- self._shared_activity.connect('notify::private',
+ self.shared_activity = activity
+ self.shared_activity.connect('notify::private',
self.__privacy_changed_cb)
self.emit('shared')
- self.__privacy_changed_cb(self._shared_activity, None)
+ self.__privacy_changed_cb(self.shared_activity, None)
self._send_invites()
@@ -870,7 +870,7 @@ class Activity(Window, gtk.Container):
buddy_key = self._invites_queue.pop()
buddy = self._pservice.get_buddy(buddy_key)
if buddy:
- self._shared_activity.invite(
+ self.shared_activity.invite(
buddy, '', self._invite_response_cb)
else:
logging.error('Cannot invite %s, no such buddy.' % buddy_key)
@@ -884,8 +884,8 @@ class Activity(Window, gtk.Container):
"""
self._invites_queue.append(buddy_key)
- if (self._shared_activity is None
- or not self._shared_activity.props.joined):
+ if (self.shared_activity is None
+ or not self.shared_activity.props.joined):
self.share(True)
else:
self._send_invites()
@@ -899,7 +899,7 @@ class Activity(Window, gtk.Container):
Once the activity is shared, its privacy can be changed by setting
its 'private' property.
"""
- if self._shared_activity and self._shared_activity.props.joined:
+ if self.shared_activity and self.shared_activity.props.joined:
raise RuntimeError("Activity %s already shared." %
self._activity_id)
verb = private and 'private' or 'public'
@@ -945,8 +945,8 @@ class Activity(Window, gtk.Container):
self._show_keep_failed_dialog()
return False
- if self._shared_activity:
- self._shared_activity.leave()
+ if self.shared_activity:
+ self.shared_activity.leave()
self._closing = True
@@ -1006,6 +1006,9 @@ class Activity(Window, gtk.Container):
metadata = property(get_metadata, None)
+ # DEPRECATED
+ _shared_activity = property(lambda self: self.shared_activity, None)
+
_session = None
def _get_session():
diff --git a/src/sugar/datastore/datastore.py b/src/sugar/datastore/datastore.py
index 1917b19..4ec95bf 100644
--- a/src/sugar/datastore/datastore.py
+++ b/src/sugar/datastore/datastore.py
@@ -83,10 +83,10 @@ class DSMetadata(gobject.GObject):
class DSObject(object):
def __init__(self, object_id, metadata=None, file_path=None):
self.object_id = object_id
+ self.owns_file = False
self._metadata = metadata
self._file_path = file_path
self._destroyed = False
- self._owns_file = False
def get_metadata(self):
if self._metadata is None and not self.object_id is None:
@@ -103,15 +103,15 @@ class DSObject(object):
def get_file_path(self):
if self._file_path is None and not self.object_id is None:
self.set_file_path(dbus_helpers.get_filename(self.object_id))
- self._owns_file = True
+ self.owns_file = True
return self._file_path
def set_file_path(self, file_path):
if self._file_path != file_path:
- if self._file_path and self._owns_file:
+ if self._file_path and self.owns_file:
if os.path.isfile(self._file_path):
os.remove(self._file_path)
- self._owns_file = False
+ self.owns_file = False
self._file_path = file_path
file_path = property(get_file_path, set_file_path)
@@ -210,10 +210,10 @@ class DSObject(object):
logging.warning('This DSObject has already been destroyed!.')
return
self._destroyed = True
- if self._file_path and self._owns_file:
+ if self._file_path and self.owns_file:
if os.path.isfile(self._file_path):
os.remove(self._file_path)
- self._owns_file = False
+ self.owns_file = False
self._file_path = None
def __del__(self):
@@ -249,10 +249,10 @@ def write(ds_object, update_mtime=True, transfer_ownership=False,
properties['mtime'] = datetime.now().isoformat()
properties['timestamp'] = int(time.time())
- if ds_object._file_path is None:
- file_path = ''
+ if ds_object.owns_file:
+ file_path = ds_object.file_path
else:
- file_path = ds_object._file_path
+ file_path = ''
# FIXME: this func will be sync for creates regardless of the handlers
# supplied. This is very bad API, need to decide what to do here.
diff --git a/src/sugar/graphics/palette.py b/src/sugar/graphics/palette.py
index 04f269f..6360f4e 100644
--- a/src/sugar/graphics/palette.py
+++ b/src/sugar/graphics/palette.py
@@ -229,9 +229,11 @@ class Palette(gtk.Window):
primary_box.set_size_request(-1, style.zoom(style.GRID_CELL_SIZE)
- 2 * self.get_border_width())
- self.connect('realize', self._realize_cb)
+
+ self.connect('show', self.__show_cb)
+ self.connect('hide', self.__hide_cb)
+ self.connect('realize', self.__realize_cb)
self.connect('destroy', self.__destroy_cb)
- self.connect('map-event', self.__map_event_cb)
self._alignment = None
self._old_alloc = None
@@ -243,7 +245,6 @@ class Palette(gtk.Window):
self._up = False
self._menu_box = None
self._content = None
- self._palette_popup_sid = None
self._invoker_hids = []
self.set_group_id("default")
@@ -265,6 +266,7 @@ class Palette(gtk.Window):
# The menu is not shown here until an item is added
self.menu = _Menu(self)
+ self.menu.connect('item-inserted', self.__menu_item_inserted_cb)
self.connect('enter-notify-event', self.__enter_notify_event_cb)
self.connect('leave-notify-event', self.__leave_notify_event_cb)
@@ -272,12 +274,12 @@ class Palette(gtk.Window):
self._mouse_detector = MouseSpeedDetector(self, 200, 5)
self._mouse_detector.connect('motion-slow', self._mouse_slow_cb)
+ def __menu_item_inserted_cb(self, menu):
+ self._update_separators()
+
def __destroy_cb(self, palette):
self.set_group_id(None)
- if self._palette_popup_sid is not None:
- _palette_observer.disconnect(self._palette_popup_sid)
-
def _add_menu(self):
self._menu_box = gtk.VBox()
self._secondary_box.pack_start(self._menu_box)
@@ -504,17 +506,20 @@ class Palette(gtk.Window):
if self.window:
self.window.set_accept_focus(accept_focus)
- def _realize_cb(self, widget):
+ def __realize_cb(self, widget):
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
self._update_accept_focus()
def _update_full_request(self):
- state = self.palette_state
+ if self.palette_state == self.PRIMARY:
+ self.menu.embed(self._menu_box)
+ self._secondary_box.show()
- self._set_state(self.SECONDARY)
self._full_request = self.size_request()
- self._set_state(state)
+ if self.palette_state == self.PRIMARY:
+ self.menu.unembed()
+ self._secondary_box.hide()
def _update_position(self):
invoker = self._invoker
@@ -529,45 +534,19 @@ class Palette(gtk.Window):
self.move(position.x, position.y)
- def _show(self):
- if self._up:
- return
-
- self._palette_popup_sid = _palette_observer.connect(
- 'popup', self._palette_observer_popup_cb)
-
+ def popup(self, immediate=False):
if self._invoker is not None:
self._update_full_request()
self._alignment = self._invoker.get_alignment(self._full_request)
self._update_position()
self.set_transient_for(self._invoker.get_toplevel())
- self.menu.set_active(True)
- self.show()
-
- def _hide(self):
- self._secondary_anim.stop()
-
- if not self._palette_popup_sid is None:
- _palette_observer.disconnect(self._palette_popup_sid)
- self._palette_popup_sid = None
-
- self.menu.set_active(False)
- self.hide()
-
- if self._invoker:
- self._invoker.notify_popdown()
-
- self._up = False
- self.emit('popdown')
-
- def popup(self, immediate=False):
self._popdown_anim.stop()
if not immediate:
self._popup_anim.start()
else:
- self._show()
+ self.show()
self._secondary_anim.start()
@@ -579,9 +558,9 @@ class Palette(gtk.Window):
if not immediate:
self._popdown_anim.start()
else:
- self._hide()
+ self.hide()
- def _set_state(self, state):
+ def set_state(self, state):
if self.palette_state == state:
return
@@ -591,6 +570,7 @@ class Palette(gtk.Window):
elif state == self.SECONDARY:
self.menu.embed(self._menu_box)
self._secondary_box.show()
+ self._update_position()
self.palette_state = state
@@ -608,7 +588,7 @@ class Palette(gtk.Window):
if self._group_id:
group = palettegroup.get_group(self._group_id)
if group and group.is_up():
- self._set_state(self.PRIMARY)
+ self.set_state(self.PRIMARY)
immediate = True
group.popdown()
@@ -629,8 +609,8 @@ class Palette(gtk.Window):
self._popup_anim.stop()
self._secondary_anim.stop()
self._popdown_anim.stop()
- self._set_state(self.SECONDARY)
- self._show()
+ self.set_state(self.SECONDARY)
+ self.show()
def __enter_notify_event_cb(self, widget, event):
if event.detail != gtk.gdk.NOTIFY_INFERIOR:
@@ -641,17 +621,26 @@ class Palette(gtk.Window):
if event.detail != gtk.gdk.NOTIFY_INFERIOR:
self.popdown()
- def _palette_observer_popup_cb(self, observer, palette):
- if self != palette:
- self._hide()
+ def __show_cb(self, widget):
+ self.menu.set_active(True)
- def __map_event_cb(self, widget, event):
self._invoker.notify_popup()
self._up = True
- _palette_observer.emit('popup', self)
self.emit('popup')
+ def __hide_cb(self, widget):
+ self.menu.set_active(False)
+
+ self._secondary_anim.stop()
+
+ if self._invoker:
+ self._invoker.notify_popdown()
+
+ self._up = False
+ self.emit('popdown')
+
+
class PaletteActionBar(gtk.HButtonBox):
def add_action(self, label, icon_name=None):
button = gtk.Button(label)
@@ -667,13 +656,17 @@ class PaletteActionBar(gtk.HButtonBox):
class _Menu(_sugarext.Menu):
__gtype_name__ = 'SugarPaletteMenu'
+ __gsignals__ = {
+ 'item-inserted': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
+ }
+
def __init__(self, palette):
_sugarext.Menu.__init__(self)
self._palette = palette
def do_insert(self, item, position):
_sugarext.Menu.do_insert(self, item, position)
- self._palette._update_separators()
+ self.emit('item-inserted')
self.show()
def do_expose_event(self, event):
@@ -687,7 +680,7 @@ class _Menu(_sugarext.Menu):
pass
def do_deactivate(self):
- self._palette._hide()
+ self._palette.hide()
class _PopupAnimation(animator.Animation):
def __init__(self, palette):
@@ -696,8 +689,8 @@ class _PopupAnimation(animator.Animation):
def next_frame(self, current):
if current == 1.0:
- self._palette._set_state(Palette.PRIMARY)
- self._palette._show()
+ self._palette.set_state(Palette.PRIMARY)
+ self._palette.show()
class _SecondaryAnimation(animator.Animation):
def __init__(self, palette):
@@ -706,8 +699,7 @@ class _SecondaryAnimation(animator.Animation):
def next_frame(self, current):
if current == 1.0:
- self._palette._set_state(Palette.SECONDARY)
- self._palette._update_position()
+ self._palette.set_state(Palette.SECONDARY)
class _PopdownAnimation(animator.Animation):
def __init__(self, palette):
@@ -716,7 +708,7 @@ class _PopdownAnimation(animator.Animation):
def next_frame(self, current):
if current == 1.0:
- self._palette._hide()
+ self._palette.hide()
class Invoker(gobject.GObject):
__gtype_name__ = 'SugarPaletteInvoker'
@@ -1109,15 +1101,3 @@ class ToolInvoker(WidgetInvoker):
return self.BOTTOM + self.TOP
else:
return self.LEFT + self.RIGHT
-
-class _PaletteObserver(gobject.GObject):
- __gtype_name__ = 'SugarPaletteObserver'
-
- __gsignals__ = {
- 'popup': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([object]))
- }
-
- def __init__(self):
- gobject.GObject.__init__(self)
-
-_palette_observer = _PaletteObserver()
diff --git a/src/sugar/presence/presenceservice.py b/src/sugar/presence/presenceservice.py
index 50f0f7f..4b0b3e1 100644
--- a/src/sugar/presence/presenceservice.py
+++ b/src/sugar/presence/presenceservice.py
@@ -457,7 +457,8 @@ class PresenceService(gobject.GObject):
def _share_activity_cb(self, activity, op):
"""Finish sharing the activity
"""
- psact = self._new_object(op)
+ # FIXME find a better way to shutup pylint
+ psact = (Activity)(self._new_object(op))
psact._joined = True
_logger.debug('%r: Just shared, setting up tubes', activity)
psact.set_up_tubes(reply_handler=lambda:
diff --git a/src/sugar/presence/tubeconn.py b/src/sugar/presence/tubeconn.py
index b487391..c2f67e6 100644
--- a/src/sugar/presence/tubeconn.py
+++ b/src/sugar/presence/tubeconn.py
@@ -31,6 +31,8 @@ logger = logging.getLogger('telepathy.tubeconn')
class TubeConnection(Connection):
+ # pylint: disable-msg=W0212
+ # Confused by __new__
def __new__(cls, conn, tubes_iface, tube_id, address=None,
group_iface=None, mainloop=None):
if address is None:
@@ -53,6 +55,8 @@ class TubeConnection(Connection):
return self
+ # pylint: disable-msg=W0201
+ # Confused by __new__
def _on_get_self_handle_reply(self, handle):
self.self_handle = handle
match = self._tubes_iface.connect_to_signal('DBusNamesChanged',