diff options
author | Bryan Clark <clarkbw@cvs.gnome.org> | 2004-08-30 17:34:52 +0000 |
---|---|---|
committer | Bryan W. Clark <clarkbw@gnome.org> | 2004-08-30 17:34:52 +0000 |
commit | 3e025313729b0ac10d77d8a55fe851bf42de8e7b (patch) | |
tree | 0aebaa0ef2bb2ae4526a441bc9d4f06620242dc7 /examples | |
parent | b2fb0f8b0d1e0ac55880a77175572b4b11e66905 (diff) | |
download | NetworkManager-3e025313729b0ac10d77d8a55fe851bf42de8e7b.tar.gz |
2004-08-30 Bryan Clark <clarkbw@cvs.gnome.org>
* examples/python/NetworkManager.py:
added convience functions has_wired_device and has_wireless_device
* examples/python/systray/network_tray.py:
cleaned up a bunch of cruft, added support for listing wireless
networks just like the real applet. This is probably all I'm
going to work on this applet from now on.
TODO: add support for actually changing networks and devices
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@111 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/python/NetworkManager.py | 12 | ||||
-rwxr-xr-x | examples/python/systray/network_tray.py | 115 |
2 files changed, 95 insertions, 32 deletions
diff --git a/examples/python/NetworkManager.py b/examples/python/NetworkManager.py index f9d29f200c..9deddfd827 100755 --- a/examples/python/NetworkManager.py +++ b/examples/python/NetworkManager.py @@ -147,6 +147,18 @@ class NetworkManager: """ def get_all_devices(self): return self.__devices.values() + + def _has_type_device (self, type): + for device in self.get_devices(): + if device["nm.type"] == type: + return True + return False + + def has_wired_device(self): + return self._has_type_device(WIRED_DEVICE) + + def has_wireless_device(self): + return self._has_type_device(WIRELESS_DEVICE) def _get_hal_info(self, udi): hal_devices = self._hal_manager.FindDeviceStringMatch("info.udi", diff --git a/examples/python/systray/network_tray.py b/examples/python/systray/network_tray.py index fc49805cc2..bedbee47d0 100755 --- a/examples/python/systray/network_tray.py +++ b/examples/python/systray/network_tray.py @@ -15,7 +15,6 @@ except: class network_tray: def __init__(self): - self._make_icons() self._make_menu() self._make_tray() @@ -29,11 +28,31 @@ class network_tray: def _add_separator_item(self): self._menu.append(gtk.SeparatorMenuItem()) - def _add_device_menu_item(self, device): + def _add_label_item(self, label): menuitem = gtk.MenuItem() - hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=3) + menuitem.set_right_justified(gtk.TRUE) + menuitem.set_sensitive(gtk.FALSE) + gtklabel = gtk.Label() + gtklabel.set_justify(gtk.JUSTIFY_RIGHT) + gtklabel.set_markup("<span size=\"small\" foreground=\"#aaaaaa\" weight=\"ultralight\">%s</span>" % label) + gtklabel.set_selectable(gtk.FALSE) + hbox = gtk.HBox(homogeneous=gtk.TRUE, spacing=6) + hbox.pack_end(gtklabel,expand=gtk.TRUE, fill=gtk.TRUE, padding=0) + menuitem.add(hbox) + self._menu.append(menuitem) + menuitem.show_all() + + def _add_device_menu_item(self, device, active=gtk.FALSE): + menuitem = gtk.MenuItem() + hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=6) hbox.pack_start(self._get_icon(device), expand=gtk.FALSE, fill=gtk.FALSE) - hbox.pack_start(gtk.Label(device["info.product"]), expand=gtk.TRUE, fill=gtk.TRUE) + label = gtk.Label() + label.set_justify(gtk.JUSTIFY_LEFT) + if active == gtk.TRUE: + label.set_markup("<span weight=\"bold\">%s</span>" % device["info.product"]) + else: + label.set_text(device["info.product"]) + hbox.pack_start(label, expand=gtk.FALSE, fill=gtk.FALSE) menuitem.add(hbox) hbox.show() self._menu.append(menuitem) @@ -41,12 +60,23 @@ class network_tray: def _add_network_menu_item(self, network): menuitem = gtk.MenuItem() - hbox = gtk.HBox() + menuitem.set_right_justified(gtk.FALSE) + hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=6) menuitem.add(hbox) - hbox.add(gtk.Label("label")) + label = gtk.Label(network["name"]) + label.set_alignment(0.1,0.5) + label.show() + hbox.pack_start(label,expand=gtk.TRUE, fill=gtk.TRUE) progress = gtk.ProgressBar() - progress.set_fraction(.5) - hbox.add(progress) + progress.set_fraction(network["quality"]) + progress.show() + hbox.pack_start(progress, expand=gtk.FALSE, fill=gtk.FALSE) + icon = self._get_encrypted_icon() + if network["encrypted"] == 1: + icon.hide() + else: + icon.show() + hbox.pack_start(icon,expand=gtk.FALSE, fill=gtk.FALSE) hbox.show() self._menu.append(menuitem) menuitem.show() @@ -54,45 +84,66 @@ class network_tray: def _network_event(self, interface, signal_name, service, path, message): + + for child in self._menu.get_children(): + self._menu.remove(child) + devices = self._nm.get_devices() + active_device = self._nm.get_active_device() tt = "" + self._add_label_item("Network Connections") for device in devices: - self._add_device_menu_item(device) + if device == active_device: + active = gtk.TRUE + else: + active = gtk.FALSE + + self._add_device_menu_item(device, active) tt = "%s%s [%s]\n"%(tt,device["info.product"],device["nm.status"]) - self._tooltips.set_tip(self._menu,tt) -# self._add_separator_item() + self._tooltips.set_tip(self._top_level_menu,tt) - self._current_icon = self._get_icon(self._nm.get_active_device()) + if active_device["nm.type"] == self._nm.WIRELESS_DEVICE: + self._add_separator_item() + self._add_label_item("Wireless Networks") + for name, network in active_device["nm.networks"].iteritems(): + self._add_network_menu_item(network) + + + self._current_icon = self._get_icon(active_device) self._current_icon.show() - self._top_level_menu.show_all() + self._top_level_menu.show() + + def _get_encrypted_icon(self): + pb = gtk.gdk.pixbuf_new_from_file("../../../panel-applet/keyring.png") + pb = pb.scale_simple(24,24,gtk.gdk.INTERP_NEAREST) + _keyring = gtk.Image() + _keyring.set_from_pixbuf(pb) + return _keyring def _get_icon(self, active_device): if active_device: if active_device["nm.type"] == self._nm.WIRED_DEVICE: - return self._wired_icon + pb = gtk.gdk.pixbuf_new_from_file("../../../panel-applet/wired.png") + pb = pb.scale_simple(24,24,gtk.gdk.INTERP_NEAREST) + _wired_icon = gtk.Image() + _wired_icon.set_from_pixbuf(pb) + return _wired_icon elif active_device["nm.type"] == self._nm.WIRELESS_DEVICE: - return self._wireless_icon + pb = gtk.gdk.pixbuf_new_from_file("../../../panel-applet/wireless-applet.png") + pb = pb.scale_simple(24,24,gtk.gdk.INTERP_NEAREST) + _wireless_icon = gtk.Image() + _wireless_icon.set_from_pixbuf(pb) + return _wireless_icon else: - return self._nothing_icon + pb = gtk.gdk.pixbuf_new_from_file("../../../panel-applet/wireless-applet.png") + pb = pb.scale_simple(16,16,gtk.gdk.INTERP_NEAREST) + _nothing_icon = gtk.Image() + _nothing_icon.set_from_pixbuf(pb) + return _nothing_icon - def _make_icons(self): - pb = gtk.gdk.pixbuf_new_from_file("../../../panel-applet/wireless-applet.png") - pb = pb.scale_simple(16,16,gtk.gdk.INTERP_NEAREST) - self._nothing_icon = gtk.Image() - self._nothing_icon.set_from_pixbuf(pb) - - pb = gtk.gdk.pixbuf_new_from_file("../../../panel-applet/wireless-applet.png") - pb = pb.scale_simple(24,24,gtk.gdk.INTERP_NEAREST) - self._wireless_icon = gtk.Image() - self._wireless_icon.set_from_pixbuf(pb) - - pb = gtk.gdk.pixbuf_new_from_file("../../../panel-applet/wired.png") - pb = pb.scale_simple(24,24,gtk.gdk.INTERP_NEAREST) - self._wired_icon = gtk.Image() - self._wired_icon.set_from_pixbuf(pb) def _make_tray(self): self._tray = trayicon.TrayIcon("NetworkManager") @@ -113,7 +164,7 @@ class network_tray: self._menu = gtk.Menu() self._top_level_menu.set_submenu(self._menu) - self._current_icon = self._nothing_icon + self._current_icon = self._get_icon(None) self._current_icon.show() self._top_level_menu.add(self._current_icon) |