From 1a679ac11ce1acff1dd97234b8b2910a2ec55ce8 Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Fri, 02 Mar 2012 19:01:34 +0000 Subject: Use SugarMenuItem in the back/forward palettes This is a fix for the GTK+3 menu palettes, and should be reverted when the palettes are fixed. Is the same hack as current Read activity. Signed-off-by: Manuel QuiƱones --- diff --git a/sugarmenuitem.py b/sugarmenuitem.py new file mode 100644 index 0000000..5071406 --- /dev/null +++ b/sugarmenuitem.py @@ -0,0 +1,95 @@ +# 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 ffc2864..098f832 100644 --- a/webtoolbar.py +++ b/webtoolbar.py @@ -25,7 +25,6 @@ from gi.repository import Pango from gi.repository import WebKit from sugar3.graphics.toolbutton import ToolButton -from sugar3.graphics.menuitem import MenuItem from sugar3.graphics import iconentry from sugar3.graphics.toolbarbox import ToolbarBox as ToolbarBase from sugar3.activity.widgets import ActivityToolbarButton @@ -34,6 +33,7 @@ from sugar3.activity.widgets import StopButton # FIXME # import filepicker import places +from sugarmenuitem import SugarMenuItem _MAX_HISTORY_ENTRIES = 15 @@ -270,6 +270,13 @@ class PrimaryToolbar(ToolbarBase): toolbar.insert(self._back, -1) self._back.show() + palette = self._back.get_palette() + self._back_box_menu = Gtk.VBox() + self._back_box_menu.show() + palette.set_content(self._back_box_menu) + # FIXME, this is a hack, should be done in the theme: + palette._content.set_border_width(1) + self._forward = ToolButton('go-next-paired') self._forward.set_tooltip(_('Forward')) self._forward.props.sensitive = False @@ -277,6 +284,13 @@ class PrimaryToolbar(ToolbarBase): toolbar.insert(self._forward, -1) self._forward.show() + palette = self._forward.get_palette() + self._forward_box_menu = Gtk.VBox() + self._forward_box_menu.show() + palette.set_content(self._forward_box_menu) + # FIXME, this is a hack, should be done in the theme: + palette._content.set_border_width(1) + self._link_add = ToolButton('emblem-favorite') self._link_add.set_tooltip(_('Bookmark')) self._link_add.connect('clicked', self._link_add_clicked_cb) @@ -410,17 +424,18 @@ class PrimaryToolbar(ToolbarBase): item_index = 0 # The index of the history item # Clear menus in palettes: - for palette in (self._back.get_palette(), self._forward.get_palette()): - for menu_item in palette.menu.get_children(): - palette.menu.remove(menu_item) + for box_menu in (self._back_box_menu, self._forward_box_menu): + for menu_item in box_menu.get_children(): + box_menu.remove(menu_item) def create_menu_item(history_item, item_index): """Create a MenuItem for the back or forward palettes.""" title = history_item.get_title() if not isinstance(title, unicode): title = unicode(title, 'utf-8') - menu_item = MenuItem(title, text_maxlen=60) - menu_item.connect('activate', self._history_item_activated_cb, + # 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, item_index) return menu_item @@ -429,8 +444,7 @@ class PrimaryToolbar(ToolbarBase): back_list.reverse() for item in back_list: menu_item = create_menu_item(item, item_index) - palette = self._back.get_palette() - palette.menu.prepend(menu_item) + self._back_box_menu.pack_end(menu_item, False, False, 0) menu_item.show() item_index += 1 @@ -442,8 +456,7 @@ class PrimaryToolbar(ToolbarBase): forward_list.reverse() for item in forward_list: menu_item = create_menu_item(item, item_index) - palette = self._forward.get_palette() - palette.menu.append(menu_item) + self._forward_box_menu.pack_start(menu_item, False, False, 0) menu_item.show() item_index += 1 -- cgit v0.9.1