[Pkg-bazaar-commits] ./bzr-gtk/unstable r211: Move notification area code into separate file.

Jelmer Vernooij jelmer at samba.org
Fri Apr 10 07:45:33 UTC 2009


------------------------------------------------------------
revno: 211
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Fri 2007-07-13 23:34:04 +0300
message:
  Move notification area code into separate file.
added:
  notify.py
modified:
  __init__.py
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2007-07-13 20:23:38 +0000
+++ b/__init__.py	2007-07-13 20:34:04 +0000
@@ -464,60 +464,11 @@
     """
 
     def run(self):
-        def toggle_lan_gateway(item):
-            if item.get_active():
-                langateway.start()
-            else:
-                langateway.stop()
-
-        def toggle_announce_branches(item):
-            if item.get_active():
-                zeroconfserver.start()
-            else:
-                zeroconfserver.close()
-
-        def show_preferences(item):
-            # FIXME
-            pass 
-
-        def make_menu(icon, event_button, event_time):
-            menu.popup(None, None, gtk.status_icon_position_menu, 
-                       event_button, event_time, icon)
-
+        from notify import NotifyPopupMenu
         gtk = self.open_display()
-        t = gtk.status_icon_new_from_file("bzr-icon-64.png")
-        t.connect('popup-menu', make_menu)
-        menu = gtk.Menu()
-        try:
-            from bzrlib.plugins.dbus.activity import LanGateway
-            langateway = LanGateway()
-            item = gtk.CheckMenuItem('_Gateway to LAN')
-            item.connect('toggled', toggle_lan_gateway)
-            menu.append(item)
-            menu.append(gtk.SeparatorMenuItem())
-        except ImportError:
-            langateway = None
-
-        try:
-            from bzrlib.plugins.avahi.share import ZeroConfServer
-            from bzrlib import urlutils
-            zeroconfserver = ZeroConfServer(urlutils.normalize_url('.'))
-            item = gtk.CheckMenuItem('Announce _branches on LAN')
-            item.connect('toggled', toggle_announce_branches)
-            menu.append(item)
-            menu.append(gtk.SeparatorMenuItem())
-        except ImportError:
-            zeroconfserver = None
-
-        item = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES, None)
-        menu.append(item)
-        menu.append(gtk.SeparatorMenuItem())
-        item = gtk.MenuItem('_Close')
-        item.connect('activate', gtk.main_quit)
-        menu.append(item)
-        menu.show_all()
-
-        gtk.main()
+        menu = NotifyPopupMenu()
+        icon = gtk.status_icon_new_from_file("bzr-icon-64.png")
+        icon.connect('popup-menu', menu.display)
 
         import cgi
         import dbus
@@ -535,6 +486,7 @@
         broadcast_service = bus.get_object(
             activity.Broadcast.DBUS_NAME,
             activity.Broadcast.DBUS_PATH)
+
         def catch_branch(revision_id, urls):
             # TODO: show all the urls, or perhaps choose the 'best'.
             url = urls[0]

=== added file 'notify.py'
--- a/notify.py	1970-01-01 00:00:00 +0000
+++ b/notify.py	2007-07-13 20:34:04 +0000
@@ -0,0 +1,76 @@
+# Copyright (C) 2007 by Robert Collins
+#                       Jelmer Vernooij
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+"""Notification area icon and notification for Bazaar."""
+
+import gtk
+
+class NotifyPopupMenu(gtk.Menu):
+    def __init__(self):
+        super(NotifyPopupMenu, self).__init__()
+        self.create_items()
+
+    def create_items(self):
+        try:
+            from bzrlib.plugins.dbus.activity import LanGateway
+            self.langateway = LanGateway()
+            item = gtk.CheckMenuItem('_Gateway to LAN')
+            item.connect('toggled', self.toggle_lan_gateway)
+            self.append(item)
+            self.append(gtk.SeparatorMenuItem())
+        except ImportError:
+            pass
+
+        try:
+            from bzrlib.plugins.avahi.share import ZeroConfServer
+            from bzrlib import urlutils
+            self.zeroconfserver = ZeroConfServer(urlutils.normalize_url('.'))
+            item = gtk.CheckMenuItem('Announce _branches on LAN')
+            item.connect('toggled', self.toggle_announce_branches)
+            self.append(item)
+            self.append(gtk.SeparatorMenuItem())
+        except ImportError:
+            pass
+
+        item = gtk.ImageMenuItem(gtk.STOCK_PREFERENCES, None)
+        item.connect('activate', self.show_preferences)
+        self.append(item)
+        self.append(gtk.SeparatorMenuItem())
+        item = gtk.MenuItem('_Close')
+        item.connect('activate', gtk.main_quit)
+        self.append(item)
+        self.show_all()
+
+    def display(self, icon, event_button, event_time):
+        self.popup(None, None, gtk.status_icon_position_menu, 
+               event_button, event_time, icon)
+
+    def toggle_lan_gateway(self, item):
+        if item.get_active():
+            self.langateway.start()
+        else:
+            self.langateway.stop()
+
+    def toggle_announce_branches(self, item):
+        if item.get_active():
+            self.zeroconfserver.start()
+        else:
+            self.zeroconfserver.close()
+
+    def show_preferences(self, item):
+        # FIXME
+        pass
+



More information about the Pkg-bazaar-commits mailing list