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): |
82 | 82 | scale_h = height * 1.0 / png_height |
83 | 83 | scale = min(scale_w, scale_h) |
84 | 84 | |
| 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 | |
85 | 90 | cr.scale(scale, scale) |
86 | 91 | |
87 | 92 | cr.set_source_rgba(1, 1, 1, 0) |
diff --git a/src/sugar3/graphics/palette.py b/src/sugar3/graphics/palette.py
index 7572ab1..29d6314 100644
a
|
b
|
class Palette(PaletteWindow): |
115 | 115 | |
116 | 116 | self._primary_event_box = Gtk.EventBox() |
117 | 117 | self._primary_event_box.show() |
118 | | self._primary_box = Gtk.HBox() |
| 118 | self._primary_box = Gtk.Box(Gtk.Orientation.HORIZONTAL) |
119 | 119 | self._primary_event_box.add(self._primary_box) |
120 | 120 | self._primary_box.show() |
121 | 121 | |
… |
… |
class Palette(PaletteWindow): |
123 | 123 | self._icon_box.set_size_request(style.GRID_CELL_SIZE, -1) |
124 | 124 | self._primary_box.pack_start(self._icon_box, False, True, 0) |
125 | 125 | |
126 | | labels_box = Gtk.VBox() |
| 126 | self.label_box = Gtk.VBox() |
127 | 127 | self._label_alignment = Gtk.Alignment(xalign=0, yalign=0.5, xscale=1, |
128 | 128 | yscale=0.33) |
129 | 129 | self._label_alignment.set_padding( |
130 | 130 | style.DEFAULT_SPACING, style.DEFAULT_SPACING, |
131 | 131 | style.DEFAULT_SPACING, style.DEFAULT_SPACING) |
132 | | self._label_alignment.add(labels_box) |
| 132 | self._label_alignment.add(self.label_box) |
133 | 133 | self._label_alignment.show() |
134 | 134 | self._primary_box.pack_start(self._label_alignment, True, True, 0) |
135 | | labels_box.show() |
| 135 | self.label_box.show() |
136 | 136 | |
137 | 137 | self._label = Gtk.AccelLabel(label='') |
138 | 138 | self._label.set_alignment(0, 0.5) |
… |
… |
class Palette(PaletteWindow): |
140 | 140 | if text_maxlen > 0: |
141 | 141 | self._label.set_max_width_chars(text_maxlen) |
142 | 142 | 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) |
144 | 144 | self._primary_event_box.connect('button-release-event', |
145 | 145 | self.__button_release_event_cb) |
146 | 146 | self._primary_event_box.set_events(Gdk.EventMask.BUTTON_RELEASE_MASK) |
147 | 147 | |
148 | 148 | self._secondary_label = Gtk.Label() |
149 | 149 | 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 |
151 | 153 | |
152 | 154 | self._secondary_box = Gtk.VBox() |
153 | 155 | |
… |
… |
class Palette(PaletteWindow): |
180 | 182 | self._content_widget = None |
181 | 183 | self.set_content(None) |
182 | 184 | |
| 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 | |
183 | 203 | def _setup_widget(self): |
184 | 204 | PaletteWindow._setup_widget(self) |
185 | 205 | self._widget.connect('destroy', self.__destroy_cb) |