Ticket #4144: 0001-Set-correct-padding-and-size-for-the-palette-window-.patch

File 0001-Set-correct-padding-and-size-for-the-palette-window-.patch, 15.2 KB (added by manuq, 11 years ago)

New toolkit patch.

  • src/sugar3/graphics/Makefile.am

    From 334f9ef5b0a0277ce3a2607a0f9de6e63ef5e1bb Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
    Date: Thu, 1 Nov 2012 17:45:37 -0300
    Subject: [PATCH toolkit-gtk3] Set correct padding and size for the palette,
     window implementation - SL #4144
    MIME-Version: 1.0
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
    
    A new API is provided: PaletteMenuBox is a container to be used in
    Palette.set_content().  This is to hide the implementation details and
    set the corresponding paddings and sizes.
    
    Usage:
    
      box = PaletteMenuBox()
      palette.set_content(box)
    
    Then we can append items to it, like:
    
      item = PaletteMenuItem(text_label, icon, xo_color=xo_color)
      box.append_child(item)
    
      separator = PaletteMenuItemSeparator()
      box.append_child(item)
    
    We can also append any widget, and the box will handle the paddings:
    
      box.append_child(widget)
    
    style.DEFAULT_PADDING for horizontal and vertical padding is the
    default.  But can be overriden:
    
      box.append_child(widget, horizontal_padding=0, vertical_padding=0)
    
    Details:
    
    - move palettemenuitem.py to palettemenu.py
    
    - Width of palette: make it a minimun size of 3 Sugar grid cells.
    
    - Padding of content, secondary box: we need top and bottom padding,
      which can be set when packing the items container inside the
      secondary box.
    
    - Padding of menu items: needs to be just for left and right, so move
      the padding to a new horizontal box.
    
    - Padding of separators: unlike GtkSeparatorMenuItem, GtkSeparator
      doesn't support padding.  But we can wrap it in a GtkEventBox and
      force the height of the widget there.
    
    Signed-off-by: Manuel Quiñones <manuq@laptop.org>
    ---
     src/sugar3/graphics/Makefile.am        |   2 +-
     src/sugar3/graphics/palette.py         |   4 +-
     src/sugar3/graphics/palettemenu.py     | 168 +++++++++++++++++++++++++++++++++
     src/sugar3/graphics/palettemenuitem.py | 123 ------------------------
     src/sugar3/graphics/palettewindow.py   |   2 +-
     5 files changed, 172 insertions(+), 127 deletions(-)
     create mode 100644 src/sugar3/graphics/palettemenu.py
     delete mode 100644 src/sugar3/graphics/palettemenuitem.py
    
    diff --git a/src/sugar3/graphics/Makefile.am b/src/sugar3/graphics/Makefile.am
    index a298a32..a4f9629 100644
    a b sugar_PYTHON = \ 
    1212        objectchooser.py        \
    1313        palettegroup.py         \
    1414        palette.py              \
    15         palettemenuitem.py      \
     15        palettemenu.py          \
    1616        palettewindow.py        \
    1717        panel.py                \
    1818        radiopalette.py         \
  • src/sugar3/graphics/palette.py

    diff --git a/src/sugar3/graphics/palette.py b/src/sugar3/graphics/palette.py
    index efdc9fd..0e49e35 100644
    a b class Palette(PaletteWindow): 
    230230    def _add_content(self):
    231231        # The content is not shown until a widget is added
    232232        self._content = Gtk.VBox()
    233         self._content.set_border_width(style.DEFAULT_SPACING)
    234         self._secondary_box.pack_start(self._content, True, True, 0)
     233        self._secondary_box.pack_start(self._content, True, True,
     234                                       style.DEFAULT_SPACING)
    235235
    236236    def _update_accel_widget(self):
    237237        assert self.props.invoker is not None
  • new file src/sugar3/graphics/palettemenu.py

    diff --git a/src/sugar3/graphics/palettemenu.py b/src/sugar3/graphics/palettemenu.py
    new file mode 100644
    index 0000000..2bf7227
    - +  
     1# Copyright 2012 One Laptop Per Child
     2#
     3# This program is free software; you can redistribute it and/or modify
     4# it under the terms of the GNU General Public License as published by
     5# the Free Software Foundation; either version 2 of the License, or
     6# (at your option) any later version.
     7#
     8# This program is distributed in the hope that it will be useful,
     9# but WITHOUT ANY WARRANTY; without even the implied warranty of
     10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11# GNU General Public License for more details.
     12#
     13# You should have received a copy of the GNU General Public License
     14# along with this program; if not, write to the Free Software
     15# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     16
     17import logging
     18
     19from gi.repository import GObject
     20from gi.repository import Gtk
     21
     22from sugar3.graphics.icon import Icon
     23from sugar3.graphics import style
     24
     25
     26class PaletteMenuBox(Gtk.VBox):
     27    def __init__(self):
     28        Gtk.VBox.__init__(self)
     29
     30    def append_item(self, item_or_widget, horizontal_padding=None,
     31                    vertical_padding=None):
     32        item = None
     33        if (isinstance(item_or_widget, PaletteMenuItem) or
     34            isinstance(item_or_widget, PaletteMenuItemSeparator)):
     35            item = item_or_widget
     36        else:
     37            item = self._wrap_widget(item_or_widget, horizontal_padding,
     38                                     vertical_padding)
     39
     40        self.pack_start(item, False, False, 0)
     41
     42    def _wrap_widget(self, widget, horizontal_padding, vertical_padding):
     43        vbox = Gtk.VBox()
     44        vbox.show()
     45
     46        if horizontal_padding is None:
     47            horizontal_padding = style.DEFAULT_SPACING
     48
     49        if vertical_padding is None:
     50            vertical_padding = style.DEFAULT_SPACING
     51
     52        hbox = Gtk.HBox()
     53        vbox.pack_start(hbox, True, True, vertical_padding)
     54        hbox.show()
     55
     56        hbox.pack_start(widget, True, True, horizontal_padding)
     57        return vbox
     58
     59
     60class PaletteMenuItemSeparator(Gtk.EventBox):
     61    """Contains a HSeparator and has the proper height for the menu."""
     62
     63    __gtype_name__ = 'SugarPaletteMenuItemSeparator'
     64
     65    def __init__(self):
     66        Gtk.EventBox.__init__(self)
     67        separator = Gtk.HSeparator()
     68        self.add(separator)
     69        separator.show()
     70        self.set_size_request(-1, style.DEFAULT_SPACING * 2)
     71
     72
     73class PaletteMenuItem(Gtk.EventBox):
     74
     75    __gtype_name__ = 'SugarPaletteMenuItem'
     76
     77    __gsignals__ = {
     78        'activate': (GObject.SignalFlags.RUN_FIRST, None, [])
     79    }
     80
     81    def __init__(self, text_label=None, icon_name=None, text_maxlen=60,
     82                 xo_color=None, file_name=None):
     83
     84        Gtk.EventBox.__init__(self)
     85        self.set_above_child(True)
     86
     87        self.icon = None
     88        self._hbox = Gtk.HBox()
     89
     90        vbox = Gtk.VBox()
     91        self.add(vbox)
     92        vbox.show()
     93
     94        hbox = Gtk.HBox()
     95        vbox.pack_start(hbox, True, True, style.DEFAULT_PADDING)
     96        hbox.show()
     97
     98        hbox.pack_start(self._hbox, True, True, style.DEFAULT_PADDING)
     99
     100        if icon_name is not None:
     101            self.icon = Icon(icon_name=icon_name,
     102                        icon_size=Gtk.IconSize.SMALL_TOOLBAR)
     103            if xo_color is not None:
     104                self.icon.props.xo_color = xo_color
     105            self._hbox.pack_start(self.icon, expand=False, fill=False,
     106                                  padding=style.DEFAULT_PADDING)
     107        elif file_name is not None:
     108            self.icon = Icon(file=file_name,
     109                             icon_size=Gtk.IconSize.SMALL_TOOLBAR)
     110            if xo_color is not None:
     111                self.icon.props.xo_color = xo_color
     112            self._hbox.pack_start(self.icon, expand=False, fill=False,
     113                                  padding=style.DEFAULT_PADDING)
     114
     115        align = Gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0)
     116        self.label = Gtk.Label(text_label)
     117        align.add(self.label)
     118        self._hbox.pack_start(align, expand=True, fill=True,
     119                        padding=style.DEFAULT_PADDING)
     120
     121        self.id_bt_release_cb = self.connect('button-release-event',
     122                self.__button_release_cb)
     123        self.id_enter_notify_cb = self.connect('enter-notify-event',
     124                                               self.__enter_notify_cb)
     125        self.id_leave_notify_cb = self.connect('leave-notify-event',
     126                                               self.__leave_notify_cb)
     127
     128        self.show_all()
     129
     130    def __button_release_cb(self, widget, event):
     131        self.emit('activate')
     132
     133    def __enter_notify_cb(self, widget, event):
     134        self.modify_bg(Gtk.StateType.NORMAL,
     135                       style.COLOR_BUTTON_GREY.get_gdk_color())
     136
     137    def __leave_notify_cb(self, widget, event):
     138        self.modify_bg(Gtk.StateType.NORMAL,
     139                       style.COLOR_BLACK.get_gdk_color())
     140
     141    def set_label(self, text_label):
     142        text = '<span foreground="%s">' % style.COLOR_WHITE.get_html() + \
     143                    text_label + '</span>'
     144        self.label.set_markup(text)
     145
     146    def set_image(self, icon):
     147        self._hbox.pack_start(icon, expand=False, fill=False,
     148                              padding=style.DEFAULT_PADDING)
     149        self._hbox.reorder_child(icon, 0)
     150
     151    def set_sensitive(self, sensitive):
     152        is_sensitive = bool(not self.get_state_flags() & \
     153                                Gtk.StateFlags.INSENSITIVE)
     154        if is_sensitive == sensitive:
     155            return
     156
     157        if sensitive:
     158            self.handler_unblock(self.id_bt_release_cb)
     159            self.handler_unblock(self.id_enter_notify_cb)
     160            self.handler_unblock(self.id_leave_notify_cb)
     161            self.unset_state_flags(Gtk.StateFlags.INSENSITIVE)
     162        else:
     163            self.handler_block(self.id_bt_release_cb)
     164            self.handler_block(self.id_enter_notify_cb)
     165            self.handler_block(self.id_leave_notify_cb)
     166            self.set_state_flags(self.get_state_flags() | \
     167                                     Gtk.StateFlags.INSENSITIVE,
     168                                 clear=True)
  • deleted file src/sugar3/graphics/palettemenuitem.py

    diff --git a/src/sugar3/graphics/palettemenuitem.py b/src/sugar3/graphics/palettemenuitem.py
    deleted file mode 100644
    index 7861a0b..0000000
    + -  
    1 # Copyright 2012 One Laptop Per Child
    2 #
    3 # This program is free software; you can redistribute it and/or modify
    4 # it under the terms of the GNU General Public License as published by
    5 # the Free Software Foundation; either version 2 of the License, or
    6 # (at your option) any later version.
    7 #
    8 # This program is distributed in the hope that it will be useful,
    9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11 # GNU General Public License for more details.
    12 #
    13 # You should have received a copy of the GNU General Public License
    14 # along with this program; if not, write to the Free Software
    15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    16 
    17 import logging
    18 
    19 from gi.repository import GObject
    20 from gi.repository import Gtk
    21 
    22 from sugar3.graphics.icon import Icon
    23 from sugar3.graphics import style
    24 
    25 
    26 class PaletteMenuItemSeparator(Gtk.HSeparator):
    27     """A HSeparator that can be styled in the theme"""
    28 
    29     __gtype_name__ = 'SugarPaletteMenuItemSeparator'
    30 
    31     def __init__(self):
    32         Gtk.HSeparator.__init__(self)
    33 
    34 
    35 class PaletteMenuItem(Gtk.EventBox):
    36 
    37     __gtype_name__ = 'SugarPaletteMenuItem'
    38 
    39     __gsignals__ = {
    40         'activate': (GObject.SignalFlags.RUN_FIRST, None, [])
    41     }
    42 
    43     def __init__(self, text_label=None, icon_name=None, text_maxlen=60,
    44                  xo_color=None, file_name=None):
    45         Gtk.EventBox.__init__(self)
    46         self.set_above_child(True)
    47         self.icon = None
    48 
    49         vbox = Gtk.VBox()
    50         vbox.set_border_width(style.DEFAULT_PADDING)
    51         self._hbox = Gtk.HBox()
    52         if icon_name is not None:
    53             self.icon = Icon(icon_name=icon_name,
    54                         icon_size=Gtk.IconSize.SMALL_TOOLBAR)
    55             if xo_color is not None:
    56                 self.icon.props.xo_color = xo_color
    57             self._hbox.pack_start(self.icon, expand=False, fill=False,
    58                                   padding=style.DEFAULT_PADDING)
    59         elif file_name is not None:
    60             self.icon = Icon(file=file_name,
    61                              icon_size=Gtk.IconSize.SMALL_TOOLBAR)
    62             if xo_color is not None:
    63                 self.icon.props.xo_color = xo_color
    64             self._hbox.pack_start(self.icon, expand=False, fill=False,
    65                                   padding=style.DEFAULT_PADDING)
    66 
    67         align = Gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0)
    68         self.label = Gtk.Label(text_label)
    69         align.add(self.label)
    70         self._hbox.pack_start(align, expand=True, fill=True,
    71                         padding=style.DEFAULT_PADDING)
    72         vbox.pack_start(self._hbox, expand=False, fill=False,
    73                         padding=style.DEFAULT_PADDING)
    74         self.add(vbox)
    75 
    76         self.id_bt_release_cb = self.connect('button-release-event',
    77                 self.__button_release_cb)
    78         self.id_enter_notify_cb = self.connect('enter-notify-event',
    79                                                self.__enter_notify_cb)
    80         self.id_leave_notify_cb = self.connect('leave-notify-event',
    81                                                self.__leave_notify_cb)
    82 
    83         self.show_all()
    84 
    85     def __button_release_cb(self, widget, event):
    86         self.emit('activate')
    87 
    88     def __enter_notify_cb(self, widget, event):
    89         self.modify_bg(Gtk.StateType.NORMAL,
    90                        style.COLOR_BUTTON_GREY.get_gdk_color())
    91 
    92     def __leave_notify_cb(self, widget, event):
    93         self.modify_bg(Gtk.StateType.NORMAL,
    94                        style.COLOR_BLACK.get_gdk_color())
    95 
    96     def set_label(self, text_label):
    97         text = '<span foreground="%s">' % style.COLOR_WHITE.get_html() + \
    98                     text_label + '</span>'
    99         self.label.set_markup(text)
    100 
    101     def set_image(self, icon):
    102         self._hbox.pack_start(icon, expand=False, fill=False,
    103                               padding=style.DEFAULT_PADDING)
    104         self._hbox.reorder_child(icon, 0)
    105 
    106     def set_sensitive(self, sensitive):
    107         is_sensitive = bool(not self.get_state_flags() & \
    108                                 Gtk.StateFlags.INSENSITIVE)
    109         if is_sensitive == sensitive:
    110             return
    111 
    112         if sensitive:
    113             self.handler_unblock(self.id_bt_release_cb)
    114             self.handler_unblock(self.id_enter_notify_cb)
    115             self.handler_unblock(self.id_leave_notify_cb)
    116             self.unset_state_flags(Gtk.StateFlags.INSENSITIVE)
    117         else:
    118             self.handler_block(self.id_bt_release_cb)
    119             self.handler_block(self.id_enter_notify_cb)
    120             self.handler_block(self.id_leave_notify_cb)
    121             self.set_state_flags(self.get_state_flags() | \
    122                                      Gtk.StateFlags.INSENSITIVE,
    123                                  clear=True)
  • src/sugar3/graphics/palettewindow.py

    diff --git a/src/sugar3/graphics/palettewindow.py b/src/sugar3/graphics/palettewindow.py
    index e1fde4a..4f34461 100644
    a b class _PaletteWindowWidget(Gtk.Window): 
    282282        if self._palette is not None:
    283283            label_width = self._palette.get_label_width()
    284284        size = max(natural, label_width + 2 * self.get_border_width(),
    285                    style.GRID_CELL_SIZE * 2)
     285                   style.GRID_CELL_SIZE * 3)
    286286        return size, size
    287287
    288288    def do_size_allocate(self, allocation):