diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2013-09-04 19:52:11 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguz@sugarlabs.org> | 2013-09-10 00:17:56 (GMT) |
commit | 3f33cb3c480bf50e2f442e721644cf07c415f79b (patch) | |
tree | 205e7bbc5ebb17a0fe7e532b3750779d249456d6 | |
parent | 30f24a8427c79983e66ff936510b4da9ef7be4ac (diff) |
Replace the gtk dialog used to show transferece progress by a Alert
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Signed-off-by: Agustin Zubiaga <aguz@sugarlabs.org>
-rw-r--r-- | ImageViewerActivity.py | 45 | ||||
-rw-r--r-- | ProgressDialog.py | 28 |
2 files changed, 36 insertions, 37 deletions
diff --git a/ImageViewerActivity.py b/ImageViewerActivity.py index 685d988..3c6b7e8 100644 --- a/ImageViewerActivity.py +++ b/ImageViewerActivity.py @@ -40,7 +40,7 @@ from sugar3.graphics.icon import Icon from sugar3.activity.widgets import ActivityToolbarButton from sugar3.activity.widgets import StopButton from sugar3.graphics import style - +from sugar3.graphics.alert import Alert from sugar3 import network from sugar3.datastore import datastore @@ -55,7 +55,30 @@ import telepathy import dbus import ImageView -import ProgressDialog + + +class ProgressAlert(Alert): + """ + Progress alert with a progressbar - to show the advance of a task + """ + + def __init__(self, timeout=5, **kwargs): + Alert.__init__(self, **kwargs) + + self._pb = Gtk.ProgressBar() + self._msg_box.pack_start(self._pb, False, False, 0) + self._pb.set_size_request(int(Gdk.Screen.width() * 9. / 10.), -1) + self._pb.set_fraction(0.0) + self._pb.show() + + def set_fraction(self, fraction): + # update only by 10% fractions + if int(fraction * 100) % 10 == 0: + self._pb.set_fraction(fraction) + self._pb.queue_draw() + # force updating the progressbar + while Gtk.events_pending(): + Gtk.main_iteration_do(True) class ImageViewerHTTPRequestHandler(network.ChunkedGlibHTTPRequestHandler): @@ -144,7 +167,7 @@ class ImageViewerActivity(activity.Activity): self.__zoomtouch_changed_cb) zoom_controller.connect('ended', self.__zoomtouch_ended_cb) - self.progressdialog = None + self._progress_alert = None toolbar_box = ToolbarBox() self._add_toolbar_buttons(toolbar_box) @@ -210,6 +233,10 @@ class ImageViewerActivity(activity.Activity): # Already joined for some reason, just get the document self._joined_cb(self) else: + self._progress_alert = ProgressAlert() + self._progress_alert.props.title = _('Please wait') + self._progress_alert.props.msg = _('Starting connection...') + self.add_alert(self._progress_alert) # Wait for a successful join before trying to get the document self.connect("joined", self._joined_cb) @@ -419,7 +446,9 @@ class ImageViewerActivity(activity.Activity): logging.debug("Got document %s (%s) from tube %u", tempfile, suggested_name, tube_id) - self.progressdialog.destroy() + if self._progress_alert is not None: + self.remove_alert(self._progress_alert) + self._progress_alert = None GObject.idle_add(self.__set_file_idle_cb, self._jobject.object_id) @@ -449,9 +478,7 @@ class ImageViewerActivity(activity.Activity): total = self._download_content_length fraction = bytes_downloaded / total - self.progressdialog.set_fraction(fraction) - - #Gtk.main_iteration() + self._progress_alert.set_fraction(fraction) def _download_error_cb(self, getter, err, tube_id): logging.debug("Error getting document from tube %u: %s", @@ -523,8 +550,8 @@ class ImageViewerActivity(activity.Activity): """ self.watch_for_tubes() - self.progressdialog = ProgressDialog.ProgressDialog(self) - self.progressdialog.show_all() + if self._progress_alert is not None: + self._progress_alert.props.msg = _('Receiving image...') def _share_document(self): """Share the document.""" diff --git a/ProgressDialog.py b/ProgressDialog.py deleted file mode 100644 index c1a8f70..0000000 --- a/ProgressDialog.py +++ /dev/null @@ -1,28 +0,0 @@ -from gi.repository import Gtk -from gi.repository import GObject -from gettext import gettext as _ - - -class ProgressDialog(Gtk.Dialog): - - def __init__(self, parent): - Gtk.Dialog.__init__(self, _('Downloading...'), parent, \ - Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, \ - (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)) - - self._activity = parent - - self.connect('response', self._response_cb) - - self._pb = Gtk.ProgressBar() - self._pb.set_text(_('Retrieving shared image, please wait...')) - self.vbox.add(self._pb) - - def _response_cb(self, dialog, response_id): - if response_id == Gtk.ResponseType.REJECT: - self._activity.close() - else: - pass - - def set_fraction(self, fraction): - self._pb.set_fraction(fraction) |