Feedbacks?<br><br><div class="gmail_quote">2012/7/1 Agustin Zubiaga <span dir="ltr"><<a href="mailto:aguz@sugarlabs.org" target="_blank">aguz@sugarlabs.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Signed-off-by: Agustin Zubiaga <<a href="mailto:aguz@sugarlabs.org">aguz@sugarlabs.org</a>><br>
Signed-off-by: Flavio Danesse <<a href="mailto:fdanesse@gmail.com">fdanesse@gmail.com</a>><br>
---<br>
 ImageView.py           |  123 +++++++++++++++++++++++++-----------------------<br>
 ImageViewerActivity.py |   75 ++++++++++++++---------------<br>
 ProgressDialog.py      |   14 +++---<br>
 3 files changed, 108 insertions(+), 104 deletions(-)<br>
<br>
diff --git a/ImageView.py b/ImageView.py<br>
index 538c5b5..39556d7 100644<br>
--- a/ImageView.py<br>
+++ b/ImageView.py<br>
@@ -17,9 +17,11 @@<br>
<br>
 from __future__ import division<br>
<br>
-import gtk<br>
-from gtk import gdk<br>
-import gobject<br>
+from gi.repository import Gtk<br>
+from gi.repository import Gdk<br>
+from gi.repository import GdkPixbuf<br>
+from gi.repository import cairo<br>
+from gi.repository import GObject<br>
<br>
 import sys<br>
 import logging<br>
@@ -27,39 +29,42 @@ import logging<br>
 import random<br>
<br>
<br>
-class ImageViewer(gtk.DrawingArea):<br>
+class ImageViewer(Gtk.DrawingArea):<br>
     __gsignals__ = {<br>
-        'expose-event': (<br>
-            'override'),<br>
+        #'expose-event': (<br>
+        #    'override'),<br>
         'zoom-changed': (<br>
-            gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, []),<br>
+            GObject.SignalFlags.RUN_FIRST, None, []),<br>
         'angle-changed': (<br>
-            gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, []),<br>
+            GObject.SignalFlags.RUN_FIRST, None, []),<br>
         }<br>
<br>
     __gproperties__ = {<br>
         'zoom': (<br>
-            gobject.TYPE_FLOAT, 'Zoom Factor', 'Factor of zoom',<br>
-            0, 4, 1, gobject.PARAM_READWRITE),<br>
+            GObject.TYPE_FLOAT, 'Zoom Factor', 'Factor of zoom',<br>
+            0, 4, 1, GObject.PARAM_READWRITE),<br>
         'angle': (<br>
-            gobject.TYPE_INT, 'Angle', 'Angle of rotation',<br>
-            0, 360, 0, gobject.PARAM_READWRITE),<br>
+            GObject.TYPE_INT, 'Angle', 'Angle of rotation',<br>
+            0, 360, 0, GObject.PARAM_READWRITE),<br>
         'file_location': (<br>
-            gobject.TYPE_STRING, 'File Location', 'Location of the image file',<br>
-            '', gobject.PARAM_READWRITE),<br>
+            GObject.TYPE_STRING, 'File Location', 'Location of the image file',<br>
+            '', GObject.PARAM_READWRITE),<br>
         }<br>
<br>
     def __init__(self):<br>
-        gtk.DrawingArea.__init__(self)<br>
+        GObject.GObject.__init__(self)<br>
         self.set_app_paintable(True)<br>
<br>
         self.pixbuf = None<br>
         self.zoom = None<br>
+        self.parent = None<br>
         self.file_location = None<br>
         self._temp_pixbuf = None<br>
         self._image_changed_flag = True<br>
         self._optimal_zoom_flag = True<br>
<br>
+        self.connect('draw', self.draw)<br>
+<br>
         self.angle = 0<br>
<br>
     def do_get_property(self, pspec):<br>
@@ -90,19 +95,7 @@ class ImageViewer(gtk.DrawingArea):<br>
         if self._optimal_zoom_flag:<br>
             self._set_zoom(self._calc_optimal_zoom())<br>
