Set correct padding and size for the palette, window implementation - SL #4144
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> Acked-by: Simon Schampijer <simon@laptop.org>
This commit is contained in:
parent
811676ef4e
commit
5505eb30bf
@ -12,7 +12,7 @@ sugar_PYTHON = \
|
||||
objectchooser.py \
|
||||
palettegroup.py \
|
||||
palette.py \
|
||||
palettemenuitem.py \
|
||||
palettemenu.py \
|
||||
palettewindow.py \
|
||||
panel.py \
|
||||
radiopalette.py \
|
||||
|
@ -230,8 +230,8 @@ class Palette(PaletteWindow):
|
||||
def _add_content(self):
|
||||
# The content is not shown until a widget is added
|
||||
self._content = Gtk.VBox()
|
||||
self._content.set_border_width(style.DEFAULT_SPACING)
|
||||
self._secondary_box.pack_start(self._content, True, True, 0)
|
||||
self._secondary_box.pack_start(self._content, True, True,
|
||||
style.DEFAULT_SPACING)
|
||||
|
||||
def _update_accel_widget(self):
|
||||
assert self.props.invoker is not None
|
||||
|
@ -23,13 +23,51 @@ from sugar3.graphics.icon import Icon
|
||||
from sugar3.graphics import style
|
||||
|
||||
|
||||
class PaletteMenuItemSeparator(Gtk.HSeparator):
|
||||
"""A HSeparator that can be styled in the theme"""
|
||||
class PaletteMenuBox(Gtk.VBox):
|
||||
def __init__(self):
|
||||
Gtk.VBox.__init__(self)
|
||||
|
||||
def append_item(self, item_or_widget, horizontal_padding=None,
|
||||
vertical_padding=None):
|
||||
item = None
|
||||
if (isinstance(item_or_widget, PaletteMenuItem) or
|
||||
isinstance(item_or_widget, PaletteMenuItemSeparator)):
|
||||
item = item_or_widget
|
||||
else:
|
||||
item = self._wrap_widget(item_or_widget, horizontal_padding,
|
||||
vertical_padding)
|
||||
|
||||
self.pack_start(item, False, False, 0)
|
||||
|
||||
def _wrap_widget(self, widget, horizontal_padding, vertical_padding):
|
||||
vbox = Gtk.VBox()
|
||||
vbox.show()
|
||||
|
||||
if horizontal_padding is None:
|
||||
horizontal_padding = style.DEFAULT_SPACING
|
||||
|
||||
if vertical_padding is None:
|
||||
vertical_padding = style.DEFAULT_SPACING
|
||||
|
||||
hbox = Gtk.HBox()
|
||||
vbox.pack_start(hbox, True, True, vertical_padding)
|
||||
hbox.show()
|
||||
|
||||
hbox.pack_start(widget, True, True, horizontal_padding)
|
||||
return vbox
|
||||
|
||||
|
||||
class PaletteMenuItemSeparator(Gtk.EventBox):
|
||||
"""Contains a HSeparator and has the proper height for the menu."""
|
||||
|
||||
__gtype_name__ = 'SugarPaletteMenuItemSeparator'
|
||||
|
||||
def __init__(self):
|
||||
Gtk.HSeparator.__init__(self)
|
||||
Gtk.EventBox.__init__(self)
|
||||
separator = Gtk.HSeparator()
|
||||
self.add(separator)
|
||||
separator.show()
|
||||
self.set_size_request(-1, style.DEFAULT_SPACING * 2)
|
||||
|
||||
|
||||
class PaletteMenuItem(Gtk.EventBox):
|
||||
@ -42,13 +80,23 @@ class PaletteMenuItem(Gtk.EventBox):
|
||||
|
||||
def __init__(self, text_label=None, icon_name=None, text_maxlen=60,
|
||||
xo_color=None, file_name=None):
|
||||
|
||||
Gtk.EventBox.__init__(self)
|
||||
self.set_above_child(True)
|
||||
|
||||
self.icon = None
|
||||
self._hbox = Gtk.HBox()
|
||||
|
||||
vbox = Gtk.VBox()
|
||||
vbox.set_border_width(style.DEFAULT_PADDING)
|
||||
self._hbox = Gtk.HBox()
|
||||
self.add(vbox)
|
||||
vbox.show()
|
||||
|
||||
hbox = Gtk.HBox()
|
||||
vbox.pack_start(hbox, True, True, style.DEFAULT_PADDING)
|
||||
hbox.show()
|
||||
|
||||
hbox.pack_start(self._hbox, True, True, style.DEFAULT_PADDING)
|
||||
|
||||
if icon_name is not None:
|
||||
self.icon = Icon(icon_name=icon_name,
|
||||
icon_size=Gtk.IconSize.SMALL_TOOLBAR)
|
||||
@ -69,9 +117,6 @@ class PaletteMenuItem(Gtk.EventBox):
|
||||
align.add(self.label)
|
||||
self._hbox.pack_start(align, expand=True, fill=True,
|
||||
padding=style.DEFAULT_PADDING)
|
||||
vbox.pack_start(self._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)
|
@ -306,7 +306,7 @@ class _PaletteWindowWidget(Gtk.Window):
|
||||
if self._palette is not None:
|
||||
label_width = self._palette.get_label_width()
|
||||
size = max(natural, label_width + 2 * self.get_border_width(),
|
||||
style.GRID_CELL_SIZE * 2)
|
||||
style.GRID_CELL_SIZE * 3)
|
||||
return size, size
|
||||
|
||||
def do_size_allocate(self, allocation):
|
||||
|
Loading…
Reference in New Issue
Block a user