Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--chat.py18
-rw-r--r--notify.py51
3 files changed, 67 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 1880796..91bb8c6 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,4 @@
+* Use sugar.graphics.alert to show status info (morgs)
* #4320: better URL handling and display (morgs)
* #4331: Don't crash/ignore non-Sugar buddies (morgs)
diff --git a/chat.py b/chat.py
index 451e1bf..2a4e74f 100644
--- a/chat.py
+++ b/chat.py
@@ -46,6 +46,8 @@ from telepathy.constants import (
CONNECTION_STATUS_CONNECTED, CONNECTION_STATUS_DISCONNECTED,
CONNECTION_STATUS_CONNECTING)
+from notify import NotifyAlert
+
logger = logging.getLogger('chat-activity')
class Chat(Activity):
@@ -75,8 +77,7 @@ class Chat(Activity):
self._joined_cb()
else:
# we are creating the activity
- self.add_text(None, _('Share, or invite someone.'),
- status_message=True)
+ self._alert(_('Off-line'), _('Share, or invite someone.'))
def _shared_cb(self, activity):
logger.debug('Chat was shared')
@@ -85,7 +86,7 @@ class Chat(Activity):
def _setup(self):
self.text_channel = TextChannelWrapper(self)
self.text_channel.set_received_callback(self._received_cb)
- self.add_text(None, _('Connected'), status_message=True)
+ self._alert(_('On-line'), _('Connected'))
self._shared_activity.connect('buddy-joined', self._buddy_joined_cb)
self._shared_activity.connect('buddy-left', self._buddy_left_cb)
self.entry.set_editable(True)
@@ -107,6 +108,17 @@ class Chat(Activity):
nick = '???'
self.add_text(buddy, text)
+ def _alert(self, title, text=None):
+ alert = NotifyAlert(timeout=5)
+ alert.props.title = title
+ alert.props.msg = text
+ self.add_alert(alert)
+ alert.connect('response', self._alert_cancel_cb)
+ alert.show()
+
+ def _alert_cancel_cb(self, alert, response_id):
+ self.remove_alert(alert)
+
def _buddy_joined_cb (self, activity, buddy):
"""Show a buddy who joined"""
if buddy == self.owner:
diff --git a/notify.py b/notify.py
new file mode 100644
index 0000000..1e8ef15
--- /dev/null
+++ b/notify.py
@@ -0,0 +1,51 @@
+# Copyright 2007 Collabora Ltd.
+# Copyright 2007 One Laptop Per Child
+#
+# 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 2 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+
+from gettext import gettext as _
+
+import gtk
+import gobject
+import hippo
+from sugar.graphics.alert import Alert, _TimeoutIcon
+from sugar.graphics import style
+
+class NotifyAlert(Alert):
+ """Timeout alert with only an "OK" button - just for notifications"""
+
+ def __init__(self, timeout=5, **kwargs):
+ Alert.__init__(self, **kwargs)
+
+ self._timeout = timeout
+
+ self._timeout_text = _TimeoutIcon(
+ text=self._timeout,
+ color=style.COLOR_BUTTON_GREY.get_int(),
+ background_color=style.COLOR_WHITE.get_int())
+ canvas = hippo.Canvas()
+ canvas.set_root(self._timeout_text)
+ canvas.show()
+ self.add_button(gtk.RESPONSE_OK, _('OK'), canvas)
+
+ gobject.timeout_add(1000, self.__timeout)
+
+ def __timeout(self):
+ self._timeout -= 1
+ self._timeout_text.props.text = self._timeout
+ if self._timeout == 0:
+ self._response(gtk.RESPONSE_OK)
+ return False
+ return True