<br>
-    #def do_size_request(self, requisition):<br>
-    #    requisition.width = self.pixbuf.get_width()<br>
-    #    requisition.height = self.pixbuf.get_height()<br>
-<br>
-    def do_expose_event(self, event):<br>
-        ctx = self.window.cairo_create()<br>
-<br>
-        ctx.rectangle(event.area.x, event.area.y,<br>
-            event.area.width, event.area.height)<br>
-        ctx.clip()<br>
-        self.draw(ctx)<br>
-<br>
-    def draw(self, ctx):<br>
+    def draw(self, widget, ctx):<br>
         if not self.pixbuf:<br>
             return<br>
         if self.zoom is None:<br>
@@ -130,7 +123,7 @@ class ImageViewer(gtk.DrawingArea):<br>
         self.set_size_request(self._temp_pixbuf.get_width(),<br>
                 self._temp_pixbuf.get_height())<br>
<br>
-        ctx.set_source_pixbuf(self._temp_pixbuf, x, y)<br>
+        Gdk.cairo_set_source_pixbuf(ctx, self._temp_pixbuf, x, y)<br>
<br>
         ctx.paint()<br>
<br>
@@ -144,12 +137,15 @@ class ImageViewer(gtk.DrawingArea):<br>
<br>
         self.angle = angle<br>
<br>
-        if self.window:<br>
+        if self.props.window:<br>
             alloc = self.get_allocation()<br>
-            rect = gdk.Rectangle(alloc.x, alloc.y,<br>
-                alloc.width, alloc.height)<br>
-            self.window.invalidate_rect(rect, True)<br>
-            self.window.process_updates(True)<br>
+            rect = cairo.RectangleInt()<br>
+            rect.x = alloc.x<br>
+            rect.y = alloc.y<br>
+            rect.width = alloc.width<br>
+            rect.height = alloc.height<br>
+            self.props.window.invalidate_rect(rect, True)<br>
+            self.props.window.process_updates(True)<br>
<br>
         self.emit('angle-changed')<br>
<br>
@@ -168,24 +164,27 @@ class ImageViewer(gtk.DrawingArea):<br>
             return True<br>
<br>
     def set_file_location(self, file_location):<br>
-        self.pixbuf = gtk.gdk.pixbuf_new_from_file(file_location)<br>
+        self.pixbuf = GdkPixbuf.Pixbuf.new_from_file(file_location)<br>
         self.file_location = file_location<br>
         self.zoom = None<br>
         self._image_changed_flag = True<br>
<br>
-        if self.window:<br>
+        if self.props.window:<br>
             alloc = self.get_allocation()<br>
-            rect = gdk.Rectangle(alloc.x, alloc.y,<br>
-                alloc.width, alloc.height)<br>
-            self.window.invalidate_rect(rect, True)<br>
-            self.window.process_updates(True)<br>
+            rect = cairo.RectangleInt()<br>
+            rect.x = alloc.x<br>
+            rect.y = alloc.y<br>
+            rect.width = alloc.width<br>
+            rect.height = alloc.height<br>
+            self.props.window.invalidate_rect(rect, True)<br>
+            self.props.window.process_updates(True)<br>
<br>
     def _calc_optimal_zoom(self):<br>
         # This tries to figure out a best fit model<br>
         # If the image can fit in, we show it in 1:1,<br>
         # in any other case we show it in a fit to screen way<br>
<br>
-        if isinstance(self.parent, gtk.Viewport):<br>
+        if isinstance(self.parent, Gtk.Viewport):<br>
             rect = self.parent.parent.get_allocation()<br>
         else:<br>
             rect = self.parent.get_allocation()<br>
@@ -206,37 +205,41 @@ class ImageViewer(gtk.DrawingArea):<br>
         self._image_changed_flag = True<br>
         self.zoom = zoom<br>
<br>
-        if self.window:<br>
+        if self.props.window:<br>
             alloc = self.get_allocation()<br>
