From 4fbf089860509abe9920ccc170d417249c816669 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Wed, 22 May 2013 18:00:05 +0000 Subject: Replace MenuItem by PaletteMenuItem - SL #4500 PaletteMenuItem is the new widget we should use in gtk3 Signed-off-by: Gonzalo Odiard --- diff --git a/toolbar.py b/toolbar.py index 97dc6bd..e344776 100644 --- a/toolbar.py +++ b/toolbar.py @@ -31,7 +31,7 @@ from sugar3.graphics.toolbutton import ToolButton from sugar3.graphics.toolcombobox import ToolComboBox from sugar3.graphics.colorbutton import ColorToolButton from sugar3.graphics.toggletoolbutton import ToggleToolButton -from sugar3.graphics.radiopalette import RadioMenuButton +from sugar3.graphics.palettemenu import PaletteMenuBox from sugar3.graphics import iconentry from sugar3.graphics import style from sugar3.activity.widgets import CopyButton @@ -472,26 +472,37 @@ class TextToolbar(Gtk.Toolbar): # MAGIC NUMBER WARNING: Secondary toolbars are not a standard height? self.set_size_request(-1, style.GRID_CELL_SIZE) - def append_align(icon_name, tooltip, do_abi_cb, style_name, button): + def append_align(icon_name, tooltip, do_abi_cb, style_name, button, + menu_box): menu_item = AbiMenuItem(abiword_canvas, style_name, do_abi_cb, icon_name, tooltip, button) - button.props.palette.menu.append(menu_item) + menu_box.append_item(menu_item) menu_item.show() - self._aligment_btn = RadioMenuButton(icon_name='format-justify-left') + self._aligment_btn = ToolButton(icon_name='format-justify-left') self._aligment_btn.props.tooltip = _('Choose alignment') + self._aligment_btn.props.hide_tooltip_on_click = False + self._aligment_btn.palette_invoker.props.toggle_palette = True + + menu_box = PaletteMenuBox() + self._aligment_btn.props.palette.set_content(menu_box) + menu_box.show() append_align('format-justify-left', _('Left justify'), - abiword_canvas.align_left, 'left-align', self._aligment_btn) + abiword_canvas.align_left, 'left-align', self._aligment_btn, + menu_box) append_align('format-justify-center', _('Center justify'), - abiword_canvas.align_center, 'center-align', self._aligment_btn) + abiword_canvas.align_center, 'center-align', self._aligment_btn, + menu_box) append_align('format-justify-right', _('Right justify'), - abiword_canvas.align_right, 'right-align', self._aligment_btn) + abiword_canvas.align_right, 'right-align', self._aligment_btn, + menu_box) append_align('format-justify-fill', _('Fill justify'), - abiword_canvas.align_justify, 'justify-align', self._aligment_btn) + abiword_canvas.align_justify, 'justify-align', self._aligment_btn, + menu_box) self.insert(self._aligment_btn, -1) @@ -574,14 +585,20 @@ class ParagraphToolbar(Gtk.Toolbar): self.insert(Gtk.SeparatorToolItem(), -1) def append_list(icon_name, tooltip, do_abi_cb, on_abi_cb, button, - button_icon=None): + menu_box, button_icon=None): menu_item = AbiMenuItem(abi, 'style-name', do_abi_cb, icon_name, tooltip, button, on_abi_cb, button_icon) - button.props.palette.menu.append(menu_item) + menu_box.append_item(menu_item) menu_item.show() - list_btn = RadioMenuButton(icon_name='toolbar-bulletlist') + list_btn = ToolButton(icon_name='toolbar-bulletlist') list_btn.props.tooltip = _('Select list') + list_btn.props.hide_tooltip_on_click = False + list_btn.palette_invoker.props.toggle_palette = True + + menu_box = PaletteMenuBox() + list_btn.props.palette.set_content(menu_box) + menu_box.show() append_list('list-none', _('Normal'), lambda: abi.set_style('Normal'), @@ -591,27 +608,32 @@ class ParagraphToolbar(Gtk.Toolbar): 'Numbered List', 'Lower Case List', 'Upper Case List'], - list_btn, 'toolbar-bulletlist') + list_btn, menu_box, 'toolbar-bulletlist') append_list('list-bullet', _('Bullet List'), lambda: abi.set_style('Bullet List'), - lambda abi, style: style == 'Bullet List', list_btn) + lambda abi, style: style == 'Bullet List', list_btn, + menu_box) append_list('list-dashed', _('Dashed List'), lambda: abi.set_style('Dashed List'), - lambda abi, style: style == 'Dashed List', list_btn) + lambda abi, style: style == 'Dashed List', list_btn, + menu_box) append_list('list-numbered', _('Numbered List'), lambda: abi.set_style('Numbered List'), - lambda abi, style: style == 'Numbered List', list_btn) + lambda abi, style: style == 'Numbered List', list_btn, + menu_box) append_list('list-lower-case', _('Lower Case List'), lambda: abi.set_style('Lower Case List'), - lambda abi, style: style == 'Lower Case List', list_btn) + lambda abi, style: style == 'Lower Case List', list_btn, + menu_box) append_list('list-upper-case', _('Upper Case List'), lambda: abi.set_style('Upper Case List'), - lambda abi, style: style == 'Upper Case List', list_btn) + lambda abi, style: style == 'Upper Case List', list_btn, + menu_box) self.insert(list_btn, -1) diff --git a/widgets.py b/widgets.py index 47b5e3d..bc05082 100644 --- a/widgets.py +++ b/widgets.py @@ -25,7 +25,7 @@ from sugar3.graphics.radiotoolbutton import RadioToolButton from sugar3.graphics.combobox import ComboBox from sugar3.graphics.palette import Palette from sugar3.graphics.toolbutton import ToolButton -from sugar3.graphics.menuitem import MenuItem +from sugar3.graphics.palettemenu import PaletteMenuItem from sugar3.datastore import datastore from sugar3.activity.activity import SCOPE_PRIVATE @@ -168,7 +168,7 @@ class AbiButton(RadioToolButton): self.handler_unblock(self._toggled_handler) -class AbiMenuItem(MenuItem): +class AbiMenuItem(PaletteMenuItem): def __init__(self, abi, abi_signal, do_abi_cb, icon_name, label, button, on_abi_cb=None, button_icon_name=None): @@ -177,7 +177,7 @@ class AbiMenuItem(MenuItem): # the list menu self._button_icon_name = button_icon_name self._button = button - MenuItem.__init__(self, icon_name=icon_name, text_label=label) + PaletteMenuItem.__init__(self, icon_name=icon_name, text_label=label) self._abi_handler = abi.connect(abi_signal, self.__abi_cb, abi_signal, on_abi_cb) -- cgit v0.9.1