Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/port
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-05-25 21:58:55 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-05-25 21:58:55 (GMT)
commitfc20159ea00c3b71a421f63122c5123895e493b2 (patch)
tree7a8a6f47985ffce503b577abd9801935c58e2a8b /port
parent8a4b5c69855748b44643df5e6edadd41a0b921b7 (diff)
Update sugar-port
Diffstat (limited to 'port')
-rw-r--r--port/AUTHORS1
-rw-r--r--port/NEWS8
-rw-r--r--port/README5
-rw-r--r--port/TODO0
-rw-r--r--port/activity.py34
-rw-r--r--port/widgets.py177
6 files changed, 216 insertions, 9 deletions
diff --git a/port/AUTHORS b/port/AUTHORS
deleted file mode 100644
index 47ead6c..0000000
--- a/port/AUTHORS
+++ /dev/null
@@ -1 +0,0 @@
-Aleksey Lim <alsroot@member.fsf.org>
diff --git a/port/NEWS b/port/NEWS
deleted file mode 100644
index 0dcfeb5..0000000
--- a/port/NEWS
+++ /dev/null
@@ -1,8 +0,0 @@
-1
-
-* Add tarball.py
-* Add json import wrapper
-* Add object chooser
-* Add activity classes
-* Add pixbuf methods
-* Add TempoSlider and ScrolledBox widgets
diff --git a/port/README b/port/README
index bd0dade..256200d 100644
--- a/port/README
+++ b/port/README
@@ -7,6 +7,11 @@ Cornerstone purposes for this project:
* Total backwards compatibility for sugar-port API
* Run on all sugar platforms beginning from 0.82
+In most cases sugar-port could be embedded to activity's directory tree.
+There is no need to include the whole sugar-port project only top level
+files/directories you are using directly - sugar-port's top level entities
+don't import each other.
+
Get it
------
diff --git a/port/TODO b/port/TODO
deleted file mode 100644
index e69de29..0000000
--- a/port/TODO
+++ /dev/null
diff --git a/port/activity.py b/port/activity.py
index dfe6a4a..e3b6fdd 100644
--- a/port/activity.py
+++ b/port/activity.py
@@ -17,6 +17,7 @@
import gtk
import logging
import telepathy
+import gobject
import sugar.activity.activity as toolkit
from sugar.presence.sugartubeconn import SugarTubeConnection
@@ -27,6 +28,18 @@ _NEW_INSTANCE = 1
_PRE_INSTANCE = 2
_POST_INSTANCE = 3
+class CursorFactory:
+ __shared_state = {"cursors": {}}
+
+ def __init__(self):
+ self.__dict__ = self.__shared_state
+
+ def get_cursor(self, cur_type):
+ if not self.cursors.has_key(cur_type):
+ cur = gtk.gdk.Cursor(cur_type)
+ self.cursors[cur_type] = cur
+ return self.cursors[cur_type]
+
class Activity(toolkit.Activity):
"""Basic activity class"""
@@ -57,6 +70,10 @@ class Activity(toolkit.Activity):
"""
raise NotImplementedError
+ def on_save_instance(self, cb, *args):
+ """ Register callback which will be invoked before save_instance """
+ self.__on_save_instance.append((cb, args))
+
def share_instance(self, connection, is_initiator):
"""
Activity was shared/joined.
@@ -98,6 +115,17 @@ class Activity(toolkit.Activity):
alert.show_all()
self.add_alert(alert)
+ def get_cursor(self):
+ return self._cursor
+
+ def set_cursor(self, cursor):
+ if not isinstance(cursor, gtk.gdk.Cursor):
+ cursor = CursorFactory().get_cursor(cursor)
+
+ if self._cursor != cursor:
+ self._cursor = cursor
+ self.window.set_cursor(self._cursor)
+
def __init__(self, canvas, handle):
"""
Initialise the Activity.
@@ -120,6 +148,10 @@ class Activity(toolkit.Activity):
self.__resume_filename = None
self.__postponed_share = []
+ self.__on_save_instance = []
+
+ self._cursor = None
+ self.set_cursor(gtk.gdk.LEFT_PTR)
# XXX do it after(possible) read_file() invoking
# have to rely on calling read_file() from map_cb in sugar-toolkit
@@ -153,6 +185,8 @@ class Activity(toolkit.Activity):
def write_file(self, filepath):
"""Subclass should not override this method"""
+ for cb, args in self.__on_save_instance:
+ cb(*args)
self.save_instance(filepath)
def __map_canvasactivity_cb(self, widget):
diff --git a/port/widgets.py b/port/widgets.py
new file mode 100644
index 0000000..aab59f8
--- /dev/null
+++ b/port/widgets.py
@@ -0,0 +1,177 @@
+# 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 gtk
+import hippo
+import gobject
+import logging
+
+from sugar.graphics import style
+from sugar.graphics.palette import CanvasInvoker, Palette
+from sugar.graphics import toolbutton
+from sugar.graphics import icon
+
+def labelize(text, widget):
+ box = hippo.CanvasBox()
+ box.props.spacing = style.DEFAULT_SPACING
+
+ text = hippo.CanvasText(text=text)
+ text.props.color = style.COLOR_SELECTION_GREY.get_int()
+ if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL:
+ text.props.xalign = hippo.ALIGNMENT_END
+ else:
+ text.props.xalign = hippo.ALIGNMENT_START
+ box.append(text)
+
+ box.append(widget, hippo.PACK_EXPAND)
+
+ return box
+
+class Entry(hippo.CanvasWidget):
+ def __init__(self, text=None, frame_color=style.COLOR_WHITE.get_gdk_color(),
+ **kwargs):
+ hippo.CanvasWidget.__init__(self, **kwargs)
+
+ self.entry = gtk.Entry()
+ self.entry.modify_bg(gtk.STATE_INSENSITIVE, frame_color)
+
+ self.props.widget = self.entry
+
+ if text:
+ self.text = text
+
+ def get_text(self):
+ return self.entry.props.text
+
+ def set_text(self, value):
+ self.entry.props.text = value
+
+ text = gobject.property(type=str, setter=set_text, getter=get_text)
+ text = property(get_text, set_text)
+
+class TextView(hippo.CanvasWidget):
+ def __init__(self, text=None, **kwargs):
+ hippo.CanvasWidget.__init__(self, **kwargs)
+
+ self.view = gtk.TextView()
+ self.view.props.left_margin = style.DEFAULT_SPACING
+ self.view.props.right_margin = style.DEFAULT_SPACING
+ self.view.props.wrap_mode = gtk.WRAP_WORD
+ self.view.props.accepts_tab = False
+ self.view.show()
+
+ scrolled_window = gtk.ScrolledWindow()
+ scrolled_window.set_shadow_type(gtk.SHADOW_OUT)
+ scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ scrolled_window.add(self.view)
+
+ self.props.widget = scrolled_window
+
+ if text:
+ self.text = text
+
+ def get_text(self):
+ return self.view.props.buffer.props.text
+
+ def set_text(self, value):
+ self.view.props.buffer.props.text = text
+
+ text = gobject.property(type=str, setter=set_text, getter=get_text)
+ text = property(get_text, set_text)
+
+class Image(hippo.CanvasWidget):
+ def __init__(self, palette=None, tooltip=None, pixbuf=None, **kwargs):
+ self.image = gtk.Image()
+ self._invoker = CanvasInvoker()
+
+ hippo.CanvasBox.__init__(self, widget=self.image, **kwargs)
+
+ self._invoker._position_hint = self._invoker.AT_CURSOR
+ self._invoker.attach(self)
+
+ self.connect('destroy', self._destroy_cb)
+
+ if palette:
+ self.palette = palette
+ if tooltip:
+ self.tooltip = tooltip
+ if pixbuf:
+ self.pixbuf = pixbuf
+
+ def _destroy_cb(self, widget):
+ if self._invoker is not None:
+ self._invoker.detach()
+
+ def create_palette(self):
+ return None
+
+ def get_palette(self):
+ return self._invoker.palette
+
+ def set_palette(self, palette):
+ self._invoker.palette = palette
+
+ palette = gobject.property(type=object,
+ setter=set_palette, getter=get_palette)
+ palette = property(get_palette, set_palette)
+
+ def get_tooltip(self):
+ return self._invoker.palette and self._invoker.palette.primary_text
+
+ def set_tooltip(self, text):
+ self.set_palette(Palette(text))
+
+ tooltip = gobject.property(type=str, setter=set_tooltip, getter=get_tooltip)
+ tooltip = property(get_tooltip, set_tooltip)
+
+ def set_pixbuf(self, value):
+ self.image.set_from_pixbuf(value)
+ self.props.box_width = value.get_width()
+ self.props.box_height = value.get_height()
+
+ pixbuf = gobject.property(type=object, setter=set_pixbuf, getter=None)
+ pixbuf = property(None, set_pixbuf)
+
+class ToolButton(toolbutton.ToolButton):
+ def __init__(self,
+ icon_name,
+ size=gtk.ICON_SIZE_SMALL_TOOLBAR,
+ padding=None,
+ **kwargs):
+
+ toolbutton.ToolButton.__init__(self, **kwargs)
+
+ image = icon.Icon(icon_name=icon_name, icon_size=size)
+ image.show()
+
+ # The alignment is a hack to work around gtk.ToolButton code
+ # that sets the icon_size when the icon_widget is a gtk.Image
+ alignment = gtk.Alignment(0.5, 0.5)
+ alignment.show()
+ alignment.add(image)
+
+ self.set_icon_widget(alignment)
+
+ sizes = { gtk.ICON_SIZE_SMALL_TOOLBAR: style.SMALL_ICON_SIZE,
+ gtk.ICON_SIZE_LARGE_TOOLBAR: style.STANDARD_ICON_SIZE }
+
+ if padding is not None and sizes.has_key(size):
+ button_size = sizes[size] + style.DEFAULT_SPACING + padding
+ self.set_size_request(button_size, button_size)
+
+class ToolWidget(gtk.ToolItem):
+ def __init__(self, widget):
+ gtk.ToolItem.__init__(self)
+ self.add(widget)
+ widget.show()