Ticket #4614: 0001-toolkit-Add-ability-to-preview-images-in-clipboard-in-Palett.patch

File 0001-toolkit-Add-ability-to-preview-images-in-clipboard-in-Palett.patch, 4.3 KB (added by svineet, 9 years ago)
  • src/sugar3/graphics/objectchooser.py

    From dd830239e75f711e74eab7c7f254cac9ae649e74 Mon Sep 17 00:00:00 2001
    From: Sai Vineet <saivineet89@gmail.com>
    Date: Thu, 4 Dec 2014 22:00:43 +0530
    Subject: [PATCH 1/1] Add ability to preview images in clipboard in Palette
     (with gonzalo)
    
    ---
     src/sugar3/graphics/objectchooser.py |  5 +++++
     src/sugar3/graphics/palette.py       | 32 ++++++++++++++++++++++++++------
     2 files changed, 31 insertions(+), 6 deletions(-)
    
    diff --git a/src/sugar3/graphics/objectchooser.py b/src/sugar3/graphics/objectchooser.py
    index 9c68661..6f39ab2 100644
    a b def get_preview_pixbuf(preview_data, width=-1, height=-1): 
    8282            scale_h = height * 1.0 / png_height
    8383            scale = min(scale_w, scale_h)
    8484
     85            # # center the image if the scales are not equal
     86            translate_x = int((width - (png_width * scale)) / 2)
     87            translate_y = int((height - (png_height * scale)) / 2)
     88            cr.translate(translate_x, translate_y)
     89
    8590            cr.scale(scale, scale)
    8691
    8792            cr.set_source_rgba(1, 1, 1, 0)
  • src/sugar3/graphics/palette.py

    diff --git a/src/sugar3/graphics/palette.py b/src/sugar3/graphics/palette.py
    index 7572ab1..29d6314 100644
    a b class Palette(PaletteWindow): 
    115115
    116116        self._primary_event_box = Gtk.EventBox()
    117117        self._primary_event_box.show()
    118         self._primary_box = Gtk.HBox()
     118        self._primary_box = Gtk.Box(Gtk.Orientation.HORIZONTAL)
    119119        self._primary_event_box.add(self._primary_box)
    120120        self._primary_box.show()
    121121
    class Palette(PaletteWindow): 
    123123        self._icon_box.set_size_request(style.GRID_CELL_SIZE, -1)
    124124        self._primary_box.pack_start(self._icon_box, False, True, 0)
    125125
    126         labels_box = Gtk.VBox()
     126        self.label_box = Gtk.VBox()
    127127        self._label_alignment = Gtk.Alignment(xalign=0, yalign=0.5, xscale=1,
    128128                                              yscale=0.33)
    129129        self._label_alignment.set_padding(
    130130            style.DEFAULT_SPACING, style.DEFAULT_SPACING,
    131131            style.DEFAULT_SPACING, style.DEFAULT_SPACING)
    132         self._label_alignment.add(labels_box)
     132        self._label_alignment.add(self.label_box)
    133133        self._label_alignment.show()
    134134        self._primary_box.pack_start(self._label_alignment, True, True, 0)
    135         labels_box.show()
     135        self.label_box.show()
    136136
    137137        self._label = Gtk.AccelLabel(label='')
    138138        self._label.set_alignment(0, 0.5)
    class Palette(PaletteWindow): 
    140140        if text_maxlen > 0:
    141141            self._label.set_max_width_chars(text_maxlen)
    142142            self._label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
    143         labels_box.pack_start(self._label, True, True, 0)
     143        self.label_box.pack_start(self._label, True, True, 0)
    144144        self._primary_event_box.connect('button-release-event',
    145145                                        self.__button_release_event_cb)
    146146        self._primary_event_box.set_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
    147147
    148148        self._secondary_label = Gtk.Label()
    149149        self._secondary_label.set_alignment(0, 0.5)
    150         labels_box.pack_start(self._secondary_label, True, True, 0)
     150        self.label_box.pack_start(self._secondary_label, True, True, 0)
     151
     152        self._image = None
    151153
    152154        self._secondary_box = Gtk.VBox()
    153155
    class Palette(PaletteWindow): 
    180182        self._content_widget = None
    181183        self.set_content(None)
    182184
     185    def set_pixbuf(self, pixbuf):
     186        if self._image is None:
     187            self._primary_box.set_orientation(Gtk.Orientation.VERTICAL)
     188            self._image_separator = Gtk.HSeparator()
     189            self._primary_box.pack_start(self._image_separator, True, True, 5)
     190
     191            self._image = Gtk.Image()
     192            self._image.set_alignment(0.5, 0.5)
     193            self._primary_box.pack_start(self._image, True, True, 5)
     194
     195        if pixbuf is not None:
     196            self._image.set_from_pixbuf(pixbuf)
     197            self._image.show()
     198            self._image_separator.show()
     199        else:
     200            self._image.hide()
     201            self._image_separator.hide()
     202
    183203    def _setup_widget(self):
    184204        PaletteWindow._setup_widget(self)
    185205        self._widget.connect('destroy', self.__destroy_cb)