Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/OficinaActivity.py
diff options
context:
space:
mode:
Diffstat (limited to 'OficinaActivity.py')
-rw-r--r--OficinaActivity.py57
1 files changed, 28 insertions, 29 deletions
diff --git a/OficinaActivity.py b/OficinaActivity.py
index 64dace4..29cb2d3 100644
--- a/OficinaActivity.py
+++ b/OficinaActivity.py
@@ -61,11 +61,11 @@ Walter Bender (walter@laptop.org)
"""
-import gtk
+from gi.repository import Gtk
import logging
-from sugar.activity import activity
-from sugar.graphics import style
+from sugar3.activity import activity
+from sugar3.graphics import style
from Area import Area
from toolbox import DrawToolbarBox
@@ -85,23 +85,23 @@ class OficinaActivity(activity.Activity):
logging.debug('Starting Paint activity (Oficina)')
- self.fixed = gtk.Fixed()
+ self.fixed = Gtk.Fixed()
self.fixed.show()
- self.fixed.modify_bg(gtk.STATE_NORMAL,
+ self.fixed.modify_bg(Gtk.StateType.NORMAL,
style.COLOR_WHITE.get_gdk_color())
+ self.textview = Gtk.TextView()
+ self.fixed.put(self.textview, 0, 0)
+
# These attributes are used in other classes, so they should be public
self.area = Area(self)
self.area.show()
self.fixed.put(self.area, 0, 0)
- self.textview = gtk.TextView()
- self.fixed.put(self.textview, 0, 0)
-
- sw = gtk.ScrolledWindow()
- sw.show()
- sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- self.set_canvas(sw)
+ self._sw = Gtk.ScrolledWindow()
+ self._sw.show()
+ self._sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
+ self.set_canvas(self._sw)
toolbar_box = DrawToolbarBox(self)
@@ -121,9 +121,9 @@ class OficinaActivity(activity.Activity):
self.canvas.add_with_viewport(self.fixed)
# to remove the border, we need set the shadowtype
# in the viewport child of the scrolledwindow
- self.canvas.get_children()[0].set_shadow_type(gtk.SHADOW_NONE)
+ self.canvas.get_children()[0].set_shadow_type(Gtk.ShadowType.NONE)
self.disconnect(self._setup_handle)
- self._setup_handle = self.fixed.connect('size_allocate',
+ self._setup_handle = self._sw.connect('size_allocate',
size_allocate_cb)
self._setup_handle = self.connect('map', map_cp)
@@ -140,27 +140,30 @@ class OficinaActivity(activity.Activity):
logging.debug('reading file %s, mimetype: %s, title: %s',
file_path, self.metadata['mime_type'], self.metadata['title'])
- pixbuf = gtk.gdk.pixbuf_new_from_file(file_path)
+ self.area.load_from_file(file_path)
def size_allocate_cb(widget, allocation):
+ logging.error('read file size allocate')
self.fixed.disconnect(self._setup_handle)
- self.area.setup(pixbuf.get_width(), pixbuf.get_height())
+ width = self.area.drawing_canvas.get_width()
+ height = self.area.drawing_canvas.get_height()
+ self.area.setup(width, height)
# The scrolled window is confused with a image of the same size
# of the canvas when the toolbars popup and the scrolls
# keep visible.
- if pixbuf.get_height() > allocation.height or \
- pixbuf.get_width() > allocation.width:
- self.canvas.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ if height > allocation.height or width > allocation.width:
+ self.canvas.set_policy(Gtk.PolicyType.AUTOMATIC,
+ Gtk.PolicyType.AUTOMATIC)
else:
- self.canvas.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ self.canvas.set_policy(Gtk.PolicyType.NEVER,
+ Gtk.PolicyType.AUTOMATIC)
- self.area.loadImageFromJournal(pixbuf)
self.center_area()
self.canvas.add_with_viewport(self.fixed)
# to remove the border, we need set the shadowtype
# in the viewport child of the scrolledwindow
- self.canvas.get_children()[0].set_shadow_type(gtk.SHADOW_NONE)
+ self.canvas.get_children()[0].set_shadow_type(Gtk.ShadowType.NONE)
self.canvas.get_children()[0].set_border_width(0)
self.disconnect(self._setup_handle)
@@ -186,20 +189,16 @@ class OficinaActivity(activity.Activity):
self.area.d.text(self.area, event=None)
self.area.getout()
- pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8,
- width, height)
- pixbuf.get_from_drawable(self.area.pixmap,
- gtk.gdk.colormap_get_system(), 0, 0, 0, 0, -1, -1)
+ self.area.drawing_canvas.write_to_png(file_path)
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
+ canvas_width = self.canvas.get_allocation().width
+ canvas_height = self.canvas.get_allocation().height
area_width, area_height = self.area.get_size_request()
# Avoid 'x' and 'y' to be outside the screen