From 7d255fd28fac26693c3b42743171659bad9df208 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Fri, 23 Nov 2012 13:23:59 +0000 Subject: Use the PaletteMenuItem from the toolkit instead of local SugarMenuItem, part of SL #3455 With this patch Browse uses PaletteMenuItem from 'sugar3.graphics.palettemenu' instead of the local SugarMenuItem defined by Browse in the "sugarmenuitem" module. The local module will be removed as well. Signed-off-by: Manuel Kaufmann Acked-by: Simon Schampijer --- diff --git a/palettes.py b/palettes.py index 00cf26a..bfb27e9 100644 --- a/palettes.py +++ b/palettes.py @@ -29,10 +29,9 @@ from gi.repository import WebKit from gi.repository import SugarGestures from sugar3.graphics.palette import Palette, Invoker +from sugar3.graphics.palettemenu import PaletteMenuItem from sugar3 import profile -from sugarmenuitem import SugarMenuItem - class ContentInvoker(Invoker): def __init__(self, browser): @@ -165,9 +164,9 @@ class SelectionPalette(Palette): self.props.primary_text = title - menu_item = SugarMenuItem(_('Copy text'), 'edit-copy') + menu_item = PaletteMenuItem(_('Copy text'), 'edit-copy') menu_item.icon.props.xo_color = profile.get_color() - menu_item.connect('clicked', self.__copy_activate_cb) + menu_item.connect('activate', self.__copy_activate_cb) menu_box.pack_end(menu_item, False, False, 0) menu_item.show() @@ -200,26 +199,26 @@ class LinkPalette(Palette): menu_box.show() self._content.set_border_width(1) - menu_item = SugarMenuItem(_('Follow link'), 'browse-follow-link') - menu_item.connect('clicked', self.__follow_activate_cb) + menu_item = PaletteMenuItem(_('Follow link'), 'browse-follow-link') + menu_item.connect('activate', self.__follow_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() - menu_item = SugarMenuItem(_('Follow link in new tab'), + menu_item = PaletteMenuItem(_('Follow link in new tab'), 'browse-follow-link-new-tab') - menu_item.connect('clicked', self.__follow_activate_cb, True) + menu_item.connect('activate', self.__follow_activate_cb, True) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() - menu_item = SugarMenuItem(_('Keep link'), 'document-save') + menu_item = PaletteMenuItem(_('Keep link'), 'document-save') menu_item.icon.props.xo_color = profile.get_color() - menu_item.connect('clicked', self.__download_activate_cb) + menu_item.connect('activate', self.__download_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() - menu_item = SugarMenuItem(_('Copy link'), 'edit-copy') + menu_item = PaletteMenuItem(_('Copy link'), 'edit-copy') menu_item.icon.props.xo_color = profile.get_color() - menu_item.connect('clicked', self.__copy_activate_cb) + menu_item.connect('activate', self.__copy_activate_cb) menu_box.pack_start(menu_item, False, False, 0) menu_item.show() @@ -267,15 +266,15 @@ class ImagePalette(Palette): menu_box.show() self._content.set_border_width(1) - menu_item = SugarMenuItem(_('Copy image'), 'edit-copy') + menu_item = PaletteMenuItem(_('Copy image'), 'edit-copy') menu_item.icon.props.xo_color = profile.get_color() - menu_item.connect('clicked', self.__copy_activate_cb) + menu_item.connect('activate', self.__copy_activate_cb) menu_box.pack_end(menu_item, False, False, 0) menu_item.show() - menu_item = SugarMenuItem(_('Keep image'), 'document-save') + menu_item = PaletteMenuItem(_('Keep image'), 'document-save') menu_item.icon.props.xo_color = profile.get_color() - menu_item.connect('clicked', self.__download_activate_cb) + menu_item.connect('activate', self.__download_activate_cb) menu_box.pack_end(menu_item, False, False, 0) menu_item.show() diff --git a/sugarmenuitem.py b/sugarmenuitem.py deleted file mode 100644 index 5071406..0000000 --- a/sugarmenuitem.py +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright 2012 One Laptop Per Child -# -# 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 - -from gi.repository import GObject -from gi.repository import Gtk - -from sugar3.graphics.icon import Icon -from sugar3.graphics import style - - -class SugarMenuItem(Gtk.EventBox): - - __gsignals__ = { - 'clicked': (GObject.SignalFlags.RUN_FIRST, None, []) - } - - def __init__(self, text_label='', icon_name=None): - Gtk.EventBox.__init__(self) - self._sensitive = True - vbox = Gtk.VBox() - hbox = Gtk.HBox() - vbox.set_border_width(style.DEFAULT_PADDING) - if icon_name is not None: - self.icon = Icon() - self.icon.props.icon_name = icon_name - hbox.pack_start(self.icon, expand=False, fill=False, - padding=style.DEFAULT_PADDING) - align = Gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0) - text = '' % style.COLOR_WHITE.get_html() + \ - text_label + '' - self.label = Gtk.Label() - self.label.set_use_markup(True) - self.label.set_markup(text) - align.add(self.label) - hbox.pack_start(align, expand=True, fill=True, - padding=style.DEFAULT_PADDING) - vbox.pack_start(hbox, expand=False, fill=False, - padding=style.DEFAULT_PADDING) - self.add(vbox) - self.id_bt_release_cb = self.connect('button-release-event', - self.__button_release_cb) - self.id_enter_notify_cb = self.connect('enter-notify-event', - self.__enter_notify_cb) - self.id_leave_notify_cb = self.connect('leave-notify-event', - self.__leave_notify_cb) - self.modify_bg(Gtk.StateType.NORMAL, style.COLOR_BLACK.get_gdk_color()) - self.show_all() - self.set_above_child(True) - - def __button_release_cb(self, widget, event): - self.emit('clicked') - - def __enter_notify_cb(self, widget, event): - self.modify_bg(Gtk.StateType.NORMAL, - style.COLOR_BUTTON_GREY.get_gdk_color()) - - def __leave_notify_cb(self, widget, event): - self.modify_bg(Gtk.StateType.NORMAL, style.COLOR_BLACK.get_gdk_color()) - - def set_icon(self, icon_name): - self.icon.props.icon_name = icon_name - - def set_label(self, text_label): - text = '' % style.COLOR_WHITE.get_html() + \ - text_label + '' - self.label.set_markup(text) - - def set_sensitive(self, sensitive): - if self._sensitive == sensitive: - return - - self._sensitive = sensitive - if sensitive: - self.handler_unblock(self.id_bt_release_cb) - self.handler_unblock(self.id_enter_notify_cb) - self.handler_unblock(self.id_leave_notify_cb) - else: - self.handler_block(self.id_bt_release_cb) - self.handler_block(self.id_enter_notify_cb) - self.handler_block(self.id_leave_notify_cb) - self.modify_bg(Gtk.StateType.NORMAL, - style.COLOR_BLACK.get_gdk_color()) diff --git a/webtoolbar.py b/webtoolbar.py index 3a0ec57..642b310 100644 --- a/webtoolbar.py +++ b/webtoolbar.py @@ -27,13 +27,13 @@ from gi.repository import WebKit from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics import iconentry from sugar3.graphics.toolbarbox import ToolbarBox as ToolbarBase +from sugar3.graphics.palettemenu import PaletteMenuItem from sugar3.graphics import style from sugar3.activity.widgets import ActivityToolbarButton from sugar3.activity.widgets import StopButton import filepicker import places -from sugarmenuitem import SugarMenuItem from browser import Browser from pdfviewer import DummyBrowser @@ -492,8 +492,8 @@ class PrimaryToolbar(ToolbarBase): if not isinstance(title, unicode): title = unicode(title, 'utf-8') # This is a fix until the Sugar MenuItem is fixed: - menu_item = SugarMenuItem(text_label=title) - menu_item.connect('clicked', self._history_item_activated_cb, + menu_item = PaletteMenuItem(text_label=title) + menu_item.connect('activate', self._history_item_activated_cb, item_index) return menu_item @@ -519,6 +519,8 @@ class PrimaryToolbar(ToolbarBase): item_index += 1 def _history_item_activated_cb(self, menu_item, index): + self._back.get_palette().popdown(immediate=True) + self._forward.get_palette().popdown(immediate=True) self._browser.set_history_index(index) def _link_add_clicked_cb(self, button): -- cgit v0.9.1