From c2b9cc5fd53da654d288db34ea7782017e37163a Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Mon, 02 Mar 2009 04:17:35 +0000 Subject: User alert to notify about existed wiki article --- diff --git a/library.py b/library.py index 360ae4b..211135d 100644 --- a/library.py +++ b/library.py @@ -212,8 +212,9 @@ class Toolbar(gtk.Toolbar): return if book.wiki.find('%s (from %s)' % (title, wiki))[0]: - self.library.progress.set_label(_('"%s" article already exists') % title) - Timer(10, self._clear_progress).start() + self.activity.notify_alert( + _('Exists'), + _('"%s" article already exists') % title) else: Timer(0, self._download, [title, wiki]).start() diff --git a/shared.py b/shared.py index c03c713..0250d27 100644 --- a/shared.py +++ b/shared.py @@ -12,12 +12,14 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +import gtk import logging import telepathy from gobject import property, SIGNAL_RUN_FIRST, TYPE_PYOBJECT from sugar.activity.activity import Activity from sugar.presence.sugartubeconn import SugarTubeConnection +from sugar.graphics.alert import ConfirmationAlert, NotifyAlert logger = logging.getLogger('infoslicer') @@ -45,6 +47,28 @@ class CanvasActivity(Activity): self.emit('init') return False + def notify_alert(self, title, msg): + alert = NotifyAlert(title=title, msg=msg) + + def response(alert, response_id, self): + self.remove_alert(alert) + + alert.connect('response', response, self) + alert.show_all() + self.add_alert(alert) + + def confirmation_alert(self, title, msg, cb, *cb_args): + alert = ConfirmationAlert(title=title, msg=msg) + + def response(alert, response_id, self, cb, *cb_args): + self.remove_alert(alert) + if response_id is gtk.RESPONSE_OK: + cb(*cb_args) + + alert.connect('response', response, self, cb, *cb_args) + alert.show_all() + self.add_alert(alert) + class SharedActivity(CanvasActivity): __gsignals__ = { 'tube' : (SIGNAL_RUN_FIRST, None, 2*[TYPE_PYOBJECT]) } diff --git a/xol.py b/xol.py index afa5abf..1e9aff5 100644 --- a/xol.py +++ b/xol.py @@ -11,7 +11,6 @@ from gettext import gettext as _ from sugar.activity.activity import get_bundle_path, get_activity_root, get_bundle_name from sugar.datastore import datastore from sugar import activity -from sugar.graphics.alert import ConfirmationAlert, NotifyAlert from Processing.NewtifulSoup import NewtifulStoneSoup as BeautifulStoneSoup import book @@ -20,17 +19,9 @@ logger = logging.getLogger('infoslicer') def publish(activity, force=False): if not [i for i in book.custom.index if i['ready']]: - alert = NotifyAlert( - title=_('Nothing to publish'), - msg=_('Mark arcticles from "Custom" panel and try again.')) - - def response(alert, response_id, activity): - activity.remove_alert(alert) - - alert.connect('response', response, activity) - alert.show_all() - activity.add_alert(alert) - + activity.notify_alert( + _('Nothing to publish'), + _('Mark arcticles from "Custom" panel and try again.')) return title = activity.metadata['title'] @@ -45,21 +36,12 @@ def publish(activity, force=False): if force: jobject = jobject[0] else: - alert = ConfirmationAlert( - title=_('Overwrite existed bundle?'), - msg=_('A bundle for current object was already created. ' \ - 'Click "OK" to overwrite it.')) - - def response(alert, response_id, activity): - activity.remove_alert(alert) - if response_id is gtk.RESPONSE_OK: - publish(activity, True) - - alert.connect('response', response, activity) - alert.show_all() - activity.add_alert(alert) + activity.confirmation_alert( + _('Overwrite existed bundle?'), + _('A bundle for current object was already created. ' \ + 'Click "OK" to overwrite it.'), + publish, activity, True) jobject[0].destroy() - return else: jobject = datastore.create() -- cgit v0.9.1