-            rect = gdk.Rectangle(alloc.x, alloc.y,<br>
-                alloc.width, alloc.height)<br>
-            self.window.invalidate_rect(rect, True)<br>
-            self.window.process_updates(True)<br>
+            rect = cairo.RectangleInt()<br>
+            rect.x = alloc.x<br>
+            rect.y = alloc.y<br>
+            rect.width = alloc.width<br>
+            rect.height = alloc.height<br>
+            self.props.window.invalidate_rect(rect, True)<br>
+            self.props.window.process_updates(True)<br>
<br>
         self.emit('zoom-changed')<br>
<br>
     def _convert_pixbuf(self, pixbuf):<br>
         if self.angle == 0:<br>
-            rotate = gtk.gdk.PIXBUF_ROTATE_NONE<br>
+            rotate = GdkPixbuf.PixbufRotation.NONE<br>
         elif self.angle == 90:<br>
-            rotate = gtk.gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE<br>
+            rotate = GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE<br>
         elif self.angle == 180:<br>
-            rotate = gtk.gdk.PIXBUF_ROTATE_UPSIDEDOWN<br>
+            rotate = GdkPixbuf.PixbufRotation.UPSIDEDOWN<br>
         elif self.angle == 270:<br>
-            rotate = gtk.gdk.PIXBUF_ROTATE_CLOCKWISE<br>
+            rotate = GdkPixbuf.PixbufRotation.CLOCKWISE<br>
         elif self.angle == 360:<br>
             self.angle = 0<br>
-            rotate = gtk.gdk.PIXBUF_ROTATE_NONE<br>
+            rotate = GdkPixbuf.PixbufRotation.NONE<br>
         else:<br>
             logging.warning('Got unsupported rotate angle')<br>
<br>
-        if rotate != gtk.gdk.PIXBUF_ROTATE_NONE:<br>
+        if rotate != GdkPixbuf.PixbufRotation.NONE:<br>
             pixbuf = pixbuf.rotate_simple(rotate)<br>
<br>
         if self.zoom != 1:<br>
             width = int(pixbuf.get_width() * self.zoom)<br>
             height = int(pixbuf.get_height() * self.zoom)<br>
-            pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_TILES)<br>
+            pixbuf = pixbuf.scale_simple(width, height,<br>
+                                         GdkPixbuf.InterpType.TILES)<br>
<br>
         return pixbuf<br>
<br>
@@ -250,18 +253,18 @@ def update(view_object):<br>
<br>
<br>
 if __name__ == '__main__':<br>
-    window = gtk.Window()<br>
+    window = Gtk.Window()<br>
<br>
-    vadj = gtk.Adjustment()<br>
-    hadj = gtk.Adjustment()<br>
-    sw = gtk.ScrolledWindow(hadj, vadj)<br>
+    vadj = Gtk.Adjustment()<br>
+    hadj = Gtk.Adjustment()<br>
+    sw = Gtk.ScrolledWindow(hadj, vadj)<br>
<br>
     view = ImageViewer()<br>
<br>
     view.set_file_location(sys.argv[1])<br>
<br>
<br>
-    sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)<br>
+    sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)<br>
<br>
<br>
     sw.add_with_viewport(view)<br>
@@ -271,6 +274,6 @@ if __name__ == '__main__':<br>
<br>
     window.show_all()<br>
<br>
-    gobject.timeout_add(1000, update, view)<br>
+    GObject.timeout_add(1000, update, view)<br>
<br>
-    gtk.main()<br>
+    Gtk.main()<br>
diff --git a/ImageViewerActivity.py b/ImageViewerActivity.py<br>
index 2391dfd..c35829b 100644<br>
--- a/ImageViewerActivity.py<br>
+++ b/ImageViewerActivity.py<br>
@@ -19,26 +19,26 @@<br>
<br>
 from __future__ import division<br>
<br>
-from sugar.activity import activity<br>
+from sugar3.activity import activity<br>
 import logging<br>
<br>
 from gettext import gettext as _<br>
