diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2010-12-22 05:23:14 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2010-12-22 05:23:14 (GMT) |
commit | 48c78884cac8b2b7ef863482ca3dba468fee4e20 (patch) | |
tree | 8f1e50addc2672bb1913739aa3bc30082c120774 | |
parent | 80d67125b39ec911eb349c1cab9d23175c226a3e (diff) |
Apply sugar-lint fixes; add HACKING file; make it useful under sweets
-rw-r--r-- | AUTHORS | 21 | ||||
-rw-r--r-- | HACKING | 29 | ||||
-rw-r--r-- | ImageView.py | 105 | ||||
-rw-r--r-- | ImageViewerActivity.py | 65 | ||||
-rw-r--r-- | ProgressDialog.py | 5 | ||||
-rw-r--r-- | activity/activity.info | 25 | ||||
-rwxr-xr-x | setup.py | 1 |
7 files changed, 159 insertions, 92 deletions
@@ -1 +1,22 @@ +Contributors +============ +Aleksey Lim <alsroot@member.fsf.org> +Bastien <bastienguerry@googlemail.com> +Carlo Falciola <cfalciola@yahoo.it> +Clytie Siddall <clytie@riverland.net.au> +Eduardo H. Silva <HoboPrimate@gmail.com> +Gary C Martin <gary@garycmartin.com> +Khaled Hosny <khaledhosny@eglug.org> +korakurider <korakurider@gmail.com> +Markus Schlager <m.slg@gmx.de> +Myckel Habets <myckel@sdf.lonestar.org> +Odontsetseg Bat-Erdene <obat-erdene@suffolk.edu> +samy boutayeb <s.boutayeb@free.fr> +Sayamindu Dasgupta <sayamindu@gmail.com> +Simon Schampijer <simon@schampijer.de> +Tomeu Vizoso <tomeu.vizoso@collabora.co.uk> + +Maintainers +----------- Sayamindu Dasgupta <sayamindu@laptop.org> +Aleksey Lim <alsroot@member.fsf.org> @@ -0,0 +1,29 @@ +How to contribute +================= + +Useful notes how to contribute to the project. + +Before committing +----------------- +All source files need to be passed through `sugar-lint`_ command. +Follow sugar-lint home page instructions and especially +`"Lint files before committing"` section. + +Send patches +------------ +Create your patches using ``git format`` command and send them to all +maintainers from the :ref:`AUTHORS <AUTHORS>` file. The easiest way it just +using ``git send-email`` command. Patches might be CCed to +sugar-devel@lists.sugarlabs.org to attract more people to review. + +Gitorious forks +--------------- +Another useful way to contribute, especially for big improvements, is creating +Gitorious forks and request them for merge to the trunk. + +* http://blog.gitorious.org/2009/05/09/weve-made-a-few-changes/ + (see `"Merge requests"` topic) +* http://blog.gitorious.org/2009/07/15/new-merge-request-functionality/ +* http://blog.gitorious.org/2009/11/06/awesome-code-review/ + +.. _sugar-lint: http://wiki.sugarlabs.org/go/Platform_Team/Sugar_Lint diff --git a/ImageView.py b/ImageView.py index bdaa458..356b794 100644 --- a/ImageView.py +++ b/ImageView.py @@ -19,7 +19,6 @@ from __future__ import division import gtk from gtk import gdk -import cairo import gobject import sys @@ -27,28 +26,28 @@ import logging import random + class ImageViewer(gtk.DrawingArea): __gsignals__ = { - 'expose-event': 'override', - 'zoom-changed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ([])), - 'angle-changed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ([])) - } + 'expose-event': ( + 'override'), + 'zoom-changed': ( + gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, []), + 'angle-changed': ( + gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, []), + } __gproperties__ = { - 'zoom': (gobject.TYPE_FLOAT, - 'Zoom Factor', 'Factor of zoom', + 'zoom': ( + gobject.TYPE_FLOAT, 'Zoom Factor', 'Factor of zoom', 0, 4, 1, gobject.PARAM_READWRITE), - 'angle': (gobject.TYPE_INT, - 'Angle', 'Angle of rotation', + 'angle': ( + gobject.TYPE_INT, 'Angle', 'Angle of rotation', 0, 360, 0, gobject.PARAM_READWRITE), - 'file_location': (gobject.TYPE_STRING, - 'File Location', 'Location of the image file', - '', gobject.PARAM_READWRITE) - } + 'file_location': ( + gobject.TYPE_STRING, 'File Location', 'Location of the image file', + '', gobject.PARAM_READWRITE), + } def __init__(self): gtk.DrawingArea.__init__(self) @@ -63,43 +62,43 @@ class ImageViewer(gtk.DrawingArea): self.angle = 0 - - def do_get_property(self, property): - if property.name == 'zoom': + def do_get_property(self, pspec): + if pspec.name == 'zoom': return self.zoom - elif property.name == 'angle': + elif pspec.name == 'angle': return self.angle - elif property.name == 'file_location': + elif pspec.name == 'file_location': return self.file_location else: - raise AttributeError, 'unknown property %s' % property.name + raise AttributeError('unknown property %s' % pspec.name) - def do_set_property(self, property, value): - if property.name == 'zoom': + def do_set_property(self, pspec, value): + if pspec.name == 'zoom': self.set_zoom(value) - elif property.name == 'angle': + elif pspec.name == 'angle': self.set_angle(value) - elif property.name == 'file_location': + elif pspec.name == 'file_location': self.set_file_location(value) else: - raise AttributeError, 'unknown property %s' % property.name + raise AttributeError('unknown property %s' % pspec.name) - def calculate_optimal_zoom(self, width = None, height = None, pixbuf = None): + def calculate_optimal_zoom(self, width=None, height=None, pixbuf=None): # This tries to figure out a best fit model - # If the image can fit in, we show it in 1:1, + # If the image can fit in, we show it in 1:1, # in any other case we show it in a fit to screen way if pixbuf == None: pixbuf = self.pixbuf if width == None or height == None: - rect = self.parent.get_allocation() + rect = self.parent.get_allocation() width = rect.width height = rect.height if width < pixbuf.get_width() or height < pixbuf.get_height(): # Image is larger than allocated size - zoom = min(width/pixbuf.get_width(), height/pixbuf.get_height()) + zoom = min(width / pixbuf.get_width(), + height / pixbuf.get_height()) else: zoom = 1 @@ -114,7 +113,7 @@ class ImageViewer(gtk.DrawingArea): def do_expose_event(self, event): ctx = self.window.cairo_create() - ctx.rectangle(event.area.x, event.area.y, + ctx.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) ctx.clip() self.draw(ctx) @@ -124,10 +123,11 @@ class ImageViewer(gtk.DrawingArea): return if self.zoom == None: self.zoom = self.calculate_optimal_zoom() - + if self._temp_pixbuf == None or self._image_changed_flag == True: width, height = self.rotate() - self._temp_pixbuf = self._temp_pixbuf.scale_simple(width, height, gtk.gdk.INTERP_TILES) + self._temp_pixbuf = self._temp_pixbuf.scale_simple( + width, height, gtk.gdk.INTERP_TILES) self._image_changed_flag = False rect = self.get_allocation() @@ -140,18 +140,18 @@ class ImageViewer(gtk.DrawingArea): if self.parent: rect = self.parent.get_allocation() if rect.width > width: - x = int(((rect.width - x) - width)/2) + x = int(((rect.width - x) - width) / 2) if rect.height > height: - y = int(((rect.height - y) - height)/2) + y = int(((rect.height - y) - height) / 2) - self.set_size_request(self._temp_pixbuf.get_width(),self._temp_pixbuf.get_height()) + self.set_size_request(self._temp_pixbuf.get_width(), + self._temp_pixbuf.get_height()) ctx.set_source_pixbuf(self._temp_pixbuf, x, y) ctx.paint() - def set_zoom(self, zoom): self._image_changed_flag = True self._optimal_zoom_flag = False @@ -159,7 +159,7 @@ class ImageViewer(gtk.DrawingArea): if self.window: alloc = self.get_allocation() - rect = gdk.Rectangle(alloc.x, alloc.y, + rect = gdk.Rectangle(alloc.x, alloc.y, alloc.width, alloc.height) self.window.invalidate_rect(rect, True) self.window.process_updates(True) @@ -181,8 +181,6 @@ class ImageViewer(gtk.DrawingArea): self.emit('angle-changed') - - def rotate(self): if self.angle == 0: rotate = gtk.gdk.PIXBUF_ROTATE_NONE @@ -197,14 +195,13 @@ class ImageViewer(gtk.DrawingArea): rotate = gtk.gdk.PIXBUF_ROTATE_NONE else: logging.warning('Got unsupported rotate angle') - pass - + self._temp_pixbuf = self.pixbuf.rotate_simple(rotate) if self._optimal_zoom_flag == True: - self.zoom = self.calculate_optimal_zoom(pixbuf = self._temp_pixbuf) - - width = int(self._temp_pixbuf.get_width()*self.zoom) - height = int(self._temp_pixbuf.get_height()*self.zoom) + self.zoom = self.calculate_optimal_zoom(pixbuf=self._temp_pixbuf) + + width = int(self._temp_pixbuf.get_width() * self.zoom) + height = int(self._temp_pixbuf.get_height() * self.zoom) return (width, height) @@ -236,15 +233,14 @@ class ImageViewer(gtk.DrawingArea): self.window.process_updates(True) -def update(view): - #return view.zoom_out() - angle = 90 * random.randint(0,4) - view.set_angle(angle) +def update(view_object): + #return view_object.zoom_out() + angle = 90 * random.randint(0, 4) + view_object.set_angle(angle) return True - if __name__ == '__main__': window = gtk.Window() @@ -263,11 +259,10 @@ if __name__ == '__main__': sw.add_with_viewport(view) window.add(sw) - window.set_size_request(800,600) + window.set_size_request(800, 600) window.show_all() gobject.timeout_add(1000, update, view) gtk.main() - diff --git a/ImageViewerActivity.py b/ImageViewerActivity.py index 4a10bcb..e6f9bc3 100644 --- a/ImageViewerActivity.py +++ b/ImageViewerActivity.py @@ -25,18 +25,17 @@ import logging from gettext import gettext as _ import time -import sys, os -import gtk, gobject +import os +import gtk +import gobject from sugar.graphics.alert import NotifyAlert from sugar.graphics.objectchooser import ObjectChooser from sugar import mime from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toolbarbox import ToolbarBox -from sugar.graphics.toolbarbox import ToolbarButton from sugar.activity.widgets import ActivityToolbarButton from sugar.activity.widgets import StopButton -from sugar.activity import activity from sugar import network from sugar.datastore import datastore @@ -48,6 +47,7 @@ import ProgressDialog _logger = logging.getLogger('imageviewer-activity') + class ImageViewerHTTPRequestHandler(network.ChunkedGlibHTTPRequestHandler): """HTTP Request Handler for transferring document while collaborating. @@ -56,6 +56,7 @@ class ImageViewerHTTPRequestHandler(network.ChunkedGlibHTTPRequestHandler): mainloop between chunks. """ + def translate_path(self, path): """Return the filepath to the shared document.""" return self.server.filepath @@ -63,6 +64,7 @@ class ImageViewerHTTPRequestHandler(network.ChunkedGlibHTTPRequestHandler): class ImageViewerHTTPServer(network.GlibTCPServer): """HTTP Server for transferring document while collaborating.""" + def __init__(self, server_address, filepath): """Set up the GlibTCPServer with the ImageViewerHTTPRequestHandler. @@ -91,12 +93,19 @@ IMAGEVIEWER_STREAM_SERVICE = 'imageviewer-activity-http' class ImageViewerActivity(activity.Activity): + def __init__(self, handle): activity.Activity.__init__(self, handle) self.zoom = None self._object_id = handle.object_id + self._zoom_out_button = None + self._zoom_in_button = None + self._old_zoom = None + self._fileserver = None + self._fileserver_tube_id = None + self.view = ImageView.ImageViewer() self.progressdialog = None @@ -105,8 +114,7 @@ class ImageViewerActivity(activity.Activity): self.set_toolbar_box(toolbar_box) toolbar_box.show() - self.connect('window-state-event', - self.__window_state_event_cb) + self.connect('window-state-event', self.__window_state_event_cb) vadj = gtk.Adjustment() hadj = gtk.Adjustment() @@ -129,7 +137,7 @@ class ImageViewerActivity(activity.Activity): self.port = 1024 + (h % 64511) self.is_received_document = False - + if self._shared_activity and handle.object_id == None: # We're joining, and we don't already have the document. if self.get_shared(): @@ -142,6 +150,9 @@ class ImageViewerActivity(activity.Activity): self._show_object_picker = gobject.timeout_add(1000, \ self._show_picker_cb) + def handle_view_source(self): + pass + def _add_toolbar_buttons(self, toolbar_box): activity_button = ActivityToolbarButton(self) toolbar_box.toolbar.insert(activity_button, 0) @@ -164,7 +175,7 @@ class ImageViewerActivity(activity.Activity): zoom_tofit_button.connect('clicked', self.__zoom_tofit_cb) toolbar_box.toolbar.insert(zoom_tofit_button, -1) zoom_tofit_button.show() - + zoom_original_button = ToolButton('zoom-original') zoom_original_button.set_tooltip(_('Original size')) zoom_original_button.connect('clicked', self.__zoom_original_cb) @@ -178,7 +189,8 @@ class ImageViewerActivity(activity.Activity): rotate_anticlockwise_button = ToolButton('rotate_anticlockwise') rotate_anticlockwise_button.set_tooltip(_('Rotate anticlockwise')) - rotate_anticlockwise_button.connect('clicked', self.__rotate_anticlockwise_cb) + rotate_anticlockwise_button.connect('clicked', + self.__rotate_anticlockwise_cb) toolbar_box.toolbar.insert(rotate_anticlockwise_button, -1) rotate_anticlockwise_button.show() @@ -192,7 +204,7 @@ class ImageViewerActivity(activity.Activity): spacer.props.draw = False toolbar_box.toolbar.insert(spacer, -1) spacer.show() - + fullscreen_button = ToolButton('view-fullscreen') fullscreen_button.set_tooltip(_('Fullscreen')) fullscreen_button.connect('clicked', self.__fullscreen_cb) @@ -220,28 +232,29 @@ class ImageViewerActivity(activity.Activity): def __zoom_tofit_cb(self, button): zoom = self.view.calculate_optimal_zoom() self.view.set_zoom(zoom) - + def __zoom_original_cb(self, button): self.view.set_zoom(1) def __rotate_anticlockwise_cb(self, button): angle = self.view.get_property('angle') self.view.set_angle(angle + 90) - + def __rotate_clockwise_cb(self, button): angle = self.view.get_property('angle') if angle == 0: angle = 360 - self.view.set_angle(angle - 90) - + self.view.set_angle(angle - 90) + def __fullscreen_cb(self, button): self._old_zoom = self.view.get_property('zoom') #XXX: Hack # Zoom to fit screen if possible screen = self.get_screen() - zoom = self.view.calculate_optimal_zoom(screen.get_width(), screen.get_height()) + zoom = self.view.calculate_optimal_zoom( + screen.get_width(), screen.get_height()) self.view.set_zoom(zoom) - + self.fullscreen() def _show_picker_cb(self): @@ -268,19 +281,19 @@ class ImageViewerActivity(activity.Activity): tempfile = os.path.join(self.get_activity_root(), 'instance', \ 'tmp%i' % time.time()) - + os.link(file_path, tempfile) self._tempfile = tempfile gobject.idle_add(self.__set_file_idle_cb, tempfile) def __set_file_idle_cb(self, file_path): self.view.set_file_location(file_path) - + try: self.zoom = int(self.metadata.get('zoom', '0')) if self.zoom > 0: self.view.set_zoom(self.zoom) - except: + except Exception: pass return False @@ -333,16 +346,16 @@ class ImageViewerActivity(activity.Activity): def _download_progress_cb(self, getter, bytes_downloaded, tube_id): if self._download_content_length > 0: _logger.debug("Downloaded %u of %u bytes from tube %u...", - bytes_downloaded, self._download_content_length, + bytes_downloaded, self._download_content_length, tube_id) else: _logger.debug("Downloaded %u bytes from tube %u...", bytes_downloaded, tube_id) total = self._download_content_length - fraction = bytes_downloaded/total + fraction = bytes_downloaded / total self.progressdialog.set_fraction(fraction) - + #gtk.main_iteration() def _download_error_cb(self, getter, err, tube_id): @@ -414,7 +427,7 @@ class ImageViewerActivity(activity.Activity): Get the shared document from another participant. """ self.watch_for_tubes() - + self.progressdialog = ProgressDialog.ProgressDialog(self) self.progressdialog.show_all() @@ -432,7 +445,8 @@ class ImageViewerActivity(activity.Activity): # Make a tube for it chan = self._shared_activity.telepathy_tubes_chan iface = chan[telepathy.CHANNEL_TYPE_TUBES] - self._fileserver_tube_id = iface.OfferStreamTube(IMAGEVIEWER_STREAM_SERVICE, + self._fileserver_tube_id = \ + iface.OfferStreamTube(IMAGEVIEWER_STREAM_SERVICE, {}, telepathy.SOCKET_ADDRESS_TYPE_IPV4, ('127.0.0.1', dbus.UInt16(self.port)), @@ -469,7 +483,7 @@ class ImageViewerActivity(activity.Activity): def _list_tubes_error_cb(self, e): """Handle ListTubes error by logging.""" _logger.error('ListTubes() failed: %s', e) - + def _shared_cb(self, activityid): """Callback when activity shared. @@ -492,4 +506,3 @@ class ImageViewerActivity(activity.Activity): def _alert_cancel_cb(self, alert, response_id): self.remove_alert(alert) - diff --git a/ProgressDialog.py b/ProgressDialog.py index bf92502..a46bae3 100644 --- a/ProgressDialog.py +++ b/ProgressDialog.py @@ -1,7 +1,9 @@ import gtk from gettext import gettext as _ + class ProgressDialog(gtk.Dialog): + def __init__(self, parent): gtk.Dialog.__init__(self, _('Downloading...'), parent, \ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \ @@ -20,7 +22,6 @@ class ProgressDialog(gtk.Dialog): self._activity.close() else: pass - + def set_fraction(self, fraction): self._pb.set_fraction(fraction) - diff --git a/activity/activity.info b/activity/activity.info index 29c4c80..7563a87 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,10 +1,19 @@ [Activity] -name = Image Viewer +sweet = imageviewer +name = Image Viewer +summary = The Image Viewer activity is a simple and fast image viewer tool +description = It has features one would expect of a standard image viewer, + like zoom, rotate, etc. +homepage = http://wiki.sugarlabs.org/go/Activities/Image_Viewer +license = GPLv2+ + +icon = activity-imageviewer +exec = sugar-activity ImageViewerActivity.ImageViewerActivity +mime_types = image/bmp;image/gif;image/jpeg;image/png;image/tiff;image/svg+xml + +version = 15 +stability = testing + +# support original activity.info fields +activity_version = %(version)s bundle_id = org.laptop.ImageViewerActivity -class = ImageViewerActivity.ImageViewerActivity -icon = activity-imageviewer -activity_version = 15 -host_version = 14 -show_launcher = no -mime_types = image/bmp;image/gif;image/jpeg;image/png;image/tiff -license = GPLv2+ @@ -3,4 +3,3 @@ from sugar.activity import bundlebuilder bundlebuilder.start() - |