Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Francis <francis@sugarlabs.org>2012-10-18 00:08:01 (GMT)
committer Daniel Francis <francis@sugarlabs.org>2012-10-18 00:08:01 (GMT)
commitf94493e3993f4d218bef7810d2ad44d691048cf3 (patch)
treec81f148f7f11a8e2e8ef545a8270b0d3041068d1
parentf708da3017040588952a33ca4c658c2268440ecb (diff)
Add alerts
Added minimal alerts: - Simple Alert (Alert) In desktops it is a dialog and in Sugar it is a SugarAlert. - Notify (NotifyAlert) In desktops it is a notification made with pynotify and in Sugar its a sugar.graphics.alert.NotifyAlert Signed-off-by: Daniel Francis <francis@sugarlabs.org>
-rwxr-xr-xapplication.py14
-rw-r--r--desktop/sweetener/alerts.py44
-rw-r--r--sugar/sweetener/alerts.py61
3 files changed, 115 insertions, 4 deletions
diff --git a/application.py b/application.py
index 23556ab..7fcac0c 100755
--- a/application.py
+++ b/application.py
@@ -32,6 +32,7 @@ glib.set_application_name(appname)
import gtk
from options import Options
from canvas import Canvas
+from sweetener.alerts import Alert
this_dir = os.path.split('__file__')[:-1]
if len(this_dir) == 1 and this_dir[0] == '':
@@ -139,7 +140,7 @@ class Application(gtk.Window):
def expose_event(self, widget, event):
#logger.debug('Exposing')
if not self.started:
- if self.file_path != None:
+ if self.file_path is not None:
self.canvas.read_file(self.file_path)
self.set_title(os.path.abspath('%s - %s' % (self.file_path,
appname)))
@@ -157,6 +158,9 @@ class Application(gtk.Window):
else:
self._unfullscreen_button.hide()
+ def add_alert(self, alert):
+ alert.run()
+
def fullscreen(self):
self.options.hide()
self._is_fullscreen = True
@@ -198,7 +202,8 @@ class Application(gtk.Window):
def stop(self):
if info.io_mode == info.CONFIG:
- self.file_path = os.path.join(os.environ['HOME'], '.' + info.lower_name)
+ self.file_path = os.path.join(os.environ['HOME'],
+ '.' + info.lower_name)
self.save()
gtk.main_quit()
@@ -217,7 +222,7 @@ class Application(gtk.Window):
self.set_title('%s - %s' % (self.file_path, appname))
def save(self):
- if self.file_path == None:
+ if self.file_path is None:
self.save_as()
else:
logger.debug('Write file %s' % self.file_path)
@@ -255,7 +260,8 @@ if __name__ == '__main__':
file_path = None
logger.debug('Create new file')
else:
- if os.path.exists(os.path.join(os.environ['HOME'], '.' + info.lower_name)):
+ if os.path.exists(os.path.join(os.environ['HOME'],
+ '.' + info.lower_name)):
file_path = os.path.join(os.environ['HOME'], '.' + info.lower_name)
else:
file_path = None
diff --git a/desktop/sweetener/alerts.py b/desktop/sweetener/alerts.py
new file mode 100644
index 0000000..7f90efb
--- /dev/null
+++ b/desktop/sweetener/alerts.py
@@ -0,0 +1,44 @@
+# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+import gtk
+
+import pynotify
+import info
+pynotify.init(info.name)
+
+
+class Alert(gtk.MessageDialog):
+ def __init__(self, parent, title, content, mtype):
+ gtk.MessageDialog.__init__(self, parent, gtk.DIALOG_MODAL,
+ type=mtype,
+ buttons=gtk.BUTTONS_OK)
+ self.set_markup('<b>%s</b>' % title)
+ self.format_secondary_markup(content)
+
+ def run(self):
+ gtk.MessageDialog.run(self)
+ gtk.MessageDialog.destroy(self)
+
+
+class NotifyAlert(pynotify.Notification):
+ def __init__(self, parent, title, content, icon, timeout):
+ pynotify.Notification.__init__(self, title, message=content, icon=icon)
+ self.set_timeout(timeout)
+
+ def run(self):
+ self.show()
diff --git a/sugar/sweetener/alerts.py b/sugar/sweetener/alerts.py
new file mode 100644
index 0000000..9609a82
--- /dev/null
+++ b/sugar/sweetener/alerts.py
@@ -0,0 +1,61 @@
+# Copyright (C) 2012 S. Daniel Francis <francis@sugarlabs.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+from gettext import gettext as _
+import gtk
+from sugar.graphics import style
+from sugar.graphics.alert import Alert as SugarAlert
+from sugar.graphics.alert import NotifyAlert as SugarNotify
+
+from icon import Icon
+
+
+class Alert(SugarAlert):
+ def __init__(self, parent, title, content, mtype):
+ SugarAlert.__init__(self)
+ self._parent = parent
+ if mtype == gtk.MESSAGE_INFO:
+ icon = Icon(icon_name='emblem-notification')
+ icon.show()
+ self.props.icon = icon
+ icon.props.pixel_size = style.SMALL_ICON_SIZE * 2
+ self.props.title = title
+ self.props.msg = content
+ ok_icon = Icon(icon_name='dialog-ok')
+ self.add_button(gtk.RESPONSE_OK, _('Ok'), ok_icon)
+ ok_icon.show()
+ self.connect('response', self.remove_myself)
+
+ def remove_myself(self, widget=None, response=None):
+ self._parent.remove_alert(self)
+
+
+class NotifyAlert(SugarNotify):
+ def __init__(self, parent, title, content, icon, timeout):
+ SugarNotify.__init__(self, timeout)
+ self._parent = parent
+ self.props.title = title
+ self.props.msg = content
+ if icon is not None:
+ icon = Icon(icon_name=icon)
+ icon.show()
+ self.props.icon = icon
+ icon.props.pixel_size = style.SMALL_ICON_SIZE * 2
+ self.connect('response', self.remove_myself)
+
+ def remove_myself(self, widget=None, response=None):
+ self._parent.remove_alert(self)