Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar
diff options
context:
space:
mode:
authorMike C. Fletcher <mcfletch@raistlin.(none)>2007-04-21 18:05:08 (GMT)
committer Mike C. Fletcher <mcfletch@raistlin.(none)>2007-04-21 18:05:08 (GMT)
commitdf4919de2faaf3ed9719fe66dda54a0e2b2cd0d5 (patch)
tree766a298e2f1bd709775e985a4d586da5ebb8be9a /sugar
parente571b3bff9b834c099bc82be5e20305d9dfb9730 (diff)
parenta0348a565c09e434514b34b05f3866c97f0aee49 (diff)
Merge branch 'master' of git+ssh://mcfletch@dev.laptop.org/git/sugar
Diffstat (limited to 'sugar')
-rw-r--r--sugar/Makefile.am13
-rw-r--r--sugar/activity/activityfactoryservice.py2
-rw-r--r--sugar/browser/__init__.py7
-rw-r--r--sugar/env.py23
-rw-r--r--sugar/graphics/animator.py8
-rw-r--r--sugar/graphics/canvasicon.py5
-rw-r--r--sugar/graphics/snowflakebox.py13
-rw-r--r--sugar/graphics/spreadbox.py25
-rw-r--r--sugar/graphics2/Makefile.am5
-rw-r--r--sugar/graphics2/__init__.py0
-rw-r--r--sugar/graphics2/toolbox.py32
-rw-r--r--sugar/graphics2/window.py49
-rw-r--r--sugar/ltihooks.py72
-rw-r--r--sugar/presence/presenceservice.py13
14 files changed, 246 insertions, 21 deletions
diff --git a/sugar/Makefile.am b/sugar/Makefile.am
index 7ea659a..9e8db38 100644
--- a/sugar/Makefile.am
+++ b/sugar/Makefile.am
@@ -1,10 +1,11 @@
SUBDIRS = activity browser clipboard graphics p2p presence datastore
sugardir = $(pythondir)/sugar
-sugar_PYTHON = \
- __init__.py \
- date.py \
- env.py \
- logger.py \
- profile.py \
+sugar_PYTHON = \
+ __init__.py \
+ date.py \
+ env.py \
+ logger.py \
+ ltihooks.py \
+ profile.py \
util.py
diff --git a/sugar/activity/activityfactoryservice.py b/sugar/activity/activityfactoryservice.py
index 5dcedb3..ee98f51 100644
--- a/sugar/activity/activityfactoryservice.py
+++ b/sugar/activity/activityfactoryservice.py
@@ -140,7 +140,7 @@ def run_with_args(args):
run(options.bundle_path)
def run(bundle_path):
- sys.path.insert(0, bundle_path)
+ sys.path.append(bundle_path)
bundle = Bundle(bundle_path)
diff --git a/sugar/browser/__init__.py b/sugar/browser/__init__.py
index a79048b..7de5339 100644
--- a/sugar/browser/__init__.py
+++ b/sugar/browser/__init__.py
@@ -3,4 +3,9 @@
XUL Runner and gtkmozembed and is produced by the PyGTK
.defs system.
"""
-from sugar.browser._sugarbrowser import *
+
+try:
+ from sugar.browser._sugarbrowser import *
+except ImportError:
+ from sugar import ltihooks
+ from sugar.browser._sugarbrowser import *
diff --git a/sugar/env.py b/sugar/env.py
index f25f460..3555e93 100644
--- a/sugar/env.py
+++ b/sugar/env.py
@@ -29,6 +29,17 @@ def _get_prefix_path(base, path=None):
else:
return os.path.join(prefix, base)
+def _get_sugar_path(base, path=None):
+ if os.environ.has_key('SUGAR_PATH'):
+ sugar_path = os.environ['SUGAR_PATH']
+ else:
+ sugar_path = _get_prefix_path('share/sugar')
+
+ if path:
+ return os.path.join(sugar_path, base, path)
+ else:
+ return os.path.join(sugar_path, base)
+
def is_emulator():
if os.environ.has_key('SUGAR_EMULATOR'):
if os.environ['SUGAR_EMULATOR'] == 'yes':
@@ -56,17 +67,17 @@ def get_profile_path(path=None):
def get_user_activities_path():
return os.path.expanduser('~/Activities')
-def get_bin_path(path=None):
- return _get_prefix_path('bin', path)
-
def get_locale_path(path=None):
return _get_prefix_path('share/locale', path)
+def get_bin_path(path=None):
+ return _get_sugar_path('bin', path)
+
def get_service_path(name):
- return _get_prefix_path('share/sugar/services', name)
+ return _get_sugar_path('services', name)
def get_shell_path(path=None):
- return _get_prefix_path('share/sugar/shell', path)
+ return _get_sugar_path('shell', path)
def get_data_path(path=None):
- return _get_prefix_path('share/sugar', path)
+ return _get_sugar_path('data', path)
diff --git a/sugar/graphics/animator.py b/sugar/graphics/animator.py
index 60ff9f3..459851b 100644
--- a/sugar/graphics/animator.py
+++ b/sugar/graphics/animator.py
@@ -28,7 +28,7 @@ class Animator(gobject.GObject):
gobject.TYPE_NONE, ([])),
}
- def __init__(self, time, fps, easing=EASE_OUT_EXPO):
+ def __init__(self, time, fps=20, easing=EASE_OUT_EXPO):
gobject.GObject.__init__(self)
self._animations = []
self._time = time
@@ -39,6 +39,10 @@ class Animator(gobject.GObject):
def add(self, animation):
self._animations.append(animation)
+ def remove_all(self):
+ self.stop()
+ self._animations = []
+
def start(self):
if self._timeout_sid:
self.stop()
@@ -51,7 +55,7 @@ class Animator(gobject.GObject):
if self._timeout_sid:
gobject.source_remove(self._timeout_sid)
self._timeout_sid = 0
- self.emit('completed')
+ self.emit('completed')
def _next_frame_cb(self):
current_time = min(self._time, time.time() - self._start_time)
diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py
index d50e9f9..14f8351 100644
--- a/sugar/graphics/canvasicon.py
+++ b/sugar/graphics/canvasicon.py
@@ -369,6 +369,11 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
if not self._popup:
return
+ if not self.get_context():
+ # If we have been detached from our parent, don't show up the popup
+ # in this case.
+ return
+
popup_context = self.get_popup_context()
[x, y] = [None, None]
diff --git a/sugar/graphics/snowflakebox.py b/sugar/graphics/snowflakebox.py
index dfef45b..14f4559 100644
--- a/sugar/graphics/snowflakebox.py
+++ b/sugar/graphics/snowflakebox.py
@@ -20,9 +20,11 @@ import math
import cairo
import hippo
-_BASE_RADIUS = 65
+from sugar.graphics import units
+
+_BASE_RADIUS = units.points_to_pixels(20)
_CHILDREN_FACTOR = 1
-_FLAKE_DISTANCE = 6
+_FLAKE_DISTANCE = units.points_to_pixels(4)
class SnowflakeBox(hippo.CanvasBox, hippo.CanvasItem):
__gtype_name__ = 'SugarSnowflakeBox'
@@ -67,6 +69,13 @@ class SnowflakeBox(hippo.CanvasBox, hippo.CanvasItem):
self.set_position(child, int(x), int(y))
+ def do_get_height_request(self, for_width):
+ hippo.CanvasBox.do_get_height_request(self, for_width)
+
+ height = for_width
+
+ return (height, height)
+
def do_get_width_request(self):
hippo.CanvasBox.do_get_width_request(self)
diff --git a/sugar/graphics/spreadbox.py b/sugar/graphics/spreadbox.py
index 24e12f3..ff50f71 100644
--- a/sugar/graphics/spreadbox.py
+++ b/sugar/graphics/spreadbox.py
@@ -22,20 +22,31 @@ import gtk
from sugar.graphics import units
+_WIDTH = gtk.gdk.screen_width()
+_HEIGHT = gtk.gdk.screen_height()
_CELL_WIDTH = units.grid_to_pixels(1)
_CELL_HEIGHT = units.grid_to_pixels(1)
-_GRID_WIDTH = gtk.gdk.screen_width() / _CELL_WIDTH
-_GRID_HEIGHT = gtk.gdk.screen_height() / _CELL_HEIGHT
+_GRID_WIDTH = _WIDTH / _CELL_WIDTH
+_GRID_HEIGHT = _HEIGHT / _CELL_HEIGHT
-class SpreadBox(hippo.CanvasBox):
+class SpreadBox(hippo.CanvasBox, hippo.CanvasItem):
+ __gtype_name__ = 'SugarSpreadBox'
def __init__(self, **kwargs):
hippo.CanvasBox.__init__(self, **kwargs)
self._grid = []
+ self._center = None
for i in range(0, _GRID_WIDTH * _GRID_HEIGHT):
self._grid.append(None)
+ def set_center_item(self, item):
+ if self._center:
+ self.remove(self._center)
+
+ self._center = item
+ self.append(item, hippo.PACK_FIXED)
+
def add_item(self, item):
start_pos = int(random.random() * len(self._grid))
@@ -60,3 +71,11 @@ class SpreadBox(hippo.CanvasBox):
if self._grid[i] == item:
self._grid[i] = None
self.remove(item)
+
+ def do_allocate(self, width, height, origin_changed):
+ hippo.CanvasBox.do_allocate(self, width, height, origin_changed)
+
+ if self._center:
+ [icon_width, icon_height] = self._center.get_allocation()
+ self.set_position(self._center, (width - icon_width) / 2,
+ (height - icon_height) / 2)
diff --git a/sugar/graphics2/Makefile.am b/sugar/graphics2/Makefile.am
new file mode 100644
index 0000000..f5bde18
--- /dev/null
+++ b/sugar/graphics2/Makefile.am
@@ -0,0 +1,5 @@
+sugardir = $(pythondir)/sugar/graphics2
+sugar_PYTHON = \
+ __init__.py \
+ window.py \
+ toolbox.py
diff --git a/sugar/graphics2/__init__.py b/sugar/graphics2/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/sugar/graphics2/__init__.py
diff --git a/sugar/graphics2/toolbox.py b/sugar/graphics2/toolbox.py
new file mode 100644
index 0000000..be7e5e0
--- /dev/null
+++ b/sugar/graphics2/toolbox.py
@@ -0,0 +1,32 @@
+# Copyright (C) 2007, Red Hat, Inc.
+#
+# 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 gtk
+
+class Toolbox(gtk.VBox):
+ __gtype_name__ = 'SugarToolbox'
+ def __init__(self):
+ gtk.VBox.__init__(self)
+
+ self._notebook = gtk.Notebook()
+ self._notebook.set_tab_pos(gtk.POS_BOTTOM)
+ self._notebook.set_show_border(False)
+ self.pack_start(self._notebook)
+ self._notebook.show()
+
+ def add_toolbar(self, name, toolbar):
+ self._notebook.append_page(toolbar, gtk.Label(name))
diff --git a/sugar/graphics2/window.py b/sugar/graphics2/window.py
new file mode 100644
index 0000000..d03788b
--- /dev/null
+++ b/sugar/graphics2/window.py
@@ -0,0 +1,49 @@
+# Copyright (C) 2007, Red Hat, Inc.
+#
+# 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 gtk
+import hippo
+
+from sugar.graphics2.toolbox import Toolbox
+
+class Window(gtk.Window):
+ def __init__(self):
+ gtk.Window.__init__(self)
+
+ vbox = gtk.VBox()
+ self.add(vbox)
+
+ self.toolbox = Toolbox()
+ vbox.pack_start(self.toolbox, False)
+ self.toolbox.show()
+
+ self._canvas_box = gtk.VBox()
+ vbox.pack_start(self._canvas_box)
+ self._canvas_box.show()
+
+ self.canvas = hippo.Canvas()
+ self._canvas_box.pack_start(self.canvas)
+ self.canvas.show()
+
+ vbox.show()
+
+ def set_canvas(self, canvas):
+ if self.canvas:
+ self._canvas_box.remove(self.canvas)
+
+ self._canvas_box.add(canvas)
+ self.canvas = canvas
diff --git a/sugar/ltihooks.py b/sugar/ltihooks.py
new file mode 100644
index 0000000..d68f2eb
--- /dev/null
+++ b/sugar/ltihooks.py
@@ -0,0 +1,72 @@
+# -*- Mode: Python -*-
+# vi:si:et:sw=4:sts=4:ts=4
+
+# ltihooks.py: python import hooks that understand libtool libraries.
+# Copyright (C) 2000 James Henstridge.
+# renamed to gstltihooks.py so it does not accidentally get imported by
+# an installed copy of gtk
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import os, ihooks
+
+class LibtoolHooks(ihooks.Hooks):
+ def get_suffixes(self):
+ """Like normal get_suffixes, but adds .la suffixes to list"""
+ ret = ihooks.Hooks.get_suffixes(self)
+ ret.insert(0, ('module.la', 'rb', 3))
+ ret.insert(0, ('.la', 'rb', 3))
+ return ret
+
+ def load_dynamic(self, name, filename, file=None):
+ """Like normal load_dynamic, but treat .la files specially"""
+ if len(filename) > 3 and filename[-3:] == '.la':
+ fp = open(filename, 'r')
+ dlname = ''
+ installed = 1
+ line = fp.readline()
+ while line:
+ # dlname: the name that we can dlopen
+ if len(line) > 7 and line[:7] == 'dlname=':
+ dlname = line[8:-2]
+ # installed: whether it's already installed
+ elif len(line) > 10 and line[:10] == 'installed=':
+ installed = line[10:-1] == 'yes'
+ line = fp.readline()
+ fp.close()
+ if dlname:
+ if installed:
+ filename = os.path.join(os.path.dirname(filename),
+ dlname)
+ else:
+ # if .libs already there, don't need to add it again
+ if os.path.dirname(filename).endswith('.libs'):
+ filename = os.path.join(os.path.dirname(filename),
+ dlname)
+ else:
+ filename = os.path.join(os.path.dirname(filename),
+ '.libs', dlname)
+ return ihooks.Hooks.load_dynamic(self, name, filename, file)
+
+importer = ihooks.ModuleImporter()
+importer.set_hooks(LibtoolHooks())
+
+def install():
+ print 'Installed ltihooks.'
+ importer.install()
+def uninstall():
+ importer.uninstall()
+
+install()
diff --git a/sugar/presence/presenceservice.py b/sugar/presence/presenceservice.py
index 78f51e6..e61c8d7 100644
--- a/sugar/presence/presenceservice.py
+++ b/sugar/presence/presenceservice.py
@@ -337,6 +337,19 @@ class PresenceService(gobject.GObject):
reply_handler=lambda *args: self._share_activity_cb(activity, *args),
error_handler=lambda *args: self._share_activity_error_cb(activity, *args))
+ def get_preferred_connection(self):
+ """Gets the preferred telepathy connection object that an activity
+ should use when talking directly to telepathy
+
+ returns the bus name and the object path of the Telepathy connection"""
+
+ try:
+ bus_name, object_path = self._ps.GetPreferredConnection()
+ except dbus.exceptions.DBusException:
+ return None
+
+ return bus_name, object_path
+
class _MockPresenceService(gobject.GObject):
"""Test fixture allowing testing of items that use PresenceService