Skip to content

Commit

Permalink
Support for pixbuf images to palettes
Browse files Browse the repository at this point in the history
Fixes #4614
  • Loading branch information
edudev committed Dec 13, 2013
1 parent ee88193 commit e5997eb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/sugar3/graphics/objectchooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def get_preview_pixbuf(preview_data, width=-1, height=-1):
scale_h = height * 1.0 / png_height
scale = min(scale_w, scale_h)

# center the image if the scales are not equal
translate_x = int((width - (png_width * scale)) / 2)
translate_y = int((height - (png_height * scale)) / 2)
cr.translate(translate_x, translate_y)

cr.scale(scale, scale)

cr.set_source_rgba(1, 1, 1, 0)
Expand Down
34 changes: 29 additions & 5 deletions src/sugar3/graphics/palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ def __init__(self, label=None, accel_path=None,
self._icon_box.set_size_request(style.GRID_CELL_SIZE, -1)
self._primary_box.pack_start(self._icon_box, False, True, 0)

labels_box = Gtk.VBox()
self._labels_box = Gtk.VBox()
self._label_alignment = Gtk.Alignment(xalign=0, yalign=0.5, xscale=1,
yscale=0.33)
self._label_alignment.set_padding(0, 0, style.DEFAULT_SPACING,
style.DEFAULT_SPACING)
self._label_alignment.add(labels_box)
self._label_alignment.add(self._labels_box)
self._label_alignment.show()
self._primary_box.pack_start(self._label_alignment, True, True, 0)
labels_box.show()
self._labels_box.show()

self._label = Gtk.AccelLabel(label='')
self._label.set_alignment(0, 0.5)

if text_maxlen > 0:
self._label.set_max_width_chars(text_maxlen)
self._label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
labels_box.pack_start(self._label, True, True, 0)
self._labels_box.pack_start(self._label, True, True, 0)

self._secondary_label = Gtk.Label()
self._secondary_label.set_alignment(0, 0.5)
Expand All @@ -143,7 +143,10 @@ def __init__(self, label=None, accel_path=None,
self._secondary_label.set_max_width_chars(text_maxlen)
self._secondary_label.set_ellipsize(Pango.EllipsizeMode.END)

labels_box.pack_start(self._secondary_label, True, True, 0)
self._labels_box.pack_start(self._secondary_label, True, True, 0)

self._image = None
self._image_separator = None

self._secondary_box = Gtk.VBox()

Expand Down Expand Up @@ -272,6 +275,25 @@ def get_secondary_text(self):
secondary_text = GObject.property(type=str, getter=get_secondary_text,
setter=set_secondary_text)

def set_pixbuf(self, pixbuf):
if self._image is None:
self._image_separator = Gtk.HSeparator()
self._labels_box.pack_start(self._image_separator, True, True, 0)
self._image_separator.show()

self._image = Gtk.Image()
self._image.set_alignment(0.5, 0.5)
self._labels_box.pack_start(self._image, True, True, 5)

if pixbuf is not None:
self._image.set_from_pixbuf(pixbuf)
self._image.show()
else:
self._image.hide()

def get_pixbuf(self):
return self._image

def _show_icon(self):
self._label_alignment.set_padding(0, 0, 0, style.DEFAULT_SPACING)
self._icon_box.show()
Expand Down Expand Up @@ -373,6 +395,8 @@ def get_label_width(self):
def _update_separators(self):
visible = self._content.get_children()
self._separator.props.visible = visible
if self._image_separator:
self._image_separator.props.visible = visible

def _update_accept_focus(self):
accept_focus = len(self._content.get_children())
Expand Down

0 comments on commit e5997eb

Please sign in to comment.