diff options
author | Jonas Smedegaard <dr@jones.dk> | 2008-04-22 18:31:03 (GMT) |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2008-04-22 18:31:03 (GMT) |
commit | e77f334416f1e918d81a8576dfb05cb5765ed0d9 (patch) | |
tree | 17fc783715d98cc8834c6b248ce7b8e66570b162 | |
parent | 54f2d87bc5fd1eb6ae70fd06ef697e1a022de0ce (diff) |
Imported Upstream version 0.79.5upstream/0.79.5
36 files changed, 403 insertions, 331 deletions
@@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.61 for sugar-toolkit 0.79.3. +# Generated by GNU Autoconf 2.61 for sugar-toolkit 0.79.5. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. @@ -726,8 +726,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='sugar-toolkit' PACKAGE_TARNAME='sugar-toolkit' -PACKAGE_VERSION='0.79.3' -PACKAGE_STRING='sugar-toolkit 0.79.3' +PACKAGE_VERSION='0.79.5' +PACKAGE_STRING='sugar-toolkit 0.79.5' PACKAGE_BUGREPORT='' ac_unique_file="configure.ac" @@ -1448,7 +1448,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures sugar-toolkit 0.79.3 to adapt to many kinds of systems. +\`configure' configures sugar-toolkit 0.79.5 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1518,7 +1518,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of sugar-toolkit 0.79.3:";; + short | recursive ) echo "Configuration of sugar-toolkit 0.79.5:";; esac cat <<\_ACEOF @@ -1622,7 +1622,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -sugar-toolkit configure 0.79.3 +sugar-toolkit configure 0.79.5 generated by GNU Autoconf 2.61 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1636,7 +1636,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by sugar-toolkit $as_me 0.79.3, which was +It was created by sugar-toolkit $as_me 0.79.5, which was generated by GNU Autoconf 2.61. Invocation command line was $ $0 $@ @@ -2312,7 +2312,7 @@ fi # Define the identity of the package. PACKAGE='sugar-toolkit' - VERSION='0.79.3' + VERSION='0.79.5' cat >>confdefs.h <<_ACEOF @@ -22197,7 +22197,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by sugar-toolkit $as_me 0.79.3, which was +This file was extended by sugar-toolkit $as_me 0.79.5, which was generated by GNU Autoconf 2.61. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -22244,7 +22244,7 @@ Report bugs to <bug-autoconf@gnu.org>." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -sugar-toolkit config.status 0.79.3 +sugar-toolkit config.status 0.79.5 configured by $0, generated by GNU Autoconf 2.61, with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/configure.ac b/configure.ac index 408b2ec..4f4f407 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([sugar-toolkit],[0.79.3],[],[sugar-toolkit]) +AC_INIT([sugar-toolkit],[0.79.5],[],[sugar-toolkit]) AC_PREREQ([2.59]) diff --git a/sugar/_sugarext.c b/sugar/_sugarext.c index a292d8a..767f3e9 100644 --- a/sugar/_sugarext.c +++ b/sugar/_sugarext.c @@ -53,7 +53,7 @@ PyTypeObject G_GNUC_INTERNAL PySexyIconEntry_Type; PyTypeObject G_GNUC_INTERNAL PySugarAddressEntry_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ - "_sugarext.AddressEntry", /* tp_name */ + "sugar._sugarext.AddressEntry", /* tp_name */ sizeof(PyGObject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ @@ -167,7 +167,7 @@ static const PyMethodDef _PySugarKeyGrabber_methods[] = { PyTypeObject G_GNUC_INTERNAL PySugarKeyGrabber_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ - "_sugarext.KeyGrabber", /* tp_name */ + "sugar._sugarext.KeyGrabber", /* tp_name */ sizeof(PyGObject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ @@ -266,7 +266,7 @@ static const PyMethodDef _PySugarMenu_methods[] = { PyTypeObject G_GNUC_INTERNAL PySugarMenu_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ - "_sugarext.Menu", /* tp_name */ + "sugar._sugarext.Menu", /* tp_name */ sizeof(PyGObject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ @@ -379,7 +379,7 @@ static const PyMethodDef _PySugarPreview_methods[] = { PyTypeObject G_GNUC_INTERNAL PySugarPreview_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ - "_sugarext.Preview", /* tp_name */ + "sugar._sugarext.Preview", /* tp_name */ sizeof(PyGObject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ @@ -431,7 +431,7 @@ _wrap_sexy_icon_entry_new(PyGObject *self, PyObject *args, PyObject *kwargs) static char* kwlist[] = { NULL }; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - ":_sugarext.IconEntry.__init__", + ":sugar._sugarext.IconEntry.__init__", kwlist)) return -1; @@ -439,7 +439,7 @@ _wrap_sexy_icon_entry_new(PyGObject *self, PyObject *args, PyObject *kwargs) if (!self->obj) { PyErr_SetString( PyExc_RuntimeError, - "could not create _sugarext.IconEntry object"); + "could not create sugar._sugarext.IconEntry object"); return -1; } return 0; @@ -555,7 +555,7 @@ static const PyMethodDef _PySexyIconEntry_methods[] = { PyTypeObject G_GNUC_INTERNAL PySexyIconEntry_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ - "_sugarext.IconEntry", /* tp_name */ + "sugar._sugarext.IconEntry", /* tp_name */ sizeof(PyGObject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ diff --git a/sugar/_sugarext.override b/sugar/_sugarext.override index 61fb815..1d0289e 100644 --- a/sugar/_sugarext.override +++ b/sugar/_sugarext.override @@ -14,7 +14,7 @@ headers #include <glib.h> %% -modulename _sugarext +modulename sugar._sugarext %% import gobject.GObject as PyGObject_Type import gtk.Entry as PyGtkEntry_Type diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py index 2c1eaae..6204354 100644 --- a/sugar/activity/activity.py +++ b/sugar/activity/activity.py @@ -71,13 +71,12 @@ from sugar.graphics.icon import Icon from sugar.datastore import datastore from sugar import wm from sugar import profile -from sugar import _sugarbaseext from sugar import _sugarext _ = lambda msg: gettext.dgettext('sugar', msg) SCOPE_PRIVATE = "private" -SCOPE_INVITE_ONLY = "invite" # shouldn't be shown in UI, it's implicit when you invite somebody +SCOPE_INVITE_ONLY = "invite" # shouldn't be shown in UI, it's implicit SCOPE_NEIGHBORHOOD = "public" J_DBUS_SERVICE = 'org.laptop.Journal' @@ -85,7 +84,8 @@ J_DBUS_PATH = '/org/laptop/Journal' J_DBUS_INTERFACE = 'org.laptop.Journal' class ActivityToolbar(gtk.Toolbar): - """The Activity toolbar with the Journal entry title, sharing, Keep and Stop buttons + """The Activity toolbar with the Journal entry title, sharing, + Keep and Stop buttons All activities should have this toolbar. It is easiest to add it to your Activity by using the ActivityToolbox. @@ -177,7 +177,8 @@ class ActivityToolbar(gtk.Toolbar): def __title_changed_cb(self, entry): if not self._update_title_sid: - self._update_title_sid = gobject.timeout_add(1000, self.__update_title_cb) + self._update_title_sid = gobject.timeout_add( + 1000, self.__update_title_cb) def __update_title_cb(self): title = self.title.get_text() @@ -219,9 +220,9 @@ class EditToolbar(gtk.Toolbar): paste -- the paste button separator -- A separator between undo/redo and copy/paste - This class only provides the 'edit' buttons in a standard layout, your activity - will need to either hide buttons which make no sense for your Activity, or you - need to connect the button events to your own callbacks: + This class only provides the 'edit' buttons in a standard layout, + your activity will need to either hide buttons which make no sense for your + Activity, or you need to connect the button events to your own callbacks: ## Example from Read.activity: # Create the edit toolbar: @@ -273,15 +274,15 @@ class EditToolbar(gtk.Toolbar): class ActivityToolbox(Toolbox): """Creates the Toolbox for the Activity - By default, the toolbox contains only the ActivityToolbar. After creating the - toolbox, you can add your activity specific toolbars, for example the + By default, the toolbox contains only the ActivityToolbar. After creating + the toolbox, you can add your activity specific toolbars, for example the EditToolbar. To add the ActivityToolbox to your Activity in MyActivity.__init__() do: # Create the Toolbar with the ActivityToolbar: toolbox = activity.ActivityToolbox(self) - ... your code, inserting all other toolbars you need, like EditToolbar ... + ... your code, inserting all other toolbars you need, like EditToolbar # Add the toolbox to the activity frame: self.set_toolbox(toolbox) @@ -299,7 +300,8 @@ class ActivityToolbox(Toolbox): return self._activity_toolbar class Activity(Window, gtk.Container): - """This is the base Activity class that all other Activities derive from. This is where your activity starts. + """This is the base Activity class that all other Activities derive from. + This is where your activity starts. To get a working Activity: 0. Derive your Activity from this class: @@ -453,12 +455,13 @@ class Activity(Window, gtk.Container): self.set_title(self._jobject.metadata['title']) if self._jobject.metadata.has_key('share-scope'): - share_scope = self._jobject.metadata['share-scope'] + share_scope = self._jobject.metadata['share-scope'] elif create_jobject: logging.debug('Creating a jobject.') self._jobject = datastore.create() - self._jobject.metadata['title'] = _('%s Activity') % get_bundle_name() + title = _('%s Activity') % get_bundle_name() + self._jobject.metadata['title'] = title self.set_title(self._jobject.metadata['title']) self._jobject.metadata['title_set_by_user'] = '0' self._jobject.metadata['activity'] = self.get_bundle_id() @@ -475,7 +478,8 @@ class Activity(Window, gtk.Container): self._jobject.metadata['icon-color'] = icon_color self._jobject.file_path = '' - # Cannot call datastore.write async for creates: https://dev.laptop.org/ticket/3071 + # Cannot call datastore.write async for creates: + # https://dev.laptop.org/ticket/3071 datastore.write(self._jobject) else: self._jobject = None @@ -487,17 +491,20 @@ class Activity(Window, gtk.Container): self._activity_id, mesh_instance, share_scope) if mesh_instance is not None: # There's already an instance on the mesh, join it - logging.debug("*** Act %s joining existing mesh instance %r", self._activity_id, mesh_instance) + 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) + 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) elif share_scope != SCOPE_PRIVATE: - logging.debug("*** Act %s no existing mesh instance, but used to be shared, will share" % self._activity_id) + logging.debug("*** Act %s no existing mesh instance, but used to " \ + "be shared, will share" % self._activity_id) # no existing mesh instance, but activity used to be shared, so # restart the share if share_scope == SCOPE_INVITE_ONLY: @@ -569,7 +576,8 @@ class Activity(Window, gtk.Container): store activity related data that doesn't pertain to the current execution of the activity and thus cannot go into the DataStore. - Currently, this will return something like ~/.sugar/default/MyActivityName/ + Currently, this will return something like + ~/.sugar/default/MyActivityName/ Activities should ONLY save settings, user preferences and other data which isn't specific to a journal item here. If (meta-)data is in anyway @@ -635,7 +643,8 @@ class Activity(Window, gtk.Container): def _cleanup_jobject(self): if self._jobject: if self._owns_file and os.path.isfile(self._jobject.file_path): - logging.debug('_cleanup_jobject: removing %r' % self._jobject.file_path) + logging.debug('_cleanup_jobject: removing %r' % + self._jobject.file_path) os.remove(self._jobject.file_path) self._owns_file = False self._jobject.destroy() @@ -653,7 +662,7 @@ class Activity(Window, gtk.Container): # to a temp file. Impementing gtk.gdk.Pixbuf.save_to_buffer in pygtk # would solve this. fd, file_path = tempfile.mkstemp('.png') - del fd + os.close(fd) pixbuf.save(file_path, 'png') f = open(file_path) @@ -713,9 +722,10 @@ class Activity(Window, gtk.Container): self._owns_file = True self._jobject.file_path = file_path except NotImplementedError: - pass + logging.debug('Activity.write_file is not implemented.') - # Cannot call datastore.write async for creates: https://dev.laptop.org/ticket/3071 + # Cannot call datastore.write async for creates: + # https://dev.laptop.org/ticket/3071 if self._jobject.object_id is None: datastore.write(self._jobject, transfer_ownership=True) else: @@ -726,7 +736,8 @@ class Activity(Window, gtk.Container): error_handler=self.__save_error_cb) def copy(self): - """Request that the activity 'Keep in Journal' the current state of the activity. + """Request that the activity 'Keep in Journal' the current state + of the activity. Activities should not override this method. Instead, like save() do any copy work that needs to be done in write_file() @@ -763,7 +774,8 @@ class Activity(Window, gtk.Container): self._pservice.disconnect(self._share_id) self._share_id = None if not success: - logging.debug('Share of activity %s failed: %s.' % (self._activity_id, err)) + logging.debug('Share of activity %s failed: %s.' % + (self._activity_id, err)) return logging.debug('Share of activity %s successful, PS activity is %r.', @@ -788,7 +800,8 @@ class Activity(Window, gtk.Container): buddy_key = self._invites_queue.pop() buddy = self._pservice.get_buddy(buddy_key) if buddy: - self._shared_activity.invite(buddy, '', self._invite_response_cb) + self._shared_activity.invite( + buddy, '', self._invite_response_cb) else: logging.error('Cannot invite %s, no such buddy.' % buddy_key) @@ -854,9 +867,9 @@ class Activity(Window, gtk.Container): def close(self, force=False, skip_save=False): """Request that the activity be stopped and saved to the Journal - Activities should not override this method, but should implement write_file() to - do any state saving instead. If the application wants to control wether it can - close, it should override can_close(). + Activities should not override this method, but should implement + write_file() to do any state saving instead. If the application wants + to control wether it can close, it should override can_close(). """ if not force: @@ -866,7 +879,7 @@ class Activity(Window, gtk.Container): try: if not skip_save: self.save() - except: + except Exception: logging.info(traceback.format_exc()) self._display_keep_failed_dialog() return diff --git a/sugar/activity/activityfactory.py b/sugar/activity/activityfactory.py index 1638197..7bf36c4 100644 --- a/sugar/activity/activityfactory.py +++ b/sugar/activity/activityfactory.py @@ -58,7 +58,7 @@ _children_pid = [] def _sigchild_handler(signum, frame): for child_pid in _children_pid: - pid, status = os.waitpid(child_pid, os.WNOHANG) + pid = os.waitpid(child_pid, os.WNOHANG)[0] if pid > 0: _children_pid.remove(pid) diff --git a/sugar/activity/activityhandle.py b/sugar/activity/activityhandle.py index f91651e..3f4a44c 100644 --- a/sugar/activity/activityhandle.py +++ b/sugar/activity/activityhandle.py @@ -15,8 +15,6 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -from sugar.presence import presenceservice - class ActivityHandle(object): """Data structure storing simple activity metadata""" def __init__( diff --git a/sugar/activity/bundlebuilder.py b/sugar/activity/bundlebuilder.py index 7ff2b0b..4ea05f8 100644 --- a/sugar/activity/bundlebuilder.py +++ b/sugar/activity/bundlebuilder.py @@ -68,16 +68,15 @@ class _ManifestFileList(_DefaultFileList): f.close() def _extract_bundle(source_file, dest_dir): - if not os.path.exists(dest_dir): - os.mkdir(dest_dir) + if not os.path.exists(dest_dir): + os.mkdir(dest_dir) - zf = zipfile.ZipFile(source_file) + zf = zipfile.ZipFile(source_file) - for i, name in enumerate(zf.namelist()): - path = os.path.join(dest_dir, name) - - if not os.path.exists(os.path.dirname(path)): - os.makedirs(os.path.dirname(path)) + for name in zf.namelist(): + path = os.path.join(dest_dir, name) + if not os.path.exists(os.path.dirname(path)): + os.makedirs(os.path.dirname(path)) outfile = open(path, 'wb') outfile.write(zf.read(name)) @@ -132,7 +131,7 @@ def cmd_dev(): if os.path.islink(bundle_path): print 'ERROR - The bundle has been already setup for development.' else: - print 'ERROR - A bundle with the same name is already installed.' + print 'ERROR - A bundle with the same name is already installed.' def _get_file_list(manifest): if os.path.isfile(manifest): diff --git a/sugar/activity/registry.py b/sugar/activity/registry.py index e327cf0..5f5aefc 100644 --- a/sugar/activity/registry.py +++ b/sugar/activity/registry.py @@ -68,9 +68,12 @@ class ActivityRegistry(gobject.GObject): _ACTIVITY_REGISTRY_PATH, follow_name_owner_changes = True) self._registry = dbus.Interface(bus_object, _ACTIVITY_REGISTRY_IFACE) - self._registry.connect_to_signal('ActivityAdded', self._activity_added_cb) - self._registry.connect_to_signal('ActivityRemoved', self._activity_removed_cb) - self._registry.connect_to_signal('ActivityChanged', self._activity_changed_cb) + self._registry.connect_to_signal('ActivityAdded', + self._activity_added_cb) + self._registry.connect_to_signal('ActivityRemoved', + self._activity_removed_cb) + self._registry.connect_to_signal('ActivityChanged', + self._activity_changed_cb) # Two caches fo saving some travel across dbus. self._service_name_to_activity_info = {} @@ -90,7 +93,6 @@ class ActivityRegistry(gobject.GObject): def _get_activities_cb(self, reply_handler, info_list): result = [] - i = 0 for info_dict in info_list: result.append(_activity_info_from_dict(info_dict)) @@ -104,12 +106,15 @@ class ActivityRegistry(gobject.GObject): def get_activities_async(self, reply_handler=None, error_handler=None): if not reply_handler: - logging.error('Function get_activities_async called without a reply handler. Can not run.') + logging.error('Function get_activities_async called' \ + 'without a reply handler. Can not run.') return self._registry.GetActivities( - reply_handler=lambda info_list:self._get_activities_cb(reply_handler, info_list), - error_handler=lambda e:self._get_activities_error_cb(error_handler, e)) + reply_handler=lambda info_list: \ + self._get_activities_cb(reply_handler, info_list), + error_handler=lambda e: \ + self._get_activities_error_cb(error_handler, e)) def get_activity(self, service_name): if self._service_name_to_activity_info.has_key(service_name): diff --git a/sugar/bundle/activitybundle.py b/sugar/bundle/activitybundle.py index ee72f80..5f1fb7b 100644 --- a/sugar/bundle/activitybundle.py +++ b/sugar/bundle/activitybundle.py @@ -217,8 +217,9 @@ class ActivityBundle(Bundle): return False def install(self): + activities_path = env.get_user_activities_path() act = activity.get_registry().get_activity(self._bundle_id) - if act is not None and act.path.startswith(env.get_user_activities_path()): + if act is not None and act.path.startswith(activities_path): raise AlreadyInstalledException install_dir = env.get_user_activities_path() @@ -226,7 +227,8 @@ class ActivityBundle(Bundle): install_path = os.path.join(install_dir, self._zip_root_dir) - xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share')) + xdg_data_home = os.getenv('XDG_DATA_HOME', + os.path.expanduser('~/.local/share')) mime_path = os.path.join(install_path, 'activity', 'mimetypes.xml') if os.path.isfile(mime_path): @@ -234,7 +236,8 @@ class ActivityBundle(Bundle): mime_pkg_dir = os.path.join(mime_dir, 'packages') if not os.path.isdir(mime_pkg_dir): os.makedirs(mime_pkg_dir) - installed_mime_path = os.path.join(mime_pkg_dir, '%s.xml' % self._bundle_id) + installed_mime_path = os.path.join(mime_pkg_dir, + '%s.xml' % self._bundle_id) os.symlink(mime_path, installed_mime_path) os.spawnlp(os.P_WAIT, 'update-mime-database', 'update-mime-database', mime_dir) @@ -272,7 +275,7 @@ class ActivityBundle(Bundle): act = activity.get_registry().get_activity(self._bundle_id) if not force and act.version != self._activity_version: - logging.warning('Not uninstalling because different bundle present') + logging.warning('Not uninstalling, different bundle present') return elif not act.path.startswith(env.get_user_activities_path()): logging.warning('Not uninstalling system activity') @@ -281,10 +284,12 @@ class ActivityBundle(Bundle): install_path = os.path.join(env.get_user_activities_path(), self._zip_root_dir) - xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share')) + xdg_data_home = os.getenv('XDG_DATA_HOME', + os.path.expanduser('~/.local/share')) mime_dir = os.path.join(xdg_data_home, 'mime') - installed_mime_path = os.path.join(mime_dir, 'packages', '%s.xml' % self._bundle_id) + installed_mime_path = os.path.join(mime_dir, 'packages', + '%s.xml' % self._bundle_id) if os.path.exists(installed_mime_path): os.remove(installed_mime_path) os.spawnlp(os.P_WAIT, 'update-mime-database', @@ -294,8 +299,8 @@ class ActivityBundle(Bundle): if mime_types is not None: installed_icons_dir = os.path.join(xdg_data_home, 'icons/sugar/scalable/mimetypes') - for file in os.listdir(installed_icons_dir): - path = os.path.join(installed_icons_dir, file) + for f in os.listdir(installed_icons_dir): + path = os.path.join(installed_icons_dir, f) if os.path.islink(path) and \ os.readlink(path).startswith(install_path): os.remove(path) @@ -313,9 +318,11 @@ class ActivityBundle(Bundle): try: self.uninstall(force=True) except Exception, e: - logging.warning('Uninstall failed (%s), still trying to install newer bundle', e) + logging.warning('Uninstall failed (%s), still trying ' \ + 'to install newer bundle', e) else: - logging.warning('Unable to uninstall system activity, installing upgraded version in user activities') + logging.warning('Unable to uninstall system activity, ' \ + 'installing upgraded version in user activities') self.install() diff --git a/sugar/bundle/bundle.py b/sugar/bundle/bundle.py index f7f18c9..ae5e996 100644 --- a/sugar/bundle/bundle.py +++ b/sugar/bundle/bundle.py @@ -18,15 +18,27 @@ """Sugar bundle file handler""" import os +import logging import StringIO import zipfile -class AlreadyInstalledException(Exception): pass -class NotInstalledException(Exception): pass -class InvalidPathException(Exception): pass -class ZipExtractException(Exception): pass -class RegistrationException(Exception): pass -class MalformedBundleException(Exception): pass +class AlreadyInstalledException(Exception): + pass + +class NotInstalledException(Exception): + pass + +class InvalidPathException(Exception): + pass + +class ZipExtractException(Exception): + pass + +class RegistrationException(Exception): + pass + +class MalformedBundleException(Exception): + pass class Bundle: """A Sugar activity, content module, etc. @@ -38,8 +50,13 @@ class Bundle: This is an abstract base class. See ActivityBundle and ContentBundle for more details on those bundle types. """ + + _zipped_extension = None + _unzipped_extension = None + def __init__(self, path): self._path = path + self._zip_root_dir = None if os.path.isdir(self._path): self._unpacked = True @@ -66,7 +83,7 @@ class Bundle: self._zip_root_dir = file_names[0].split('/')[0] if self._unzipped_extension is not None: - (name, ext) = os.path.splitext(self._zip_root_dir) + ext = os.path.splitext(self._zip_root_dir)[0] if ext != self._unzipped_extension: raise MalformedBundleException( 'All files in the bundle must be inside a single ' + @@ -80,24 +97,23 @@ class Bundle: 'top-level directory') def _get_file(self, filename): - file = None + f = None if self._unpacked: path = os.path.join(self._path, filename) if os.path.isfile(path): - file = open(path) + f = open(path) else: zip_file = zipfile.ZipFile(self._path) path = os.path.join(self._zip_root_dir, filename) try: data = zip_file.read(path) - file = StringIO.StringIO(data) + f = StringIO.StringIO(data) except KeyError: - # == "file not found" - pass + logging.log('%s not found.' % filename) zip_file.close() - return file + return f def get_path(self): """Get the bundle path.""" @@ -123,12 +139,7 @@ class Bundle: if not self._unpacked: raise NotInstalledException - # FIXME: use manifest - zip = zipfile.ZipFile(bundle_path, 'w', zipfile.ZIP_DEFLATED) - for root, dirs, files in os.walk(self._path): - for name in files: - zip.write(filename, os.path.join(base_dir, filename)) - zip.close() + raise NotImplementedError def _uninstall(self, install_path): if not os.path.isdir(install_path): diff --git a/sugar/bundle/contentbundle.py b/sugar/bundle/contentbundle.py index 9e2d36e..effab23 100644 --- a/sugar/bundle/contentbundle.py +++ b/sugar/bundle/contentbundle.py @@ -39,6 +39,16 @@ class ContentBundle(Bundle): def __init__(self, path): Bundle.__init__(self, path) + self._locale = None + self._l10n = None + self._category = None + self._name = None + self._subcategory = None + self._category_class = None + self._category_icon = None + self._library_version = None + self._bundle_class = None + info_file = self._get_file('library/library.info') if info_file is None: raise MalformedBundleException('No library.info file') @@ -145,9 +155,6 @@ class ContentBundle(Bundle): def get_category(self): return self._category - def get_category(self): - return self._category - def get_category_icon(self): return self._category_icon @@ -161,9 +168,11 @@ class ContentBundle(Bundle): return self._bundle_class def _run_indexer(self): - os.spawnlp(os.P_WAIT, 'python', - 'python', - env.get_prefix_path('share/library-common/make_index.py')) + if os.environ.has_key('XDG_DATA_DIRS'): + for path in os.environ['XDG_DATA_DIRS'].split(':'): + indexer = os.path.join(path, 'library-common', 'make_index.py') + if os.path.exists(indexer): + os.spawnlp(os.P_WAIT, 'python', 'python', indexer) def is_installed(self): if self._unpacked: diff --git a/sugar/clipboard/clipboardservice.py b/sugar/clipboard/clipboardservice.py index d975330..59ef0fb 100644 --- a/sugar/clipboard/clipboardservice.py +++ b/sugar/clipboard/clipboardservice.py @@ -183,7 +183,8 @@ class ClipboardService(gobject.GObject): returns None """ - self._dbus_service.set_object_percent(dbus.ObjectPath(object_id), percent) + self._dbus_service.set_object_percent( + dbus.ObjectPath(object_id), percent) def get_object(self, object_id): """Retrieve the clipboard object structure for given object diff --git a/sugar/datastore/datastore.py b/sugar/datastore/datastore.py index 334c866..fda29b0 100644 --- a/sugar/datastore/datastore.py +++ b/sugar/datastore/datastore.py @@ -27,7 +27,6 @@ from sugar import activity from sugar.activity.activityhandle import ActivityHandle from sugar.bundle.contentbundle import ContentBundle from sugar.bundle.activitybundle import ActivityBundle -from sugar.bundle.contentbundle import ContentBundle from sugar import mime class DSMetadata(gobject.GObject): @@ -122,7 +121,7 @@ class DSObject(object): result = registry.get_activities_for_type(mime_type) if not result: for parent_mime in mime.get_mime_parents(mime_type): - result.extend(registry.get_activities_for_type(parent_mime)) + result.extend(registry.get_activities_for_type(parent_mime)) return result def get_activities(self): @@ -158,7 +157,7 @@ class DSObject(object): if self.is_activity_bundle(): if bundle_id is not None: - raise ValueError('Object is a bundle, cannot be resumed as an activity.') + raise ValueError('Bundle cannot be resumed as an activity.') logging.debug('Creating activity bundle') bundle = ActivityBundle(self.file_path) @@ -169,7 +168,8 @@ class DSObject(object): logging.debug('Upgrading activity bundle') bundle.upgrade() - logging.debug('activityfactory.creating bundle with id %r', bundle.get_bundle_id()) + logging.debug('activityfactory.creating bundle with id %r', + bundle.get_bundle_id()) activityfactory.create(bundle.get_bundle_id()) else: if not self.get_activities() and bundle_id is None: @@ -192,7 +192,6 @@ class DSObject(object): def destroy(self): if self._destroyed: logging.warning('This DSObject has already been destroyed!.') - import traceback;traceback.print_stack() return self._destroyed = True if self._file_path and self._owns_file: @@ -204,7 +203,7 @@ class DSObject(object): def __del__(self): if not self._destroyed: logging.warning('DSObject was deleted without cleaning up first. ' \ - 'Please call DSObject.destroy() before disposing it.') + 'Call DSObject.destroy() before disposing it.') self.destroy() def copy(self): @@ -224,7 +223,8 @@ def create(): metadata['timestamp'] = int(time.time()) return DSObject(object_id=None, metadata=metadata, file_path=None) -def write(ds_object, update_mtime=True, transfer_ownership=False, reply_handler=None, error_handler=None, timeout=-1): +def write(ds_object, update_mtime=True, transfer_ownership=False, + reply_handler=None, error_handler=None, timeout=-1): logging.debug('datastore.write') properties = ds_object.metadata.get_dictionary().copy() @@ -250,8 +250,8 @@ def write(ds_object, update_mtime=True, transfer_ownership=False, reply_handler= timeout=timeout) else: if reply_handler or error_handler: - logging.warning('datastore.write() cannot currently be called async' \ - ' for creates, see https://dev.laptop.org/ticket/3071') + logging.warning('datastore.write() cannot currently be called' \ + 'async for creates, see ticket 3071') ds_object.object_id = dbus_helpers.create(properties, file_path, transfer_ownership) @@ -274,7 +274,8 @@ def find(query, sorting=None, limit=None, offset=None, properties=[], if offset: query['offset'] = offset - props_list, total_count = dbus_helpers.find(query, properties, reply_handler, error_handler) + props_list, total_count = dbus_helpers.find(query, properties, + reply_handler, error_handler) objects = [] for props in props_list: diff --git a/sugar/datastore/dbus_helpers.py b/sugar/datastore/dbus_helpers.py index a5ce9c8..8dfb41a 100644 --- a/sugar/datastore/dbus_helpers.py +++ b/sugar/datastore/dbus_helpers.py @@ -20,9 +20,6 @@ import logging import dbus import dbus.glib -import gobject - -from sugar import util DS_DBUS_SERVICE = "org.laptop.sugar.DataStore" DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore" @@ -51,7 +48,8 @@ def update(uid, properties, filename, transfer_ownership=False, debug_props = properties.copy() if debug_props.has_key("preview"): debug_props["preview"] = "<omitted>" - logging.debug('dbus_helpers.update: %s, %s, %s, %s' % (uid, filename, debug_props, transfer_ownership)) + logging.debug('dbus_helpers.update: %s, %s, %s, %s' % + (uid, filename, debug_props, transfer_ownership)) if reply_handler and error_handler: _get_data_store().update(uid, dbus.Dictionary(properties), filename, transfer_ownership, @@ -59,7 +57,8 @@ def update(uid, properties, filename, transfer_ownership=False, error_handler=error_handler, timeout=timeout) else: - _get_data_store().update(uid, dbus.Dictionary(properties), filename, transfer_ownership) + _get_data_store().update(uid, dbus.Dictionary(properties), + filename, transfer_ownership) def delete(uid): logging.debug('dbus_helpers.delete: %r' % uid) @@ -92,7 +91,8 @@ def mounts(): return _get_data_store().mounts() def get_unique_values(key): - return _get_data_store().get_uniquevaluesfor(key, dbus.Dictionary({}, signature='ss')) + return _get_data_store().get_uniquevaluesfor( + key, dbus.Dictionary({}, signature='ss')) def complete_indexing(): return _get_data_store().complete_indexing() diff --git a/sugar/env.py b/sugar/env.py index e0b6fa9..16327fc 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -34,7 +34,7 @@ def get_profile_path(path=None): if not os.path.isdir(base): try: os.makedirs(base, 0770) - except OSError, exc: + except OSError: print "Could not create user directory." if path != None: diff --git a/sugar/graphics/animator.py b/sugar/graphics/animator.py index 459851b..85b9852 100644 --- a/sugar/graphics/animator.py +++ b/sugar/graphics/animator.py @@ -28,13 +28,14 @@ class Animator(gobject.GObject): gobject.TYPE_NONE, ([])), } - def __init__(self, time, fps=20, easing=EASE_OUT_EXPO): + def __init__(self, duration, fps=20, easing=EASE_OUT_EXPO): gobject.GObject.__init__(self) self._animations = [] - self._time = time + self._duration = duration self._interval = 1.0 / fps self._easing = easing self._timeout_sid = 0 + self._start_time = None def add(self, animation): self._animations.append(animation) @@ -58,13 +59,13 @@ class Animator(gobject.GObject): self.emit('completed') def _next_frame_cb(self): - current_time = min(self._time, time.time() - self._start_time) + current_time = min(self._duration, time.time() - self._start_time) current_time = max(current_time, 0.0) for animation in self._animations: - animation.do_frame(current_time, self._time, self._easing) + animation.do_frame(current_time, self._duration, self._easing) - if current_time == self._time: + if current_time == self._duration: self.stop() return False else: @@ -75,18 +76,18 @@ class Animation(object): self.start = start self.end = end - def do_frame(self, time, duration, easing): + def do_frame(self, t, duration, easing): start = self.start change = self.end - self.start - if time == duration: + if t == duration: # last frame frame = self.end else: if easing == EASE_OUT_EXPO: - frame = change * (-pow(2, -10 * time/duration) + 1) + start; + frame = change * (-pow(2, -10 * t / duration) + 1) + start elif easing == EASE_IN_EXPO: - frame = change * pow(2, 10 * (time / duration - 1)) + start; + frame = change * pow(2, 10 * (t / duration - 1)) + start self.next_frame(frame) diff --git a/sugar/graphics/combobox.py b/sugar/graphics/combobox.py index 5584267..2924fb3 100644 --- a/sugar/graphics/combobox.py +++ b/sugar/graphics/combobox.py @@ -14,9 +14,6 @@ # License along with this library; if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -import sys -import os -import logging import gobject import gtk @@ -44,17 +41,17 @@ class ComboBox(gtk.ComboBox): def do_get_property(self, pspec): if pspec.name == 'value': - row = self.get_active_item() - if not row: + row = self.get_active_item() + if not row: return None - return row[0] + return row[0] else: return gtk.ComboBox.do_get_property(self, pspec) def _get_real_name_from_theme(self, name, size): icon_theme = gtk.icon_theme_get_default() width, height = gtk.icon_size_lookup(size) - info = icon_theme.lookup_icon(name, width, 0) + info = icon_theme.lookup_icon(name, max(width, height), 0) if not info: raise ValueError("Icon '" + name + "' not found.") fname = info.get_filename() @@ -66,8 +63,9 @@ class ComboBox(gtk.ComboBox): self._icon_renderer = gtk.CellRendererPixbuf() settings = self.get_settings() - w, h = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) - self._icon_renderer.props.stock_size = w + w, h = gtk.icon_size_lookup_for_settings( + settings, gtk.ICON_SIZE_MENU) + self._icon_renderer.props.stock_size = max(w, h) self.pack_start(self._icon_renderer, False) self.add_attribute(self._icon_renderer, 'pixbuf', 2) @@ -87,7 +85,8 @@ class ComboBox(gtk.ComboBox): if icon_name: file_name = self._get_real_name_from_theme(icon_name, size) - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(file_name, width, height) + pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( + file_name, width, height) else: pixbuf = None @@ -110,5 +109,4 @@ class ComboBox(gtk.ComboBox): self._model.clear() def _is_separator(self, model, row): - action_id, text, icon_name, is_separator = model[row] - return is_separator + return model[row][3] diff --git a/sugar/graphics/icon.py b/sugar/graphics/icon.py index 213b3bc..2bd73c8 100644 --- a/sugar/graphics/icon.py +++ b/sugar/graphics/icon.py @@ -15,10 +15,8 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -import os import re import math -import time import logging import gobject @@ -26,10 +24,7 @@ import gtk import hippo import cairo -from sugar.graphics.style import Color from sugar.graphics.xocolor import XoColor -from sugar.graphics import style -from sugar.graphics.palette import Palette, CanvasInvoker from sugar.util import LRU _BADGE_SIZE = 0.45 @@ -79,6 +74,7 @@ class _IconBuffer(object): def __init__(self): self.icon_name = None + self.icon_size = None self.file_name = None self.fill_color = None self.stroke_color = None @@ -362,10 +358,11 @@ class Icon(gtk.Image): if self.get_direction() != gtk.TEXT_DIR_LTR: xalign = 1.0 - xalign - x = math.floor(self.allocation.x + xpad + - (self.allocation.width - requisition[0]) * xalign) - y = math.floor(self.allocation.y + ypad + - (self.allocation.height - requisition[1]) * yalign) + allocation = self.get_allocation() + x = math.floor(allocation.x + xpad + + (allocation.width - requisition[0]) * xalign) + y = math.floor(allocation.y + ypad + + (allocation.height - requisition[1]) * yalign) cr = self.window.cairo_create() cr.set_source_surface(surface, x, y) @@ -464,7 +461,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): self._buffer.height = value self.emit_request_changed() elif pspec.name == 'scale': - logging.warning('CanvasIcon: the scale parameter is currently unsupported') + logging.warning( + 'CanvasIcon: the scale parameter is currently unsupported') if self._buffer.scale != value: self._buffer.scale = value self.emit_request_changed() @@ -534,6 +532,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): return self._palette def set_palette(self, palette): + from sugar.graphics.palette import CanvasInvoker + if self._palette is not None: self._palette.props.invoker = None self._palette = palette @@ -541,18 +541,20 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): self._palette.props.invoker = CanvasInvoker(self) def set_tooltip(self, text): + from sugar.graphics.palette import Palette + self.set_palette(Palette(text)) palette = property(get_palette, set_palette) def get_icon_state(base_name, perc): - step = 5 - strength = round(perc / step) * step - icon_theme = gtk.icon_theme_get_default() + step = 5 + strength = round(perc / step) * step + icon_theme = gtk.icon_theme_get_default() - while strength <= 100: - icon_name = '%s-%03d' % (base_name, strength) - if icon_theme.has_icon(icon_name): - return icon_name + while strength <= 100: + icon_name = '%s-%03d' % (base_name, strength) + if icon_theme.has_icon(icon_name): + return icon_name - strength = strength + step + strength = strength + step diff --git a/sugar/graphics/iconentry.py b/sugar/graphics/iconentry.py index a1fed31..df38b9e 100644 --- a/sugar/graphics/iconentry.py +++ b/sugar/graphics/iconentry.py @@ -21,7 +21,6 @@ from sugar import _sugarext from sugar.graphics import style from sugar.graphics.icon import _SVGLoader -import sugar.profile ICON_ENTRY_PRIMARY = _sugarext.ICON_ENTRY_PRIMARY ICON_ENTRY_SECONDARY = _sugarext.ICON_ENTRY_SECONDARY @@ -44,7 +43,6 @@ class IconEntry(_sugarext.IconEntry): if icon_info.get_filename().endswith('.svg'): loader = _SVGLoader() - color = sugar.profile.get_color() entities = {'fill_color': style.COLOR_TOOLBAR_GREY.get_svg(), 'stroke_color': style.COLOR_TOOLBAR_GREY.get_svg()} handle = loader.load(icon_info.get_filename(), entities, None) diff --git a/sugar/graphics/menuitem.py b/sugar/graphics/menuitem.py index 908cc1f..3d6764b 100644 --- a/sugar/graphics/menuitem.py +++ b/sugar/graphics/menuitem.py @@ -29,5 +29,6 @@ class MenuItem(gtk.ImageMenuItem): icon.show() if text_maxlen > 0: - self.child.set_ellipsize(pango.ELLIPSIZE_MIDDLE) - self.child.set_max_width_chars(text_maxlen) + child = self.get_child() + child.set_ellipsize(pango.ELLIPSIZE_MIDDLE) + child.set_max_width_chars(text_maxlen) diff --git a/sugar/graphics/notebook.py b/sugar/graphics/notebook.py index 2d49b1f..bc6bab5 100644 --- a/sugar/graphics/notebook.py +++ b/sugar/graphics/notebook.py @@ -30,7 +30,8 @@ class Notebook(gtk.Notebook): __gproperties__ = { 'can-close-tabs': (bool, None, None, False, - gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT_ONLY) + gobject.PARAM_READWRITE | + gobject.PARAM_CONSTRUCT_ONLY) } def __init__(self, **kwargs): @@ -41,7 +42,8 @@ class Notebook(gtk.Notebook): # Set True the scrollable notebook property gobject.GObject.__init__(self, **kwargs) - gtk.Notebook.__init__(self) + + self._can_close_tabs = None self.set_scrollable(True) self.show() @@ -59,7 +61,7 @@ class Notebook(gtk.Notebook): gtk.Button.set_relief(button, gtk.RELIEF_NONE) settings = gtk.Widget.get_settings(button) - (w,h) = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) + w, h = gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) gtk.Widget.set_size_request(button, w + 4, h + 4) image.show() icon_box.pack_start(image, True, False, 0) @@ -77,7 +79,6 @@ class Notebook(gtk.Notebook): # Add a picture on a button self._add_icon_to_button(tab_button) - icon_box = gtk.HBox(False, 0) event_box.show() tab_button.show() diff --git a/sugar/graphics/objectchooser.py b/sugar/graphics/objectchooser.py index 59f1a8a..51fa3a7 100644 --- a/sugar/graphics/objectchooser.py +++ b/sugar/graphics/objectchooser.py @@ -16,7 +16,6 @@ # Boston, MA 02111-1307, USA. import logging -import time import gobject import gtk diff --git a/sugar/graphics/palette.py b/sugar/graphics/palette.py index 61c94b7..e2dfd21 100644 --- a/sugar/graphics/palette.py +++ b/sugar/graphics/palette.py @@ -20,13 +20,13 @@ import logging import gtk import gobject -import time import hippo import pango from sugar.graphics import palettegroup from sugar.graphics import animator from sugar.graphics import style +from sugar.graphics.icon import Icon from sugar import _sugarext # Helper function to find the gap position and size of widget a @@ -81,10 +81,9 @@ class MouseSpeedDetector(gobject.GObject): self._threshold = thresh self._parent = parent self._delay = delay - self._state = None - self._timeout_hid = None + self._mouse_pos = None def start(self): self._state = None @@ -99,8 +98,7 @@ class MouseSpeedDetector(gobject.GObject): def _get_mouse_position(self): display = gtk.gdk.display_get_default() - screen, x, y, mask = display.get_pointer() - return (x, y) + return display.get_pointer()[1:3] def _detect_motion(self): oldx, oldy = self._mouse_pos @@ -225,7 +223,7 @@ class Palette(gtk.Window): self.set_decorated(False) self.set_resizable(False) # Just assume xthickness and ythickness are the same - self.set_border_width(self.style.xthickness) + self.set_border_width(self.get_style().xthickness) primary_box.set_size_request(-1, style.zoom(style.GRID_CELL_SIZE) - 2 * self.get_border_width()) @@ -242,7 +240,11 @@ class Palette(gtk.Window): self._invoker = None self._group_id = None self._up = False + self._menu_box = None + self._content = None self._palette_popup_sid = None + self._enter_invoker_hid = None + self._leave_invoker_hid = None # we set these for backward compatibility if label is not None: @@ -291,7 +293,7 @@ class Palette(gtk.Window): # Prevent a warning from pygtk if previous_style is not None: gtk.Window.do_style_set(self, previous_style) - self.set_border_width(self.style.xthickness) + self.set_border_width(self.get_style().xthickness) def is_up(self): return self._up @@ -462,19 +464,18 @@ class Palette(gtk.Window): else: gap = False + allocation = self.get_allocation() + wstyle = self.get_style() + if gap: - self.style.paint_box_gap(event.window, gtk.STATE_PRELIGHT, - gtk.SHADOW_IN, event.area, self, "palette", - 0, 0, - self.allocation.width, - self.allocation.height, - gap[0], gap[1], gap[2]) - else: - self.style.paint_box(event.window, gtk.STATE_PRELIGHT, + wstyle.paint_box_gap(event.window, gtk.STATE_PRELIGHT, gtk.SHADOW_IN, event.area, self, "palette", - 0, 0, - self.allocation.width, - self.allocation.height) + 0, 0, allocation.width, allocation.height, + gap[0], gap[1], gap[2]) + else: + wstyle.paint_box(event.window, gtk.STATE_PRELIGHT, + gtk.SHADOW_IN, event.area, self, "palette", + 0, 0, allocation.width, allocation.height) # Fall trough to the container expose handler. # (Leaving out the window expose handler which redraws everything) @@ -633,8 +634,8 @@ class Palette(gtk.Window): self.emit('popup') class PaletteActionBar(gtk.HButtonBox): - def add_action(label, icon_name=None): - button = Button(label) + def add_action(self, label, icon_name=None): + button = gtk.Button(label) if icon_name: icon = Icon(icon_name) @@ -736,7 +737,7 @@ class Invoker(gobject.GObject): if self._cursor_x == -1 or self._cursor_y == -1: display = gtk.gdk.display_get_default() - screen, x, y, mask = display.get_pointer() + x, y = display.get_pointer()[1:3] self._cursor_x = x self._cursor_y = y @@ -897,25 +898,25 @@ class WidgetInvoker(Invoker): return True def draw_rectangle(self, event, palette): - style = self._widget.style + wstyle = self._widget.get_style() gap = _calculate_gap(self.get_rect(), palette.get_rect()) if gap: - style.paint_box_gap(event.window, gtk.STATE_PRELIGHT, - gtk.SHADOW_IN, event.area, self._widget, - "palette-invoker", - self._widget.allocation.x, - self._widget.allocation.y, - self._widget.allocation.width, - self._widget.allocation.height, - gap[0], gap[1], gap[2]) + wstyle.paint_box_gap(event.window, gtk.STATE_PRELIGHT, + gtk.SHADOW_IN, event.area, self._widget, + "palette-invoker", + self._widget.allocation.x, + self._widget.allocation.y, + self._widget.allocation.width, + self._widget.allocation.height, + gap[0], gap[1], gap[2]) else: - style.paint_box(event.window, gtk.STATE_PRELIGHT, - gtk.SHADOW_IN, event.area, self._widget, - "palette-invoker", - self._widget.allocation.x, - self._widget.allocation.y, - self._widget.allocation.width, - self._widget.allocation.height) + wstyle.paint_box(event.window, gtk.STATE_PRELIGHT, + gtk.SHADOW_IN, event.area, self._widget, + "palette-invoker", + self._widget.allocation.x, + self._widget.allocation.y, + self._widget.allocation.width, + self._widget.allocation.height) def _enter_notify_event_cb(self, widget, event): self.emit('mouse-enter') @@ -962,7 +963,6 @@ class CanvasInvoker(Invoker): def _motion_notify_event_cb(self, button, event): if event.detail == hippo.MOTION_DETAIL_ENTER: - context = self._item.get_context() self.emit('mouse-enter') elif event.detail == hippo.MOTION_DETAIL_LEAVE: self.emit('mouse-leave') diff --git a/sugar/graphics/radiotoolbutton.py b/sugar/graphics/radiotoolbutton.py index 8cccefc..3fc815b 100644 --- a/sugar/graphics/radiotoolbutton.py +++ b/sugar/graphics/radiotoolbutton.py @@ -16,8 +16,6 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -import logging - import gtk import gobject @@ -85,20 +83,22 @@ class RadioToolButton(gtk.RadioToolButton): self._palette = palette self._palette.props.invoker = ToolInvoker(self) - palette = gobject.property(type=object, setter=set_palette, getter=get_palette) + palette = gobject.property( + type=object, setter=set_palette, getter=get_palette) def do_expose_event(self, event): + child = self.get_child() + allocation = self.get_allocation() + if self._palette and self._palette.is_up(): invoker = self._palette.props.invoker invoker.draw_rectangle(event, self._palette) - elif self.child.state == gtk.STATE_PRELIGHT: - self.child.style.paint_box(event.window, gtk.STATE_PRELIGHT, - gtk.SHADOW_NONE, event.area, - self.child, "toolbutton-prelight", - self.allocation.x, - self.allocation.y, - self.allocation.width, - self.allocation.height) + elif child.state == gtk.STATE_PRELIGHT: + child.style.paint_box(event.window, gtk.STATE_PRELIGHT, + gtk.SHADOW_NONE, event.area, + child, "toolbutton-prelight", + allocation.x, allocation.y, + allocation.width, allocation.height) gtk.RadioToolButton.do_expose_event(self, event) diff --git a/sugar/graphics/roundbox.py b/sugar/graphics/roundbox.py index 51b9e7d..573344e 100644 --- a/sugar/graphics/roundbox.py +++ b/sugar/graphics/roundbox.py @@ -29,7 +29,7 @@ class CanvasRoundBox(hippo.CanvasBox, hippo.CanvasItem): def __init__(self, **kwargs): hippo.CanvasBox.__init__(self, **kwargs) - # TODO: we should calculate this value depending on the height of the box. + # TODO: we should calculate radius depending on the height of the box. self._radius = style.zoom(10) self.props.orientation = hippo.ORIENTATION_HORIZONTAL @@ -46,18 +46,18 @@ class CanvasRoundBox(hippo.CanvasBox, hippo.CanvasItem): width -= self._BORDER_DEFAULT height -= self._BORDER_DEFAULT - cr.move_to(x + self._radius, y); + cr.move_to(x + self._radius, y) cr.arc(x + width - self._radius, y + self._radius, - self._radius, math.pi * 1.5, math.pi * 2); + self._radius, math.pi * 1.5, math.pi * 2) cr.arc(x + width - self._radius, x + height - self._radius, - self._radius, 0, math.pi * 0.5); + self._radius, 0, math.pi * 0.5) cr.arc(x + self._radius, y + height - self._radius, - self._radius, math.pi * 0.5, math.pi); + self._radius, math.pi * 0.5, math.pi) cr.arc(x + self._radius, y + self._radius, self._radius, - math.pi, math.pi * 1.5); + math.pi, math.pi * 1.5) hippo.cairo_set_source_rgba32(cr, self.props.background_color) - cr.fill_preserve(); + cr.fill_preserve() # TODO: we should be more consistent here with the border properties. if self.props.border_color: diff --git a/sugar/graphics/toggletoolbutton.py b/sugar/graphics/toggletoolbutton.py index 3d05cc0..4c59f80 100644 --- a/sugar/graphics/toggletoolbutton.py +++ b/sugar/graphics/toggletoolbutton.py @@ -46,17 +46,18 @@ class ToggleToolButton(gtk.ToggleToolButton): self.set_palette(Palette(text)) def do_expose_event(self, event): + allocation = self.get_allocation() + child = self.get_child() + if self._palette and self._palette.is_up(): invoker = self._palette.props.invoker invoker.draw_rectangle(event, self._palette) - elif self.child.state == gtk.STATE_PRELIGHT: - self.child.style.paint_box(event.window, gtk.STATE_PRELIGHT, - gtk.SHADOW_NONE, event.area, - self.child, "toolbutton-prelight", - self.allocation.x, - self.allocation.y, - self.allocation.width, - self.allocation.height) + elif child.state == gtk.STATE_PRELIGHT: + child.style.paint_box(event.window, gtk.STATE_PRELIGHT, + gtk.SHADOW_NONE, event.area, + child, "toolbutton-prelight", + allocation.x, allocation.y, + allocation.width, allocation.height) gtk.ToggleToolButton.do_expose_event(self, event) diff --git a/sugar/graphics/toolbox.py b/sugar/graphics/toolbox.py index e5ae141..4897add 100644 --- a/sugar/graphics/toolbox.py +++ b/sugar/graphics/toolbox.py @@ -19,7 +19,6 @@ import gtk import gobject import hippo -from sugar.graphics.toolbutton import ToolButton from sugar.graphics import style class Toolbox(gtk.VBox): @@ -60,7 +59,7 @@ class Toolbox(gtk.VBox): def add_toolbar(self, name, toolbar): label = gtk.Label(name) - width, height = label.size_request() + width = label.size_request()[0] label.set_size_request(max(width, style.TOOLBOX_TAB_LABEL_WIDTH), -1) label.set_alignment(0.0, 0.5) diff --git a/sugar/graphics/toolbutton.py b/sugar/graphics/toolbutton.py index 08bc1f3..236d7ec 100644 --- a/sugar/graphics/toolbutton.py +++ b/sugar/graphics/toolbutton.py @@ -106,20 +106,21 @@ class ToolButton(gtk.ToolButton): self._palette = palette self._palette.props.invoker = ToolInvoker(self) - palette = gobject.property(type=object, setter=set_palette, getter=get_palette) + palette = gobject.property( + type=object, setter=set_palette, getter=get_palette) def do_expose_event(self, event): + child = self.get_child() + allocation = self.get_allocation() if self._palette and self._palette.is_up(): invoker = self._palette.props.invoker invoker.draw_rectangle(event, self._palette) - elif self.child.state == gtk.STATE_PRELIGHT: - self.child.style.paint_box(event.window, gtk.STATE_PRELIGHT, - gtk.SHADOW_NONE, event.area, - self.child, "toolbutton-prelight", - self.allocation.x, - self.allocation.y, - self.allocation.width, - self.allocation.height) + elif child.state == gtk.STATE_PRELIGHT: + child.style.paint_box(event.window, gtk.STATE_PRELIGHT, + gtk.SHADOW_NONE, event.area, + child, "toolbutton-prelight", + allocation.x, allocation.y, + allocation.width, allocation.height) gtk.ToolButton.do_expose_event(self, event) diff --git a/sugar/graphics/tray.py b/sugar/graphics/tray.py index 064c3d0..abc8df3 100644 --- a/sugar/graphics/tray.py +++ b/sugar/graphics/tray.py @@ -68,27 +68,29 @@ class _TrayViewport(gtk.Viewport): self._scroll_next() def _scroll_next(self): + allocation = self.get_allocation() if self.orientation == gtk.ORIENTATION_HORIZONTAL: adj = self.get_hadjustment() - new_value = adj.value + self.allocation.width - adj.value = min(new_value, adj.upper - self.allocation.width) + new_value = adj.value + allocation.width + adj.value = min(new_value, adj.upper - allocation.width) else: adj = self.get_vadjustment() - new_value = adj.value + self.allocation.height - adj.value = min(new_value, adj.upper - self.allocation.height) + new_value = adj.value + allocation.height + adj.value = min(new_value, adj.upper - allocation.height) def _scroll_previous(self): + allocation = self.get_allocation() if self.orientation == gtk.ORIENTATION_HORIZONTAL: adj = self.get_hadjustment() - new_value = adj.value - self.allocation.width + new_value = adj.value - allocation.width adj.value = max(adj.lower, new_value) else: adj = self.get_vadjustment() - new_value = adj.value - self.allocation.height + new_value = adj.value - allocation.height adj.value = max(adj.lower, new_value) def do_size_request(self, requisition): - child_requisition = self.child.size_request() + child_requisition = self.get_child().size_request() if self.orientation == gtk.ORIENTATION_HORIZONTAL: requisition[0] = 0 requisition[1] = child_requisition[1] diff --git a/sugar/graphics/window.py b/sugar/graphics/window.py index 3189400..ced5595 100644 --- a/sugar/graphics/window.py +++ b/sugar/graphics/window.py @@ -17,7 +17,6 @@ import gobject import gtk -import logging from sugar.graphics.icon import Icon @@ -71,12 +70,6 @@ class UnfullscreenButton(gtk.Window): self._reposition() class Window(gtk.Window): - - __gproperties__ = { - 'enable-fullscreen-mode': (bool, None, None, True, - gobject.PARAM_READWRITE), - } - def __init__(self, **args): self._enable_fullscreen_mode = True @@ -109,18 +102,6 @@ class Window(gtk.Window): self._unfullscreen_button.connect_button_press( self.__unfullscreen_button_pressed) - def do_get_property(self, prop): - if prop.name == 'enable-fullscreen-mode': - return self._enable_fullscreen_mode - else: - return gtk.Window.do_get_property(self, prop) - - def do_set_property(self, prop, val): - if prop.name == 'enable-fullscreen-mode': - self._enable_fullscreen_mode = val - else: - gtk.Window.do_set_property(self, prop, val) - def set_canvas(self, canvas): if self.canvas: self._event_box.remove(self.canvas) @@ -218,3 +199,14 @@ class Window(gtk.Window): def __unfullscreen_button_pressed(self, widget, event): self.unfullscreen() + + def set_enable_fullscreen_mode(self, enable_fullscreen_mode): + self._enable_fullscreen_mode = enable_fullscreen_mode + + def get_enable_fullscreen_mode(self): + return self._enable_fullscreen_mode + + enable_fullscreen_mode = gobject.property(type=object, + setter=set_enable_fullscreen_mode, + getter=get_enable_fullscreen_mode) + diff --git a/sugar/graphics/xocolor.py b/sugar/graphics/xocolor.py index d37eab1..b2da8e9 100644 --- a/sugar/graphics/xocolor.py +++ b/sugar/graphics/xocolor.py @@ -219,24 +219,24 @@ class XoColor: def __init__(self, color_string=None): if color_string == None or not is_valid(color_string): n = int(random.random() * (len(_colors) - 1)) - [self._stroke, self._fill] = _colors[n] + [self.stroke, self.fill] = _colors[n] else: - [self._stroke, self._fill] = _parse_string(color_string) + [self.stroke, self.fill] = _parse_string(color_string) def __cmp__(self, other): if isinstance(other, XoColor): - if self._stroke == other._stroke and self._fill == other._fill: + if self.stroke == other.stroke and self.fill == other.fill: return 0 return -1 def get_stroke_color(self): - return self._stroke + return self.stroke def get_fill_color(self): - return self._fill + return self.fill def to_string(self): - return '%s,%s' % (self._stroke, self._fill) + return '%s,%s' % (self.stroke, self.fill) if __name__ == "__main__": import sys diff --git a/sugar/network.py b/sugar/network.py index 49d4882..db8a562 100644 --- a/sugar/network.py +++ b/sugar/network.py @@ -15,8 +15,6 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -# pylint: disable-msg = W0221 - import socket import os import threading @@ -56,7 +54,8 @@ class GlibTCPServer(SocketServer.TCPServer): request_queue_size = 20 def __init__(self, server_address, RequestHandlerClass): - SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass) + SocketServer.TCPServer.__init__(self, server_address, + RequestHandlerClass) self.socket.setblocking(0) # Set nonblocking # Watch the listener socket for data @@ -87,7 +86,8 @@ class ChunkedGlibHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def __init__(self, request, client_address, server): self._file = None self._srcid = 0 - SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self, request, client_address, server) + SimpleHTTPServer.SimpleHTTPRequestHandler.__init__( + self, request, client_address, server) def log_request(self, code='-', size='-'): pass @@ -96,7 +96,9 @@ class ChunkedGlibHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): """Serve a GET request.""" self._file = self.send_head() if self._file: - self._srcid = gobject.io_add_watch(self.wfile, gobject.IO_OUT | gobject.IO_ERR, self._send_next_chunk) + self._srcid = gobject.io_add_watch(self.wfile, gobject.IO_OUT | + gobject.IO_ERR, + self._send_next_chunk) else: self._file.close() self._cleanup() @@ -169,7 +171,8 @@ class ChunkedGlibHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): self.send_response(200) self.send_header("Content-type", ctype) self.send_header("Content-Length", str(os.fstat(f.fileno())[6])) - self.send_header("Content-Disposition", 'attachment; filename="%s"' % os.path.basename(path)) + self.send_header("Content-Disposition", 'attachment; filename="%s"' % + os.path.basename(path)) self.end_headers() return f @@ -195,6 +198,8 @@ class GlibURLDownloader(gobject.GObject): self._srcid = 0 self._fname = None self._outf = None + self._suggested_fname = None + self._info = None self._written = 0 gobject.GObject.__init__(self) @@ -203,7 +208,8 @@ class GlibURLDownloader(gobject.GObject): self._outf = None self._fname = None if destfd and not destfile: - raise ValueError("Must provide destination file too when specifying file descriptor") + raise ValueError("Must provide destination file too when" \ + "specifying file descriptor") if destfile: self._suggested_fname = os.path.basename(destfile) self._fname = os.path.abspath(os.path.expanduser(destfile)) @@ -211,15 +217,18 @@ class GlibURLDownloader(gobject.GObject): # Use the user-supplied destination file descriptor self._outf = destfd else: - self._outf = os.open(self._fname, os.O_RDWR | os.O_TRUNC | os.O_CREAT, 0644) + self._outf = os.open(self._fname, os.O_RDWR | + os.O_TRUNC | os.O_CREAT, 0644) else: - self._suggested_fname = self._get_filename_from_headers(self._info.headers) - garbage, path = urllib.splittype(self._url) - garbage, path = urllib.splithost(path or "") - path, garbage = urllib.splitquery(path or "") - path, garbage = urllib.splitattr(path or "") + fname = self._get_filename_from_headers(self._info.headers) + self._suggested_fname = fname + path = urllib.splittype(self._url)[1] + path = urllib.splithost(path or "")[1] + path = urllib.splitquery(path or "")[0] + path = urllib.splitattr(path or "")[0] suffix = os.path.splitext(path)[1] - (self._outf, self._fname) = tempfile.mkstemp(suffix=suffix, dir=self._destdir) + (self._outf, self._fname) = tempfile.mkstemp(suffix=suffix, + dir=self._destdir) fcntl.fcntl(self._info.fp.fileno(), fcntl.F_SETFD, os.O_NDELAY) self._srcid = gobject.io_add_watch(self._info.fp.fileno(), @@ -313,7 +322,8 @@ class GlibXMLRPCRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler): traceback.print_exc() _del_authinfo() -class GlibXMLRPCServer(GlibTCPServer, SimpleXMLRPCServer.SimpleXMLRPCDispatcher): +class GlibXMLRPCServer(GlibTCPServer, + SimpleXMLRPCServer.SimpleXMLRPCDispatcher): """GlibXMLRPCServer Use nonblocking sockets and handle the accept via glib rather than @@ -324,7 +334,8 @@ class GlibXMLRPCServer(GlibTCPServer, SimpleXMLRPCServer.SimpleXMLRPCDispatcher) logRequests=0, allow_none=False): self.logRequests = logRequests if sys.version_info[:3] >= (2, 5, 0): - SimpleXMLRPCServer.SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding="utf-8") + SimpleXMLRPCServer.SimpleXMLRPCDispatcher.__init__( + self, allow_none, encoding="utf-8") else: SimpleXMLRPCServer.SimpleXMLRPCDispatcher.__init__(self) GlibTCPServer.__init__(self, addr, requestHandler) @@ -381,13 +392,14 @@ class GlibXMLRPCTransport(xmlrpclib.Transport): # @return A connection handle. def __init__(self, use_datetime=0): + self.verbose = None if sys.version_info[:3] >= (2, 5, 0): xmlrpclib.Transport.__init__(self, use_datetime) def make_connection(self, host): """Use our own connection object so we can get its socket.""" # create a HTTP connection object from a host descriptor - host, extra_headers, x509 = self.get_host_info(host) + host = self.get_host_info(host)[0] return GlibHTTP(host) ## @@ -399,7 +411,8 @@ class GlibXMLRPCTransport(xmlrpclib.Transport): # @param verbose Debugging flag. # @return Parsed response. - def start_request(self, host, handler, request_body, verbose=0, reply_handler=None, error_handler=None, user_data=None): + def start_request(self, host, handler, request_body, verbose=0, + reply_handler=None, error_handler=None, user_data=None): """Do the first half of the request by sending data to the remote server. The bottom half bits get run when the remote server's response actually comes back.""" @@ -416,10 +429,12 @@ class GlibXMLRPCTransport(xmlrpclib.Transport): # Schedule a GIOWatch so we don't block waiting for the response gobject.io_add_watch(h._conn.sock, gobject.IO_IN, self._finish_request, - h, host, handler, verbose, reply_handler, error_handler, user_data) + h, host, handler, verbose, reply_handler, error_handler, user_data) - def _finish_request(self, source, condition, h, host, handler, verbose, reply_handler=None, error_handler=None, user_data=None): - """Parse and return response when the remote server actually returns it.""" + def _finish_request(self, source, condition, h, host, handler, verbose, + reply_handler=None, error_handler=None, user_data=None): + """Parse and return response when the + remote server actually returns it.""" if not (condition & gobject.IO_IN): return True @@ -434,7 +449,8 @@ class GlibXMLRPCTransport(xmlrpclib.Transport): return False if errcode != 200: - raise xmlrpclib.ProtocolError(host + handler, errcode, errmsg, headers) + raise xmlrpclib.ProtocolError(host + handler, errcode, + errmsg, headers) self.verbose = verbose response = self._parse_response(h.getfile(), h._conn.sock) if reply_handler: @@ -485,10 +501,10 @@ class GlibServerProxy(xmlrpclib.ServerProxy): self._encoding = encoding self._verbose = verbose self._allow_none = allow_none - xmlrpclib.ServerProxy.__init__(self, uri, self._transport, encoding, verbose, allow_none) + xmlrpclib.ServerProxy.__init__(self, uri, self._transport, + encoding, verbose, allow_none) # get the url - import urllib urltype, uri = urllib.splittype(uri) if urltype not in ("http", "https"): raise IOError, "unsupported XML-RPC protocol" @@ -499,7 +515,8 @@ class GlibServerProxy(xmlrpclib.ServerProxy): def __request(self, methodname, *args, **kwargs): """Call the method on the remote server. We just start the request here and the transport itself takes care of scheduling the response callback - when the remote server returns the response. We don't want to block anywhere.""" + when the remote server returns the response. + We don't want to block anywhere.""" request = xmlrpclib.dumps(args, methodname, encoding=self._encoding, allow_none=self._allow_none) diff --git a/sugar/presence/activity.py b/sugar/presence/activity.py index b0110a0..ad21158 100644 --- a/sugar/presence/activity.py +++ b/sugar/presence/activity.py @@ -64,6 +64,7 @@ class Activity(gobject.GObject): def __init__(self, bus, new_obj_cb, del_obj_cb, object_path): """Initialse the activity interface, connecting to service""" gobject.GObject.__init__(self) + self._telepathy_room_handle = None self._object_path = object_path self._ps_new_object = new_obj_cb self._ps_del_object = del_obj_cb diff --git a/sugar/presence/presenceservice.py b/sugar/presence/presenceservice.py index cb47a3a..0549d3c 100644 --- a/sugar/presence/presenceservice.py +++ b/sugar/presence/presenceservice.py @@ -70,6 +70,7 @@ class PresenceService(gobject.GObject): """ gobject.GObject.__init__(self) self._objcache = {} + self._joined = None # Get a connection to the session bus self._bus = dbus.SessionBus() @@ -121,7 +122,8 @@ class PresenceService(gobject.GObject): ) except dbus.exceptions.DBusException, err: _logger.error( - """Failure retrieving %r interface from the D-BUS service %r %r: %s""", + """Failure retrieving %r interface from + the D-BUS service %r %r: %s""", DBUS_INTERFACE, DBUS_SERVICE, DBUS_PATH, err ) if self._allow_offline_iface: @@ -129,17 +131,24 @@ class PresenceService(gobject.GObject): raise RuntimeError("Failed to connect to the presence service.") else: self._ps_ = ps - ps.connect_to_signal('BuddyAppeared', self._buddy_appeared_cb) - ps.connect_to_signal('BuddyDisappeared', self._buddy_disappeared_cb) - ps.connect_to_signal('ActivityAppeared', self._activity_appeared_cb) - ps.connect_to_signal('ActivityDisappeared', self._activity_disappeared_cb) - ps.connect_to_signal('ActivityInvitation', self._activity_invitation_cb) - ps.connect_to_signal('PrivateInvitation', self._private_invitation_cb) + ps.connect_to_signal('BuddyAppeared', + self._buddy_appeared_cb) + ps.connect_to_signal('BuddyDisappeared', + self._buddy_disappeared_cb) + ps.connect_to_signal('ActivityAppeared', + self._activity_appeared_cb) + ps.connect_to_signal('ActivityDisappeared', + self._activity_disappeared_cb) + ps.connect_to_signal('ActivityInvitation', + self._activity_invitation_cb) + ps.connect_to_signal('PrivateInvitation', + self._private_invitation_cb) return self._ps_ _ps = property( _get_ps, None, None, - """DBUS interface to the PresenceService (services/presence/presenceservice)""" + """DBUS interface to the PresenceService + (services/presence/presenceservice)""" ) def _new_object(self, object_path): @@ -170,8 +179,8 @@ class PresenceService(gobject.GObject): try: # Pre-fill the activity's ID foo = obj.props.id - except dbus.exceptions.DBusException, err: - pass + except dbus.exceptions.DBusException: + logging.debug('Cannot get the activity ID') else: raise RuntimeError("Unknown object type") self._objcache[object_path] = obj @@ -182,7 +191,8 @@ class PresenceService(gobject.GObject): return object_path in self._objcache.keys() def _del_object(self, object_path): - """Fully remove an object from the object cache when it's no longer needed. + """Fully remove an object from the object cache when + it's no longer needed. """ del self._objcache[object_path] @@ -236,7 +246,7 @@ class PresenceService(gobject.GObject): def _private_invitation_cb(self, bus_name, connection, channel): """Callback for dbus event (forwards to method to emit GObject event)""" - gobject.idle_add(self._emit_service_disappeared_signal, bus_name, + gobject.idle_add(self._emit_private_invitation_signal, bus_name, connection, channel) def _emit_activity_appeared_signal(self, object_path): @@ -304,12 +314,15 @@ class PresenceService(gobject.GObject): """ if not reply_handler: - logging.error('Function get_activities_async called without a reply handler. Can not run.') + logging.error('Function get_activities_async called without' \ + 'a reply handler. Can not run.') return self._ps.GetActivities( - reply_handler=lambda resp:self._get_activities_cb(reply_handler, resp), - error_handler=lambda e:self._get_activities_error_cb(error_handler, e)) + reply_handler=lambda resp: \ + self._get_activities_cb(reply_handler, resp), + error_handler=lambda e: \ + self._get_activities_error_cb(error_handler, e)) def get_activity(self, activity_id, warn_if_none=True): @@ -370,12 +383,15 @@ class PresenceService(gobject.GObject): """ if not reply_handler: - logging.error('Function get_buddies_async called without a reply handler. Can not run.') + logging.error('Function get_buddies_async called without' \ + 'a reply handler. Can not run.') return self._ps.GetBuddies( - reply_handler=lambda resp:self._get_buddies_cb(reply_handler, resp), - error_handler=lambda e:self._get_buddies_error_cb(error_handler, e)) + reply_handler=lambda resp: \ + self._get_buddies_cb(reply_handler, resp), + error_handler=lambda e: \ + self._get_buddies_error_cb(error_handler, e)) def get_buddy(self, key): """Retrieve single Buddy object for the given public key @@ -390,7 +406,8 @@ class PresenceService(gobject.GObject): buddy_op = self._ps.GetBuddyByPublicKey(dbus.ByteArray(key)) except dbus.exceptions.DBusException, err: _logger.warn( - """Unable to retrieve buddy handle for %r from presence service: %s""" + """Unable to retrieve buddy handle + for %r from presence service: %s""" % key, err ) return None @@ -428,10 +445,11 @@ class PresenceService(gobject.GObject): owner_op = self._ps.GetOwner() except dbus.exceptions.DBusException, err: _logger.warn( - """Unable to retrieve local user/owner from presence service: %s""" + """Unable to retrieve local user/owner + from presence service: %s""" % err ) - raise RuntimeError("Could not get owner object from presence service.") + raise RuntimeError("Could not get owner object.") return self._new_object(owner_op) def _share_activity_cb(self, activity, op): @@ -447,7 +465,8 @@ class PresenceService(gobject.GObject): def _share_activity_error_cb(self, activity, err): """Notify with GObject event of unsuccessful sharing of activity""" - _logger.debug("Error sharing activity %s: %s" % (activity.get_id(), err)) + _logger.debug("Error sharing activity %s: %s" % + (activity.get_id(), err)) self.emit("activity-shared", False, None, err) def share_activity(self, activity, properties={}, private=True): @@ -521,7 +540,8 @@ class _OfflineInterface( object ): ): """Pretend to share and fail...""" exc = IOError( - """Unable to share activity as PresenceService is not currenly available""" + """Unable to share activity as PresenceService + is not currenly available""" ) return error_handler( exc ) diff --git a/sugar/util.py b/sugar/util.py index 8a3fb4a..12f6824 100644 --- a/sugar/util.py +++ b/sugar/util.py @@ -21,11 +21,6 @@ import sha import random import binascii import string -import os -import logging - -from ConfigParser import ConfigParser -from ConfigParser import NoOptionError def printable_hash(in_hash): """Convert binary hash data into printable characters.""" @@ -65,7 +60,7 @@ def is_hex(s): def validate_activity_id(actid): """Validate an activity ID.""" - if not isinstance(actid, (str,unicode)): + if not isinstance(actid, (str, unicode)): return False if len(actid) != ACTIVITY_ID_LEN: return False @@ -92,7 +87,7 @@ def set_proc_title(title): libc.prctl(15, str(title), 0, 0, 0) return True - except: + except Exception: return False class Node(object): @@ -169,7 +164,7 @@ class LRU: def iterkeys(self): return iter(self.d) def itervalues(self): - for i,j in self.iteritems(): + for i, j in self.iteritems(): yield j def keys(self): return self.d.keys() |