From 3f792924ddf4dba301d06e496ac6e29296fbd4e9 Mon Sep 17 00:00:00 2001 From: flavio Date: Fri, 09 Nov 2012 23:58:22 +0000 Subject: Gtk 3 Port Base --- (limited to 'toolkit/activity_widgets.py') diff --git a/toolkit/activity_widgets.py b/toolkit/activity_widgets.py index 9195af5..e58f368 100644 --- a/toolkit/activity_widgets.py +++ b/toolkit/activity_widgets.py @@ -15,33 +15,40 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -import gtk -import gobject +import gi +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GObject +from gi.repository import GdkX11 import gettext -from sugar import profile -from sugar.graphics.toolbutton import ToolButton -from sugar.graphics.radiotoolbutton import RadioToolButton -from sugar.graphics.toolbox import Toolbox -from sugar.graphics.xocolor import XoColor -from sugar.graphics.icon import Icon -from sugar.bundle.activitybundle import ActivityBundle +from sugar3 import profile +from sugar3.graphics.toolbutton import ToolButton +from sugar3.graphics.radiotoolbutton import RadioToolButton +from sugar3.graphics.toolbox import Toolbox +from sugar3.graphics.xocolor import XoColor +from sugar3.graphics.icon import Icon +from sugar3.bundle.activitybundle import ActivityBundle -from toolkit.toolbarbox import ToolbarButton -from toolkit.radiopalette import RadioPalette -from toolkit.radiopalette import RadioMenuButton -from sugar.graphics import style +from toolbarbox import ToolbarButton +from radiopalette import RadioPalette +from radiopalette import RadioMenuButton -_ = lambda msg: gettext.dgettext('sugar-toolkit', msg) +from sugar3.graphics import style +_ = lambda msg: gettext.dgettext('sugar3-toolkit', msg) + +# FIXME: This module is not being used. def _create_activity_icon(metadata): + if metadata.get('icon-color', ''): color = XoColor(metadata['icon-color']) + else: color = profile.get_color() - from sugar.activity.activity import get_bundle_path + from sugar3.activity.activity import get_bundle_path bundle = ActivityBundle(get_bundle_path()) icon = Icon(file=bundle.get_icon(), xo_color=color) @@ -50,8 +57,9 @@ def _create_activity_icon(metadata): class ActivityButton(ToolButton): - def __init__(self, activity, **kwargs): - ToolButton.__init__(self, **kwargs) + def __init__(self, activity): + + ToolButton.__init__(self) icon = _create_activity_icon(activity.metadata) self.set_icon_widget(icon) @@ -66,7 +74,8 @@ class ActivityButton(ToolButton): class ActivityToolbarButton(ToolbarButton): - def __init__(self, activity, **kwargs): + def __init__(self, activity): + toolbar = ActivityToolbar(activity, orientation_left=True) toolbar.stop.hide() @@ -79,7 +88,8 @@ class ActivityToolbarButton(ToolbarButton): class StopButton(ToolButton): - def __init__(self, activity, **kwargs): + def __init__(self, activity): + ToolButton.__init__(self, 'activity-stop', **kwargs) self.props.tooltip = _('Stop') self.props.accelerator = 'Q' @@ -91,36 +101,41 @@ class StopButton(ToolButton): class UndoButton(ToolButton): - def __init__(self, **kwargs): - ToolButton.__init__(self, 'edit-undo', **kwargs) + def __init__(self): + + ToolButton.__init__(self, 'edit-undo') self.props.tooltip = _('Undo') self.props.accelerator = 'Z' class RedoButton(ToolButton): - def __init__(self, **kwargs): - ToolButton.__init__(self, 'edit-redo', **kwargs) + def __init__(self): + + ToolButton.__init__(self, 'edit-redo') self.props.tooltip = _('Redo') class CopyButton(ToolButton): - def __init__(self, **kwargs): - ToolButton.__init__(self, 'edit-copy', **kwargs) + def __init__(self): + + ToolButton.__init__(self, 'edit-copy') self.props.tooltip = _('Copy') class PasteButton(ToolButton): - def __init__(self, **kwargs): - ToolButton.__init__(self, 'edit-paste', **kwargs) + def __init__(self): + + ToolButton.__init__(self, 'edit-paste') self.props.tooltip = _('Paste') class ShareButton(RadioMenuButton): - def __init__(self, activity, **kwargs): + def __init__(self, activity): + palette = RadioPalette() self.private = RadioToolButton( @@ -137,7 +152,7 @@ class ShareButton(RadioMenuButton): activity.connect('shared', self.__update_share_cb) activity.connect('joined', self.__update_share_cb) - RadioMenuButton.__init__(self, **kwargs) + RadioMenuButton.__init__(self) self.props.palette = palette if activity.props.max_participants == 1: self.props.sensitive = False @@ -146,29 +161,35 @@ class ShareButton(RadioMenuButton): activity.share() def __update_share_cb(self, activity): + self.neighborhood.handler_block(self._neighborhood_handle) + try: if activity.get_shared(): self.private.props.sensitive = False self.neighborhood.props.sensitive = False self.neighborhood.props.active = True + else: self.private.props.sensitive = True self.neighborhood.props.sensitive = True self.private.props.active = True + finally: self.neighborhood.handler_unblock(self._neighborhood_handle) -class TitleEntry(gtk.ToolItem): +class TitleEntry(Gtk.ToolItem): - def __init__(self, activity, **kwargs): - gtk.ToolItem.__init__(self) + def __init__(self, activity): + + Gtk.ToolItem.__init__(self) self.set_expand(False) self._update_title_sid = None - self.entry = gtk.Entry(**kwargs) - self.entry.set_size_request(int(gtk.gdk.screen_width() / 3), -1) + self.entry = Gtk.Entry() + screen = GdkX11.X11Screen() + self.entry.set_size_request(int(screen.width() / 3), -1) self.entry.set_text(activity.metadata['title']) self.entry.connect('changed', self.__title_changed_cb, activity) self.entry.show() @@ -177,18 +198,21 @@ class TitleEntry(gtk.ToolItem): activity.metadata.connect('updated', self.__jobject_updated_cb) def modify_bg(self, state, color): - gtk.ToolItem.modify_bg(self, state, color) + + Gtk.ToolItem.modify_bg(self, state, color) self.entry.modify_bg(state, color) def __jobject_updated_cb(self, jobject): self.entry.set_text(jobject['title']) def __title_changed_cb(self, entry, activity): + if not self._update_title_sid: - self._update_title_sid = gobject.timeout_add_seconds( - 1, self.__update_title_cb, activity) + self._update_title_sid = GObject.timeout_add_seconds( + 1, self.__update_title_cb, activity) def __update_title_cb(self, activity): + title = self.entry.get_text() activity.metadata['title'] = title @@ -203,30 +227,34 @@ class TitleEntry(gtk.ToolItem): return False -class DescriptionItem(gtk.ToolItem): +class DescriptionItem(Gtk.ToolItem): - def __init__(self, activity, **kwargs): - gtk.ToolItem.__init__(self) + def __init__(self, activity): + + Gtk.ToolItem.__init__(self) description_button = ToolButton('edit-description') description_button.show() - description_button.set_tooltip(_('Description')) + description_button.set_tooltip_text(_('Description')) self._palette = description_button.get_palette() - description_box = gtk.HBox() - sw = gtk.ScrolledWindow() - sw.set_size_request(int(gtk.gdk.screen_width() / 2), + description_box = Gtk.HBox() + sw = Gtk.ScrolledWindow() + screen = GdkX11.X11Screen() + sw.set_size_request(int(screen.width() / 2), 2 * style.GRID_CELL_SIZE) - sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - self._text_view = gtk.TextView() + sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) + self._text_view = Gtk.TextView() self._text_view.set_left_margin(style.DEFAULT_PADDING) self._text_view.set_right_margin(style.DEFAULT_PADDING) - text_buffer = gtk.TextBuffer() + text_buffer = Gtk.TextBuffer() + if 'description' in activity.metadata: text_buffer.set_text(activity.metadata['description']) + self._text_view.set_buffer(text_buffer) self._text_view.connect('focus-out-event', - self.__description_changed_cb, activity) + self.__description_changed_cb, activity) sw.add(self._text_view) description_box.pack_start(sw, False, True, 0) self._palette.set_content(description_box) @@ -234,23 +262,28 @@ class DescriptionItem(gtk.ToolItem): self.add(description_button) description_button.connect('clicked', - self.__description_button_clicked_cb) + self.__description_button_clicked_cb) activity.metadata.connect('updated', self.__jobject_updated_cb) def _get_text_from_buffer(self): + buf = self._text_view.get_buffer() start_iter = buf.get_start_iter() end_iter = buf.get_end_iter() return buf.get_text(start_iter, end_iter, False) def __jobject_updated_cb(self, jobject): + if self._text_view.has_focus(): return + if 'description' not in jobject: return + if self._get_text_from_buffer() == jobject['description']: return + buf = self._text_view.get_buffer() buf.set_text(jobject['description']) @@ -258,6 +291,7 @@ class DescriptionItem(gtk.ToolItem): self._palette.popup(immediate=True, state=1) def __description_changed_cb(self, widget, event, activity): + description = self._get_text_from_buffer() if 'description' in activity.metadata and \ description == activity.metadata['description']: @@ -268,7 +302,7 @@ class DescriptionItem(gtk.ToolItem): return False -class ActivityToolbar(gtk.Toolbar): +class ActivityToolbar(Gtk.Toolbar): """The Activity toolbar with the Journal entry title, sharing, and Stop buttons @@ -277,7 +311,8 @@ class ActivityToolbar(gtk.Toolbar): """ def __init__(self, activity, orientation_left=False): - gtk.Toolbar.__init__(self) + + Gtk.Toolbar.__init__(self) self._activity = activity @@ -288,7 +323,7 @@ class ActivityToolbar(gtk.Toolbar): self.title = title_button.entry if orientation_left == False: - separator = gtk.SeparatorToolItem() + separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) self.insert(separator, -1) @@ -308,7 +343,7 @@ class ActivityToolbar(gtk.Toolbar): self.stop.show() -class EditToolbar(gtk.Toolbar): +class EditToolbar(Gtk.Toolbar): """Provides the standard edit toolbar for Activities. Members: @@ -343,7 +378,7 @@ class EditToolbar(gtk.Toolbar): """ def __init__(self): - gtk.Toolbar.__init__(self) + Gtk.Toolbar.__init__(self) self.undo = UndoButton() self.insert(self.undo, -1) @@ -353,7 +388,7 @@ class EditToolbar(gtk.Toolbar): self.insert(self.redo, -1) self.redo.show() - self.separator = gtk.SeparatorToolItem() + self.separator = Gtk.SeparatorToolItem() self.separator.set_draw(True) self.insert(self.separator, -1) self.separator.show() @@ -387,6 +422,7 @@ class ActivityToolbox(Toolbox): """ def __init__(self, activity): + Toolbox.__init__(self) self._activity_toolbar = ActivityToolbar(activity) -- cgit v0.9.1