diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2011-06-16 14:39:43 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2011-06-16 14:39:43 (GMT) |
commit | 07483c0b16feb3038a93bfa9e109079bd848f3cb (patch) | |
tree | 0f342c70df5bb0c0fb4ff34ac9a9294b0a9af076 /OficinaActivity.py | |
parent | 1aba0927adaa4ed5f6e9e74f30171b6df2c79d7b (diff) |
Center image in the canvas - SL #2896
Signed-off-by: manuel quiƱones <manuel.por.aca@gmail.com>
Acked-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'OficinaActivity.py')
-rw-r--r-- | OficinaActivity.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/OficinaActivity.py b/OficinaActivity.py index 86175c2..db2df9f 100644 --- a/OficinaActivity.py +++ b/OficinaActivity.py @@ -116,6 +116,7 @@ class OficinaActivity(activity.Activity): def size_allocate_cb(widget, allocation): self.fixed.disconnect(self._setup_handle) self.area.setup(allocation.width, allocation.height) + self.center_area() self.canvas.add_with_viewport(self.fixed) self.disconnect(self._setup_handle) @@ -142,6 +143,7 @@ class OficinaActivity(activity.Activity): self.fixed.disconnect(self._setup_handle) self.area.setup(pixbuf.get_width(), pixbuf.get_height()) self.area.loadImageFromJournal(pixbuf) + self.center_area() self.canvas.add_with_viewport(self.fixed) self.disconnect(self._setup_handle) @@ -173,3 +175,23 @@ class OficinaActivity(activity.Activity): gtk.gdk.colormap_get_system(), 0, 0, 0, 0, -1, -1) self.metadata['mime_type'] = 'image/png' pixbuf.save(file_path, 'png', {}) + + def _get_area_displacement(self): + """Return the point to use as top left corner in order to move + the drawing area and center it on the canvas. + + """ + canvas_width = self.canvas.allocation.width + canvas_height = self.canvas.allocation.height + area_width, area_height = self.area.get_size_request() + x = (canvas_width - area_width) / 2 + y = (canvas_height - area_height) / 2 + return x, y + + def center_area(self): + x, y = self._get_area_displacement() + self.fixed.move(self.area, x, y) + + def move_textview(self, dx, dy): + x, y = self._get_area_displacement() + self.fixed.move(self.textview, x + dx, y + dy) |