<br>
 import time<br>
 import os<br>
-import gtk<br>
-import gobject<br>
-<br>
-from sugar.graphics.alert import NotifyAlert<br>
-from sugar.graphics.objectchooser import ObjectChooser<br>
-from sugar import mime<br>
-from sugar.graphics.toolbutton import ToolButton<br>
-from sugar.graphics.toolbarbox import ToolbarBox<br>
-from sugar.activity.widgets import ActivityToolbarButton<br>
-from sugar.activity.widgets import StopButton<br>
-<br>
-from sugar import network<br>
-from sugar.datastore import datastore<br>
+from gi.repository import Gtk<br>
+from gi.repository import GObject<br>
+<br>
+from sugar3.graphics.alert import NotifyAlert<br>
+from sugar3.graphics.objectchooser import ObjectChooser<br>
+from sugar3 import mime<br>
+from sugar3.graphics.toolbutton import ToolButton<br>
+from sugar3.graphics.toolbarbox import ToolbarBox<br>
+from sugar3.activity.widgets import ActivityToolbarButton<br>
+from sugar3.activity.widgets import StopButton<br>
+<br>
+from sugar3 import network<br>
+from sugar3.datastore import datastore<br>
 import telepathy<br>
 import dbus<br>
<br>
@@ -113,14 +113,15 @@ class ImageViewerActivity(activity.Activity):<br>
         self.set_toolbar_box(toolbar_box)<br>
         toolbar_box.show()<br>
<br>
-        vadj = gtk.Adjustment()<br>
-        hadj = gtk.Adjustment()<br>
-        self.sw = gtk.ScrolledWindow(hadj, vadj)<br>
+        vadj = Gtk.Adjustment()<br>
+        hadj = Gtk.Adjustment()<br>
+        self.sw = Gtk.ScrolledWindow(hadj, vadj)<br>
+        self.view.parent = self.sw<br>
<br>
-        self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)<br>
+        self.sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)<br>
         self.sw.add_with_viewport(self.view)<br>
         # Avoid needless spacing<br>
-        self.view.parent.props.shadow_type = gtk.SHADOW_NONE<br>
+        self.view.parent.props.shadow_type = Gtk.ShadowType.NONE<br>
<br>
         self.set_canvas(self.sw)<br>
         self.sw.show_all()<br>
@@ -138,7 +139,7 @@ class ImageViewerActivity(activity.Activity):<br>
<br>
         self.is_received_document = False<br>
<br>
-        if self._shared_activity and handle.object_id == None:<br>
+        if self.shared_activity and handle.object_id == None:<br>
             # We're joining, and we don't already have the document.<br>
             if self.get_shared():<br>
                 # Already joined for some reason, just get the document<br>
@@ -147,7 +148,7 @@ class ImageViewerActivity(activity.Activity):<br>
                 # Wait for a successful join before trying to get the document<br>
                 self.connect("joined", self._joined_cb)<br>
         elif self._object_id is None:<br>
