From cda47a41f4fd06cc06f94eec1451fac33e423ade Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 11:22:51 +0100 Subject: [PATCH 01/12] Implement ToggleIconButton --- sugar/graphics/Makefile.am | 1 + sugar/graphics/color.py | 4 +- sugar/graphics/iconbutton.py | 4 +- sugar/graphics/toggleiconbutton.py | 71 ++++++++++++++++++++++++++++++ tests/test-button.py | 8 ++++ 5 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 sugar/graphics/toggleiconbutton.py diff --git a/sugar/graphics/Makefile.am b/sugar/graphics/Makefile.am index 6a45b3c7..9479ea23 100644 --- a/sugar/graphics/Makefile.am +++ b/sugar/graphics/Makefile.am @@ -20,6 +20,7 @@ sugar_PYTHON = \ snowflakebox.py \ spreadbox.py \ timeline.py \ + toggleiconbutton.py \ toolbar.py \ units.py \ window.py \ diff --git a/sugar/graphics/color.py b/sugar/graphics/color.py index 068aa160..1aa0b916 100644 --- a/sugar/graphics/color.py +++ b/sugar/graphics/color.py @@ -21,7 +21,8 @@ _system_colors = { 'button-hover' : '#808080', 'button-background-hover' : '#000000', 'icon-stroke-inactive' : '#757575', - 'icon-fill-inactive' : '#9D9FA1' + 'icon-fill-inactive' : '#9D9FA1', + 'toggle-button-background' : '#A1A5A8' } def _html_to_rgb(html_color): @@ -100,3 +101,4 @@ BUTTON_HOVER = SystemColor('button-hover') BUTTON_BACKGROUND_HOVER = SystemColor('button-background-hover') ICON_FILL_INACTIVE = SystemColor('icon-fill-inactive') ICON_STROKE_INACTIVE = SystemColor('icon-stroke-inactive') +TOGGLE_BUTTON_BACKGROUND = SystemColor('toggle-button-background') diff --git a/sugar/graphics/iconbutton.py b/sugar/graphics/iconbutton.py index 822ddf1f..5c807a7f 100644 --- a/sugar/graphics/iconbutton.py +++ b/sugar/graphics/iconbutton.py @@ -45,8 +45,8 @@ class IconButton(CanvasIcon): self._set_size(STANDARD_SIZE) - self.connect('button-press-event', - self._icon_button_button_press_event_cb) + self.connect_after('button-press-event', + self._icon_button_button_press_event_cb) def _set_size(self, size): if size == SMALL_SIZE: diff --git a/sugar/graphics/toggleiconbutton.py b/sugar/graphics/toggleiconbutton.py new file mode 100644 index 00000000..a637fcd1 --- /dev/null +++ b/sugar/graphics/toggleiconbutton.py @@ -0,0 +1,71 @@ +# Copyright (C) 2007, Red Hat +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# 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 gobject + +from sugar.graphics.iconbutton import IconButton +from sugar.graphics import color + +class ToggleIconButton(IconButton): + __gtype_name__ = 'SugarToggleIconButton' + + __gproperties__ = { + 'toggled' : (bool, None, None, False, + gobject.PARAM_READWRITE) + } + + def __init__(self, **kwargs): + self._toggled = False + + IconButton.__init__(self, **kwargs) + + self.connect('button-press-event', + self._toggle_icon_button_press_event_cb) + + def _get_bg_color(self): + if self._toggled: + col = color.TOGGLE_BUTTON_BACKGROUND + else: + col = color.BUTTON_BACKGROUND_NORMAL + + return col.get_int() + + def _set_toggled(self, toggled): + self._toggled = toggled + self.props.background_color = self._get_bg_color() + + def do_set_property(self, pspec, value): + if pspec.name == 'toggled': + self._set_toggled(value) + else: + IconButton.do_set_property(self, pspec, value) + + def do_get_property(self, pspec): + if pspec.name == 'toggled': + return self._toggled + + return IconButton.do_get_property(self, pspec) + + def _toggle_icon_button_press_event_cb(self, widget, event): + self.props.toggled = not self._toggled + return True + + def prelight(self, enter): + if enter: + IconButton.prelight(self, enter) + else: + self.props.background_color = self._get_bg_color() diff --git a/tests/test-button.py b/tests/test-button.py index 0f3ded26..9cceb92d 100755 --- a/tests/test-button.py +++ b/tests/test-button.py @@ -23,12 +23,16 @@ import hippo from sugar.graphics.toolbar import Toolbar from sugar.graphics.iconbutton import IconButton +from sugar.graphics.toggleiconbutton import ToggleIconButton from sugar.graphics.button import Button from sugar.graphics.entry import Entry def _button_activated_cb(button): print "_button_activated_cb" +def _toggled_changed_cb(button, pspec): + print "Toggle state: %d" % button.props.toggled + window = gtk.Window() window.connect("destroy", lambda w: gtk.main_quit()) window.show() @@ -48,6 +52,10 @@ for i in [1, 2]: icon_button = IconButton(icon_name='theme:stock-close') toolbar.append(icon_button) + toggle = ToggleIconButton(icon_name='theme:stock-back') + toggle.connect('notify::toggled', _toggled_changed_cb) + toolbar.append(toggle) + button = Button(text='Click me!', icon_name='theme:stock-close') button.connect('activated', _button_activated_cb) toolbar.append(button) From 810bea67728b78953ac585b6a15a1103e2a5c729 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 12:08:10 +0100 Subject: [PATCH 02/12] Remove unused var --- sugar/__installed__.py.in | 1 - 1 file changed, 1 deletion(-) diff --git a/sugar/__installed__.py.in b/sugar/__installed__.py.in index def17e03..afe91d10 100644 --- a/sugar/__installed__.py.in +++ b/sugar/__installed__.py.in @@ -1,5 +1,4 @@ sugar_source_dir = None sugar_data_dir = '@prefix@/share/sugar' -sugar_activity_info_dir = '@prefix@/share/sugar/activities' sugar_services_dir = '@prefix@/share/sugar/services' sugar_shell_bin_dir = '@prefix@/bin' From 2d9a06ec9a1a3779b169ec1ef70c542821270b25 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 12:32:32 +0100 Subject: [PATCH 03/12] Add the root path of the services to python path, not services/. Get rid of the now useless env.get_services_dir --- services/clipboard/sugar-clipboard | 5 +++-- services/console/sugar-console | 7 ++++--- services/datastore/sugar-data-store | 5 +++-- services/presence/sugar-presence-service | 4 ++-- services/presence2/sugar-presence-service2 | 4 ++-- sugar/__installed__.py.in | 1 - sugar/env.py | 3 --- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/services/clipboard/sugar-clipboard b/services/clipboard/sugar-clipboard index acc86571..576145c7 100755 --- a/services/clipboard/sugar-clipboard +++ b/services/clipboard/sugar-clipboard @@ -18,6 +18,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import sys +import os import logging from sugar import logger @@ -31,9 +32,9 @@ import dbus.glib from sugar import env -sys.path.insert(0, env.get_services_dir()) +sys.path.insert(0, os.path.join(env.get_data_dir(), 'services/clipboard')) -from clipboard.clipboardservice import ClipboardService +from clipboardservice import ClipboardService logging.info('Starting clipboard service.') diff --git a/services/console/sugar-console b/services/console/sugar-console index 78ea3a2c..2f2fc4fe 100755 --- a/services/console/sugar-console +++ b/services/console/sugar-console @@ -3,9 +3,10 @@ import pygtk pygtk.require('2.0') -import os, sys +import os +import sys from sugar import env -sys.path.insert(0, env.get_services_dir()) +sys.path.insert(0, os.path.join(env.get_data_dir(), 'services/console')) -import console.console +import console diff --git a/services/datastore/sugar-data-store b/services/datastore/sugar-data-store index b4a728bd..9ab14fee 100755 --- a/services/datastore/sugar-data-store +++ b/services/datastore/sugar-data-store @@ -18,16 +18,17 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import sys +import os import logging from sugar import logger from sugar import env -sys.path.insert(0, env.get_services_dir()) +sys.path.insert(0, os.path.join(env.get_data_dir(), 'services/datastore')) logger.start('data-store') logging.info('Starting the data store...') -from datastore import datastore +import datastore datastore.main() diff --git a/services/presence/sugar-presence-service b/services/presence/sugar-presence-service index b98db9a6..50c12173 100755 --- a/services/presence/sugar-presence-service +++ b/services/presence/sugar-presence-service @@ -24,11 +24,11 @@ import os from sugar import logger from sugar import env -sys.path.insert(0, env.get_services_dir()) +sys.path.insert(0, os.path.join(env.get_data_dir(), 'services/presence')) logger.start('presenceservice') -from presence import PresenceService +import PresenceService logging.info('Starting presence service') diff --git a/services/presence2/sugar-presence-service2 b/services/presence2/sugar-presence-service2 index 5b5afd1e..f71344a6 100755 --- a/services/presence2/sugar-presence-service2 +++ b/services/presence2/sugar-presence-service2 @@ -24,11 +24,11 @@ import os from sugar import logger from sugar import env -sys.path.insert(0, env.get_services_dir()) +sys.path.insert(0, os.join.path(env.get_data_dir(), 'services/presence2')) logger.start('presenceservice') -from presence2 import presenceservice +import presenceservice logging.info('Starting presence service') diff --git a/sugar/__installed__.py.in b/sugar/__installed__.py.in index afe91d10..bf7fd9b4 100644 --- a/sugar/__installed__.py.in +++ b/sugar/__installed__.py.in @@ -1,4 +1,3 @@ sugar_source_dir = None sugar_data_dir = '@prefix@/share/sugar' -sugar_services_dir = '@prefix@/share/sugar/services' sugar_shell_bin_dir = '@prefix@/bin' diff --git a/sugar/env.py b/sugar/env.py index afaa5653..7d6cc7c3 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -48,9 +48,6 @@ def get_profile_path(): def get_data_dir(): return sugar_data_dir -def get_services_dir(): - return sugar_services_dir - def get_shell_bin_dir(): return sugar_shell_bin_dir From 66e341c58ec7a6a1cb976a33103914bfddf7ebf6 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 13:12:52 +0100 Subject: [PATCH 04/12] Use button_press virtual method instead of the connect_after hacks. --- sugar/graphics/canvasicon.py | 5 ++--- sugar/graphics/iconbutton.py | 7 ++----- sugar/graphics/toggleiconbutton.py | 8 +++----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 3438c829..6f7a0a9d 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -176,7 +176,6 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): hippo.CanvasBox.__init__(self, **kwargs) - self.connect_after('button-press-event', self._button_press_event_cb) self.connect_after('motion-notify-event', self._motion_notify_event_cb) def _clear_buffers(self): @@ -326,9 +325,9 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): [width, height] = self._get_icon_size() return height - def _button_press_event_cb(self, item, event): + def do_button_press_event(self, event): item.emit_activated() - return False + return True def get_popup(self): if self._tooltip: diff --git a/sugar/graphics/iconbutton.py b/sugar/graphics/iconbutton.py index 5c807a7f..be08ead8 100644 --- a/sugar/graphics/iconbutton.py +++ b/sugar/graphics/iconbutton.py @@ -27,7 +27,7 @@ from sugar.graphics import color STANDARD_SIZE = 0 SMALL_SIZE = 1 -class IconButton(CanvasIcon): +class IconButton(CanvasIcon, hippo.CanvasItem): __gtype_name__ = 'SugarIconButton' __gproperties__ = { @@ -45,9 +45,6 @@ class IconButton(CanvasIcon): self._set_size(STANDARD_SIZE) - self.connect_after('button-press-event', - self._icon_button_button_press_event_cb) - def _set_size(self, size): if size == SMALL_SIZE: self.props.box_width = -1 @@ -72,7 +69,7 @@ class IconButton(CanvasIcon): else: return CanvasIcon.do_get_property(self, pspec) - def _icon_button_button_press_event_cb(self, widget, event): + def do_button_press_event(self, event): if self._active: self.emit_activated() return True diff --git a/sugar/graphics/toggleiconbutton.py b/sugar/graphics/toggleiconbutton.py index a637fcd1..06f55217 100644 --- a/sugar/graphics/toggleiconbutton.py +++ b/sugar/graphics/toggleiconbutton.py @@ -16,11 +16,12 @@ # Boston, MA 02111-1307, USA. import gobject +import hippo from sugar.graphics.iconbutton import IconButton from sugar.graphics import color -class ToggleIconButton(IconButton): +class ToggleIconButton(IconButton, hippo.CanvasItem): __gtype_name__ = 'SugarToggleIconButton' __gproperties__ = { @@ -33,9 +34,6 @@ class ToggleIconButton(IconButton): IconButton.__init__(self, **kwargs) - self.connect('button-press-event', - self._toggle_icon_button_press_event_cb) - def _get_bg_color(self): if self._toggled: col = color.TOGGLE_BUTTON_BACKGROUND @@ -60,7 +58,7 @@ class ToggleIconButton(IconButton): return IconButton.do_get_property(self, pspec) - def _toggle_icon_button_press_event_cb(self, widget, event): + def do_button_press_event(self, event): self.props.toggled = not self._toggled return True From c255a7b544ff773b8f77531d99b363e70fc7b0dd Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 13:28:00 +0100 Subject: [PATCH 05/12] Remove unused var --- sugar/__installed__.py.in | 1 - 1 file changed, 1 deletion(-) diff --git a/sugar/__installed__.py.in b/sugar/__installed__.py.in index bf7fd9b4..415e0e1b 100644 --- a/sugar/__installed__.py.in +++ b/sugar/__installed__.py.in @@ -1,3 +1,2 @@ -sugar_source_dir = None sugar_data_dir = '@prefix@/share/sugar' sugar_shell_bin_dir = '@prefix@/bin' From 6afd512d55dacc16758428d15dd06dd41ce8f889 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 13:47:17 +0100 Subject: [PATCH 06/12] Cleanup kbd config passing --- sugar-emulator | 10 +++++++--- sugar/emulator.py | 29 +++++++++++++++-------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/sugar-emulator b/sugar-emulator index 98e51d36..c87dc711 100755 --- a/sugar-emulator +++ b/sugar-emulator @@ -47,17 +47,21 @@ else: program = sys.argv[1] if gtk.gdk.screen_width() < 1200 or gtk.gdk.screen_height() < 900: - fullscreen = True width = -1 height = -1 else: - fullscreen = False width = 1200 height = 900 dpi = min(_sugar.get_screen_dpi(), 96) -emulator = Emulator(width, height, fullscreen, dpi) +if sourcedir: + kbd_config = os.path.join(sourcedir, 'shell/data/kbdconfig') +else: + kbd_config = os.path.join(env.get_data_dir(), 'kbdconfig') + +emulator = Emulator(width, height, dpi) +emulator.set_keyboard_config(kbd_config) emulator.start() if sourcedir: diff --git a/sugar/emulator.py b/sugar/emulator.py index 8491dbfd..90d6cf99 100644 --- a/sugar/emulator.py +++ b/sugar/emulator.py @@ -64,13 +64,13 @@ class Process: self._stdout = result[2] class MatchboxProcess(Process): - def __init__(self): - kbd_config = os.path.join(env.get_data_dir(), 'kbdconfig') - options = '-kbdconfig %s ' % kbd_config - - options += '-use_titlebar no ' + def __init__(self, kbd_config): + options = '-use_titlebar no ' options += '-theme olpc ' + if kbd_config: + options = '-kbdconfig %s ' % kbd_config + command = 'matchbox-window-manager %s ' % options Process.__init__(self, command) @@ -78,15 +78,14 @@ class MatchboxProcess(Process): return 'Matchbox' class XephyrProcess(Process): - def __init__(self, width, height, fullscreen, dpi): + def __init__(self, width, height, dpi): self._display = get_display_number() cmd = 'Xephyr :%d -ac ' % (self._display) - if fullscreen: - cmd += ' -fullscreen ' - if width > 0 and height > 0: cmd += ' -screen %dx%d' % (width, height) + else: + cmd += ' -fullscreen ' if dpi > 0: cmd += ' -dpi %d' % (dpi) @@ -103,20 +102,22 @@ class XephyrProcess(Process): class Emulator(object): """The OLPC emulator""" - def __init__(self, width, height, fullscreen, dpi): - self._fullscreen = fullscreen + def __init__(self, width, height, dpi): + self._keyboard_config = None self._width = width self._height = height self._dpi = dpi + def set_keyboard_config(self, config): + self._keyboard_config = config + def start(self): try: - process = XephyrProcess(self._width, self._height, - self._fullscreen, self._dpi) + process = XephyrProcess(self._width, self._height, self._dpi) process.start() except: print 'Cannot run the emulator. You need to install Xephyr' sys.exit(0) - process = MatchboxProcess() + process = MatchboxProcess(self._keyboard_config) process.start() From 73c1dbe4a7d8b5e54b6c16f82690200abaedf978 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 13:53:26 +0100 Subject: [PATCH 07/12] CLeanup emulator shutdown --- Makefile.am | 3 +-- shell/data/kbdconfig | 2 -- shell/view/keyhandler.py | 11 ++++++++++- sugar-emulator-shutdown | 24 ------------------------ sugar/emulator.py | 2 +- 5 files changed, 12 insertions(+), 30 deletions(-) delete mode 100755 sugar-emulator-shutdown diff --git a/Makefile.am b/Makefile.am index ac05c5d6..4606e900 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,8 +3,7 @@ SUBDIRS = lib po shell sugar services tools ACLOCAL_AMFLAGS = -I m4 bin_SCRIPTS = \ - sugar-emulator \ - sugar-emulator-shutdown + sugar-emulator DISTCLEANFILES = \ intltool-extract \ diff --git a/shell/data/kbdconfig b/shell/data/kbdconfig index 287de527..415c69ff 100644 --- a/shell/data/kbdconfig +++ b/shell/data/kbdconfig @@ -5,5 +5,3 @@ n=next p=prev c=close - -q=!sugar-emulator-shutdown diff --git a/shell/view/keyhandler.py b/shell/view/keyhandler.py index 085b51c0..0ef963ac 100644 --- a/shell/view/keyhandler.py +++ b/shell/view/keyhandler.py @@ -1,3 +1,6 @@ +import os +import signal + import dbus import gobject @@ -34,7 +37,8 @@ _actions_table = { '0xEB' : 'rotate', 'r' : 'rotate', '0xEC' : 'keyboard_brightness', - 'Tab' : 'home' + 'Tab' : 'home', + 'q' : 'quit_emulator', } class KeyHandler(object): @@ -149,6 +153,11 @@ class KeyHandler(object): gobject.spawn_async(['xrandr', '-o', states[self._screen_rotation]], flags=gobject.SPAWN_SEARCH_PATH) + def handle_quit_emulator(self): + if os.environ.has_key('SUGAR_EMULATOR_PID'): + pid = int(os.environ['SUGAR_EMULATOR_PID']) + os.kill(pid, signal.SIGTERM) + def handle_home(self): # FIXME: finish alt+tab support pass diff --git a/sugar-emulator-shutdown b/sugar-emulator-shutdown deleted file mode 100755 index 75f6de08..00000000 --- a/sugar-emulator-shutdown +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python - -# Copyright (C) 2006, Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -import os -import signal - -if os.environ.has_key('SUGAR_XEPHYR_PID'): - pid = int(os.environ['SUGAR_XEPHYR_PID']) - os.kill(pid, signal.SIGTERM) diff --git a/sugar/emulator.py b/sugar/emulator.py index 90d6cf99..bc069241 100644 --- a/sugar/emulator.py +++ b/sugar/emulator.py @@ -98,7 +98,7 @@ class XephyrProcess(Process): def start(self, standard_output=False): Process.start(self) os.environ['DISPLAY'] = ":%d" % (self._display) - os.environ['SUGAR_XEPHYR_PID'] = '%d' % self.pid + os.environ['SUGAR_EMULATOR_PID'] = '%d' % self.pid class Emulator(object): """The OLPC emulator""" From a380b7f915ca32293315176027f835fb739bb86b Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 14:07:17 +0100 Subject: [PATCH 08/12] Move data to be relative to the code. --- shell/data/Makefile.am | 5 +---- shell/intro/Makefile.am | 4 ++++ shell/{data => intro}/default-picture.png | Bin shell/intro/intro.py | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) rename shell/{data => intro}/default-picture.png (100%) diff --git a/shell/data/Makefile.am b/shell/data/Makefile.am index 2709c921..1f0f9c05 100644 --- a/shell/data/Makefile.am +++ b/shell/data/Makefile.am @@ -1,7 +1,4 @@ confdir = $(pkgdatadir) conf_DATA = kbdconfig -imagedir = $(pkgdatadir) -image_DATA = default-picture.png - -EXTRA_DIST = $(conf_DATA) $(image_DATA) +EXTRA_DIST = $(conf_DATA) diff --git a/shell/intro/Makefile.am b/shell/intro/Makefile.am index cc11aa90..3b92ea0a 100644 --- a/shell/intro/Makefile.am +++ b/shell/intro/Makefile.am @@ -1,3 +1,7 @@ +imagedir = $(pkgdatadir)/shell/intro +image_DATA = default-picture.png + +EXTRA_DIST = $(conf_DATA) $(image_DATA) sugardir = $(pkgdatadir)/shell/intro sugar_PYTHON = \ __init__.py \ diff --git a/shell/data/default-picture.png b/shell/intro/default-picture.png similarity index 100% rename from shell/data/default-picture.png rename to shell/intro/default-picture.png diff --git a/shell/intro/intro.py b/shell/intro/intro.py index 55aa1354..cdcc2a3d 100644 --- a/shell/intro/intro.py +++ b/shell/intro/intro.py @@ -143,7 +143,8 @@ class VideoBox(hippo.CanvasBox, hippo.CanvasItem): self._img_widget.props.widget = self._img if not has_webcam: - path = os.path.join(env.get_data_dir(),'default-picture.png') + path = os.path.join(os.path.dirname(__file__), + 'default-picture.png') self._video.load_image(path) def _clear_image_cb(self, widget, event): From 410e58aa6fb69d127702646711501671ab90413b Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Fri, 9 Mar 2007 14:32:43 +0100 Subject: [PATCH 09/12] Fix typo. --- sugar/graphics/canvasicon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 6f7a0a9d..a805087f 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -326,7 +326,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): return height def do_button_press_event(self, event): - item.emit_activated() + self.emit_activated() return True def get_popup(self): From 57c928916ca7cdacd728834a9b59ecc33b55339e Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 14:57:54 +0100 Subject: [PATCH 10/12] Refactor sugar.env and paths --- Makefile.am | 2 +- configure.ac | 2 +- {shell/data => emulator}/Makefile.am | 2 +- {shell/data => emulator}/kbdconfig | 0 services/clipboard/sugar-clipboard | 2 +- services/console/sugar-console | 2 +- services/datastore/sugar-data-store | 2 +- services/presence/sugar-presence-service | 2 +- services/presence2/sugar-presence-service2 | 2 +- shell/Makefile.am | 2 +- shell/sugar-shell | 2 +- sugar-emulator | 4 +- sugar/activity/bundle.py | 3 +- sugar/activity/bundlebuilder.py | 4 +- sugar/activity/bundleregistry.py | 18 +++++++-- sugar/env.py | 43 ++++++++++++---------- sugar/graphics/canvasicon.py | 2 +- tools/sugar-install-bundle | 2 +- 18 files changed, 55 insertions(+), 41 deletions(-) rename {shell/data => emulator}/Makefile.am (59%) rename {shell/data => emulator}/kbdconfig (100%) diff --git a/Makefile.am b/Makefile.am index 4606e900..7394eac3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = lib po shell sugar services tools +SUBDIRS = emulator lib po shell sugar services tools ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 0ae1e154..ce30bd72 100644 --- a/configure.ac +++ b/configure.ac @@ -104,6 +104,7 @@ AM_GLIB_GNU_GETTEXT AC_OUTPUT([ Makefile +emulator/Makefile lib/Makefile lib/data/Makefile lib/src/Makefile @@ -116,7 +117,6 @@ services/clipboard/Makefile services/datastore/Makefile shell/Makefile shell/intro/Makefile -shell/data/Makefile shell/hardware/Makefile shell/view/Makefile shell/view/devices/Makefile diff --git a/shell/data/Makefile.am b/emulator/Makefile.am similarity index 59% rename from shell/data/Makefile.am rename to emulator/Makefile.am index 1f0f9c05..d0386c71 100644 --- a/shell/data/Makefile.am +++ b/emulator/Makefile.am @@ -1,4 +1,4 @@ -confdir = $(pkgdatadir) +confdir = $(pkgdatadir)/emulator conf_DATA = kbdconfig EXTRA_DIST = $(conf_DATA) diff --git a/shell/data/kbdconfig b/emulator/kbdconfig similarity index 100% rename from shell/data/kbdconfig rename to emulator/kbdconfig diff --git a/services/clipboard/sugar-clipboard b/services/clipboard/sugar-clipboard index 576145c7..9ee32e70 100755 --- a/services/clipboard/sugar-clipboard +++ b/services/clipboard/sugar-clipboard @@ -32,7 +32,7 @@ import dbus.glib from sugar import env -sys.path.insert(0, os.path.join(env.get_data_dir(), 'services/clipboard')) +sys.path.insert(0, env.get_service_path('clipboard')) from clipboardservice import ClipboardService diff --git a/services/console/sugar-console b/services/console/sugar-console index 2f2fc4fe..d4d7af02 100755 --- a/services/console/sugar-console +++ b/services/console/sugar-console @@ -7,6 +7,6 @@ import os import sys from sugar import env -sys.path.insert(0, os.path.join(env.get_data_dir(), 'services/console')) +sys.path.insert(0, env.get_service_path('console')) import console diff --git a/services/datastore/sugar-data-store b/services/datastore/sugar-data-store index 9ab14fee..003e2739 100755 --- a/services/datastore/sugar-data-store +++ b/services/datastore/sugar-data-store @@ -24,7 +24,7 @@ import logging from sugar import logger from sugar import env -sys.path.insert(0, os.path.join(env.get_data_dir(), 'services/datastore')) +sys.path.insert(0, env.get_service_path('datastore')) logger.start('data-store') logging.info('Starting the data store...') diff --git a/services/presence/sugar-presence-service b/services/presence/sugar-presence-service index 50c12173..be9c0e0a 100755 --- a/services/presence/sugar-presence-service +++ b/services/presence/sugar-presence-service @@ -24,7 +24,7 @@ import os from sugar import logger from sugar import env -sys.path.insert(0, os.path.join(env.get_data_dir(), 'services/presence')) +sys.path.insert(0, env.get_service_path('presence')) logger.start('presenceservice') diff --git a/services/presence2/sugar-presence-service2 b/services/presence2/sugar-presence-service2 index f71344a6..83ff58d0 100755 --- a/services/presence2/sugar-presence-service2 +++ b/services/presence2/sugar-presence-service2 @@ -24,7 +24,7 @@ import os from sugar import logger from sugar import env -sys.path.insert(0, os.join.path(env.get_data_dir(), 'services/presence2')) +sys.path.insert(0, env.get_service_path('presence2')) logger.start('presenceservice') diff --git a/shell/Makefile.am b/shell/Makefile.am index c1185b30..0d881ed3 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = data hardware model view intro +SUBDIRS = hardware model view intro bin_SCRIPTS = \ sugar-activity \ diff --git a/shell/sugar-shell b/shell/sugar-shell index 92cefc32..4b67e963 100755 --- a/shell/sugar-shell +++ b/shell/sugar-shell @@ -36,7 +36,7 @@ logger.cleanup() logger.start('shell') if len(sys.argv) == 1: - sys.path.insert(0, os.path.join(env.get_data_dir(), 'shell')) + sys.path.insert(0, env.get_shell_path()) from view.Shell import Shell from model.ShellModel import ShellModel diff --git a/sugar-emulator b/sugar-emulator index c87dc711..d31010d0 100755 --- a/sugar-emulator +++ b/sugar-emulator @@ -56,9 +56,9 @@ else: dpi = min(_sugar.get_screen_dpi(), 96) if sourcedir: - kbd_config = os.path.join(sourcedir, 'shell/data/kbdconfig') + kbd_config = os.path.join(sourcedir, 'emulator/kbdconfig') else: - kbd_config = os.path.join(env.get_data_dir(), 'kbdconfig') + kbd_config = os.path.join(env.get_emulator_path('kbdconfig')) emulator = Emulator(width, height, dpi) emulator.set_keyboard_config(kbd_config) diff --git a/sugar/activity/bundle.py b/sugar/activity/bundle.py index 283204f3..8980a115 100644 --- a/sugar/activity/bundle.py +++ b/sugar/activity/bundle.py @@ -44,8 +44,7 @@ class Bundle: if cp.has_option(section, 'class'): self._class = cp.get(section, 'class') self._exec = '%s %s --bundle-path="%s"' % ( - os.path.join(env.get_shell_bin_dir(), _PYTHON_FACTORY), - self._class, self.get_path()) + env.get_bin_path(_PYTHON_FACTORY), self._class, self.get_path()) elif cp.has_option(section, 'exec'): self._class = None self._exec = cp.get(section, 'exec') diff --git a/sugar/activity/bundlebuilder.py b/sugar/activity/bundlebuilder.py index c223bfa1..120e7b8c 100644 --- a/sugar/activity/bundlebuilder.py +++ b/sugar/activity/bundlebuilder.py @@ -93,7 +93,7 @@ def _get_install_dir(prefix): return os.path.join(prefix, 'share/activities') def _get_bundle_path(): - return os.path.join(env.get_user_activities_dir(), _get_bundle_dir()) + return os.path.join(env.get_user_activities_path(), _get_bundle_dir()) def _get_package_name(): bundle = Bundle(_get_source_path()) @@ -120,7 +120,7 @@ setup.py help - print this message \n\ ' def cmd_dev(): - bundle_path = os.path.join(env.get_user_activities_dir(), _get_bundle_dir()) + bundle_path = os.path.join(env.get_user_activities_path(), _get_bundle_dir()) try: os.symlink(_get_source_path(), bundle_path) except OSError: diff --git a/sugar/activity/bundleregistry.py b/sugar/activity/bundleregistry.py index 08f543ff..2ad68ed5 100644 --- a/sugar/activity/bundleregistry.py +++ b/sugar/activity/bundleregistry.py @@ -1,14 +1,26 @@ import os from ConfigParser import ConfigParser + import gobject from sugar.activity.bundle import Bundle from sugar import env from sugar import util +# http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html +def _get_data_dirs(): + if os.environ.has_key('XDG_DATA_DIRS'): + return os.environ['XDG_DATA_DIRS'].split(':') + else: + return [ '/usr/local/share/', '/usr/share/' ] + class _ServiceManager(object): def __init__(self): - self._path = env.get_user_service_dir() + service_dir = os.path.expanduser('~/.local/share/dbus-1/services') + if not os.path.isdir(service_dir): + os.makedirs(service_dir) + + self._path = service_dir def add(self, bundle): util.write_service(bundle.get_service_name(), @@ -74,8 +86,8 @@ def get_registry(): _bundle_registry = BundleRegistry() -for path in env.get_data_dirs(): +for path in _get_data_dirs(): bundles_path = os.path.join(path, 'activities') _bundle_registry.add_search_path(bundles_path) -_bundle_registry.add_search_path(env.get_user_activities_dir()) +_bundle_registry.add_search_path(env.get_user_activities_path()) diff --git a/sugar/env.py b/sugar/env.py index 7d6cc7c3..d32c1cbe 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -24,6 +24,17 @@ try: except ImportError: from sugar.__installed__ import * +def _get_prefix_path(base, path=None): + if os.environ.has_key('SUGAR_PREFIX'): + prefix = os.environ['SUGAR_PREFIX'] + else: + prefix = '/usr' + + if path: + return os.path.join(prefix, base, path) + else: + return os.path.join(prefix, base) + def is_emulator(): if os.environ.has_key('SUGAR_EMULATOR'): if os.environ['SUGAR_EMULATOR'] == 'yes': @@ -45,28 +56,20 @@ def get_profile_path(): return path -def get_data_dir(): - return sugar_data_dir - -def get_shell_bin_dir(): - return sugar_shell_bin_dir - -# http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html -def get_data_dirs(): - if os.environ.has_key('XDG_DATA_DIRS'): - return os.environ['XDG_DATA_DIRS'].split(':') - else: - return [ '/usr/local/share/', '/usr/share/' ] - -def get_user_service_dir(): - service_dir = os.path.expanduser('~/.local/share/dbus-1/services') - if not os.path.isdir(service_dir): - os.makedirs(service_dir) - return service_dir - -def get_user_activities_dir(): +def get_user_activities_path(): path = os.path.expanduser('~/Activities') if not os.path.isdir(path): os.mkdir(path) return path +def get_bin_path(path=None): + return _get_prefix_path('bin', path) + +def get_service_path(name): + return _get_prefix_path('share/sugar/services', name) + +def get_shell_path(path=None): + return _get_prefix_path('share/sugar/shell', path) + +def get_emulator_path(path=None): + return _get_prefix_path('share/sugar/emulator', path) diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 6f7a0a9d..a805087f 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -326,7 +326,7 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): return height def do_button_press_event(self, event): - item.emit_activated() + self.emit_activated() return True def get_popup(self): diff --git a/tools/sugar-install-bundle b/tools/sugar-install-bundle index 971d9743..a66cd81c 100755 --- a/tools/sugar-install-bundle +++ b/tools/sugar-install-bundle @@ -27,7 +27,7 @@ bus = dbus.SessionBus() proxy_obj = bus.get_object(DBUS_SERVICE, DBUS_PATH) dbus_service = dbus.Interface(proxy_obj, DBUS_SERVICE) -bundle_dir = env.get_user_activities_dir() +bundle_dir = env.get_user_activities_path() zip_file = zipfile.ZipFile(sys.argv[1]) file_names = zip_file.namelist() From 8a98cdc6e026d230aa555a9aa8b828d20ad0b1f5 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 14:59:47 +0100 Subject: [PATCH 11/12] Fix matchbox invocation --- sugar/emulator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sugar/emulator.py b/sugar/emulator.py index bc069241..53732554 100644 --- a/sugar/emulator.py +++ b/sugar/emulator.py @@ -69,7 +69,7 @@ class MatchboxProcess(Process): options += '-theme olpc ' if kbd_config: - options = '-kbdconfig %s ' % kbd_config + options += '-kbdconfig %s ' % kbd_config command = 'matchbox-window-manager %s ' % options Process.__init__(self, command) From 1587218e9eca0fab2af3bb5e758b7103a9b6b066 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 9 Mar 2007 15:07:08 +0100 Subject: [PATCH 12/12] Remove unused files --- configure.ac | 1 - sugar/Makefile.am | 3 --- sugar/__installed__.py.in | 2 -- sugar/__uninstalled__.py | 7 ------- sugar/env.py | 7 ------- 5 files changed, 20 deletions(-) delete mode 100644 sugar/__installed__.py.in delete mode 100644 sugar/__uninstalled__.py diff --git a/configure.ac b/configure.ac index ce30bd72..ac02df8f 100644 --- a/configure.ac +++ b/configure.ac @@ -138,7 +138,6 @@ services/console/interface/memphis/Makefile services/console/interface/logviewer/Makefile services/console/interface/terminal/Makefile sugar/Makefile -sugar/__installed__.py sugar/activity/Makefile sugar/chat/Makefile sugar/chat/sketchpad/Makefile diff --git a/sugar/Makefile.am b/sugar/Makefile.am index 93c07692..0642fbd8 100644 --- a/sugar/Makefile.am +++ b/sugar/Makefile.am @@ -3,7 +3,6 @@ SUBDIRS = activity chat clipboard graphics p2p presence datastore sugardir = $(pythondir)/sugar sugar_PYTHON = \ __init__.py \ - __installed__.py \ date.py \ emulator.py \ env.py \ @@ -12,5 +11,3 @@ sugar_PYTHON = \ simulator.py \ TracebackUtils.py \ util.py - -EXTRA_DIST = __uninstalled__.py diff --git a/sugar/__installed__.py.in b/sugar/__installed__.py.in deleted file mode 100644 index 415e0e1b..00000000 --- a/sugar/__installed__.py.in +++ /dev/null @@ -1,2 +0,0 @@ -sugar_data_dir = '@prefix@/share/sugar' -sugar_shell_bin_dir = '@prefix@/bin' diff --git a/sugar/__uninstalled__.py b/sugar/__uninstalled__.py deleted file mode 100644 index 7dc2f384..00000000 --- a/sugar/__uninstalled__.py +++ /dev/null @@ -1,7 +0,0 @@ -import os - -_sourcedir = os.path.dirname(os.path.dirname(__file__)) - -sugar_data_dir = os.path.join(_sourcedir, 'shell/data') -sugar_services_dir = os.path.join(_sourcedir, 'services') -sugar_shell_bin_dir = os.path.join(_sourcedir, 'shell') diff --git a/sugar/env.py b/sugar/env.py index d32c1cbe..65fd1fe5 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -16,13 +16,6 @@ # Boston, MA 02111-1307, USA. import os -import sys -import pwd - -try: - from sugar.__uninstalled__ import * -except ImportError: - from sugar.__installed__ import * def _get_prefix_path(base, path=None): if os.environ.has_key('SUGAR_PREFIX'):