-            self._show_object_picker = gobject.timeout_add(1000, \<br>
+            self._show_object_picker = GObject.timeout_add(1000, \<br>
                 self._show_picker_cb)<br>
<br>
     def handle_view_source(self):<br>
@@ -190,7 +191,7 @@ class ImageViewerActivity(activity.Activity):<br>
         toolbar_box.toolbar.insert(zoom_original_button, -1)<br>
         zoom_original_button.show()<br>
<br>
-        spacer = gtk.SeparatorToolItem()<br>
+        spacer = Gtk.SeparatorToolItem()<br>
         spacer.props.draw = False<br>
         toolbar_box.toolbar.insert(spacer, -1)<br>
         spacer.show()<br>
@@ -208,7 +209,7 @@ class ImageViewerActivity(activity.Activity):<br>
         toolbar_box.toolbar.insert(rotate_clockwise_button, -1)<br>
         rotate_clockwise_button.show()<br>
<br>
-        spacer = gtk.SeparatorToolItem()<br>
+        spacer = Gtk.SeparatorToolItem()<br>
         spacer.props.draw = False<br>
         toolbar_box.toolbar.insert(spacer, -1)<br>
         spacer.show()<br>
@@ -219,7 +220,7 @@ class ImageViewerActivity(activity.Activity):<br>
         toolbar_box.toolbar.insert(fullscreen_button, -1)<br>
         fullscreen_button.show()<br>
<br>
-        separator = gtk.SeparatorToolItem()<br>
+        separator = Gtk.SeparatorToolItem()<br>
         separator.props.draw = False<br>
         separator.set_expand(True)<br>
         toolbar_box.toolbar.insert(separator, -1)<br>
@@ -262,13 +263,13 @@ class ImageViewerActivity(activity.Activity):<br>
             return<br>
<br>
         chooser = ObjectChooser(_('Choose document'), self,<br>
-            gtk.DIALOG_MODAL |<br>
-            gtk.DIALOG_DESTROY_WITH_PARENT, \<br>
+            Gtk.DialogFlags.MODAL |<br>
+            Gtk.DialogFlags.DESTROY_WITH_PARENT, \<br>
             what_filter=mime.GENERIC_TYPE_IMAGE)<br>
<br>
         try:<br>
             result = chooser.run()<br>
-            if result == gtk.RESPONSE_ACCEPT:<br>
+            if result == Gtk.ResponseType.ACCEPT:<br>
                 jobject = chooser.get_selected_object()<br>
                 if jobject and jobject.file_path:<br>
                     self.read_file(jobject.file_path)<br>
@@ -284,7 +285,7 @@ class ImageViewerActivity(activity.Activity):<br>
<br>
         os.link(file_path, tempfile)<br>
         self._tempfile = tempfile<br>
-        gobject.idle_add(self.__set_file_idle_cb, tempfile)<br>
+        GObject.idle_add(self.__set_file_idle_cb, tempfile)<br>
<br>
     def __set_file_idle_cb(self, file_path):<br>
         self.view.set_file_location(file_path)<br>
@@ -335,7 +336,7 @@ class ImageViewerActivity(activity.Activity):<br>
<br>
         self.progressdialog.destroy()<br>
<br>
-        gobject.idle_add(self.__set_file_idle_cb, tempfile)<br>
+        GObject.idle_add(self.__set_file_idle_cb, tempfile)<br>
         self.save()<br>
<br>
     def _download_progress_cb(self, getter, bytes_downloaded, tube_id):<br>
@@ -351,7 +352,7 @@ class ImageViewerActivity(activity.Activity):<br>
         fraction = bytes_downloaded / total<br>
         self.progressdialog.set_fraction(fraction)<br>
<br>
-        #gtk.main_iteration()<br>
+        #Gtk.main_iteration()<br>
<br>
     def _download_error_cb(self, getter, err, tube_id):<br>
         _logger.debug("Error getting document from tube %u: %s",<br>
@@ -360,12 +361,12 @@ class ImageViewerActivity(activity.Activity):<br>
         self._want_document = True<br>
         self._download_content_length = 0<br>
         self._download_content_type = None<br>
-        gobject.idle_add(self._get_document)<br>
+        GObject.idle_add(self._get_document)<br>
<br>
     def _download_document(self, tube_id, path):<br>
         # FIXME: should ideally have the CM listen on a Unix socket<br>
         # instead of IPv4 (might be more compatible with Rainbow)<br>
-        chan = self._shared_activity.telepathy_tubes_chan<br>
+        chan = self.shared_activity.telepathy_tubes_chan<br>
         iface = chan[telepathy.CHANNEL_TYPE_TUBES]<br>
         addr = iface.AcceptStreamTube(tube_id,<br>
                 telepathy.SOCKET_ADDRESS_TYPE_IPV4,<br>
@@ -413,7 +414,7 @@ class ImageViewerActivity(activity.Activity):<br>
<br>
         # Avoid trying to download the document multiple times at once<br>
         self._want_document = False<br>
-        gobject.idle_add(self._download_document, tube_id, path)<br>
+        GObject.idle_add(self._download_document, tube_id, path)<br>
         return False<br>
<br>
     def _joined_cb(self, also_self):<br>
@@ -426,7 +427,7 @@ class ImageViewerActivity(activity.Activity):<br>
         self.progressdialog = ProgressDialog.ProgressDialog(self)<br>
         self.progressdialog.show_all()<br>
<br>
-        gobject.idle_add(self._get_document)<br>
+        GObject.idle_add(self._get_document)<br>
<br>
     def _share_document(self):<br>
         """Share the document."""<br>
@@ -438,7 +439,7 @@ class ImageViewerActivity(activity.Activity):<br>
             self._tempfile)<br>
<br>
         # Make a tube for it<br>
-        chan = self._shared_activity.telepathy_tubes_chan<br>
+        chan = self.shared_activity.telepathy_tubes_chan<br>
         iface = chan[telepathy.CHANNEL_TYPE_TUBES]<br>
         self._fileserver_tube_id = \<br>
                 iface.OfferStreamTube(IMAGEVIEWER_STREAM_SERVICE,<br>
@@ -449,7 +450,7 @@ class ImageViewerActivity(activity.Activity):<br>
<br>
     def watch_for_tubes(self):<br>
         """Watch for new tubes."""<br>
-        tubes_chan = self._shared_activity.telepathy_tubes_chan<br>
+        tubes_chan = self.shared_activity.telepathy_tubes_chan<br>
<br>
         tubes_chan[telepathy.CHANNEL_TYPE_TUBES].connect_to_signal('NewTube',<br>
             self._new_tube_cb)<br>
@@ -468,7 +469,7 @@ class ImageViewerActivity(activity.Activity):<br>
             self.unused_download_tubes.add(tube_id)<br>
             # if no download is in progress, let's fetch the document<br>
             if self._want_document:<br>
-                gobject.idle_add(self._get_document)<br>
+                GObject.idle_add(self._get_document)<br>
<br>
     def _list_tubes_reply_cb(self, tubes):<br>
         """Callback when new tubes are available."""<br>
diff --git a/ProgressDialog.py b/ProgressDialog.py<br>
index a46bae3..aa9cea8 100644<br>
--- a/ProgressDialog.py<br>
+++ b/ProgressDialog.py<br>
@@ -1,24 +1,24 @@<br>
-import gtk<br>
+from gi.repository import Gtk<br>
 from gettext import gettext as _<br>
<br>
<br>
-class ProgressDialog(gtk.Dialog):<br>
+class ProgressDialog(Gtk.Dialog):<br>
<br>
     def __init__(self, parent):<br>
-        gtk.Dialog.__init__(self, _('Downloading...'), parent, \<br>
-                gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \<br>
-                (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))<br>
+        GObject.GObject.__init__(self, _('Downloading...'), parent, \<br>
+                Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, \<br>
+                (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT))<br>
<br>
         self._activity = parent<br>
<br>
         self.connect('response', self._response_cb)<br>
<br>
-        self._pb = gtk.ProgressBar()<br>
+        self._pb = Gtk.ProgressBar()<br>
         self._pb.set_text(_('Retrieving shared image, please wait...'))<br>
         self.vbox.add(self._pb)<br>
<br>
     def _response_cb(self, dialog, response_id):<br>
-        if response_id == gtk.RESPONSE_REJECT:<br>
+        if response_id == Gtk.ResponseType.REJECT:<br>
             self._activity.close()<br>
         else:<br>
             pass<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.10.2<br>
<br>
</font></span></blockquote></div><br><br clear="all"><br>-- <br><img src="https://lh3.googleusercontent.com/wx48FqQfbwg6DcUZL0ey4HpG6bX0GMyl1VWk_JJdi21Hgonb24D3lJCKSqn1iYq4sJnxbWDh8cwLnPtfg-UV8XuXXw" height="50" width="141"><br>
<br>