2004-09-08 Bryan Clark <clarkbw@cvs.gnome.org>
* examples/python/NetworkManager.py: added CONNECTED, CONNECTING, and DISCONNECTED states added methods to return number of devices of a single type * examples/python/systray/network_tray.py: did some tweaks to get the menu looking near what it is supposed to look like. Also did a Airo card hack to make it show the correct AP quality git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@134 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:

committed by
Bryan W. Clark

parent
0459813084
commit
dade73e234
11
ChangeLog
11
ChangeLog
@@ -1,3 +1,14 @@
|
|||||||
|
2004-09-08 Bryan Clark <clarkbw@cvs.gnome.org>
|
||||||
|
|
||||||
|
* examples/python/NetworkManager.py:
|
||||||
|
added CONNECTED, CONNECTING, and DISCONNECTED states
|
||||||
|
added methods to return number of devices of a single type
|
||||||
|
|
||||||
|
* examples/python/systray/network_tray.py:
|
||||||
|
did some tweaks to get the menu looking near what it is supposed
|
||||||
|
to look like. Also did a Airo card hack to make it show the
|
||||||
|
correct AP quality
|
||||||
|
|
||||||
2004-09-08 Dan Williams <dcbw@redhat.com>
|
2004-09-08 Dan Williams <dcbw@redhat.com>
|
||||||
|
|
||||||
* panel-applet/no-networkmanager.png
|
* panel-applet/no-networkmanager.png
|
||||||
|
@@ -24,6 +24,10 @@ class NetworkManager:
|
|||||||
WIRED_DEVICE = 1
|
WIRED_DEVICE = 1
|
||||||
WIRELESS_DEVICE = 2
|
WIRELESS_DEVICE = 2
|
||||||
|
|
||||||
|
CONNECTED = "connected"
|
||||||
|
CONNECTING = "connecting"
|
||||||
|
DISCONNECTED = "disconnected"
|
||||||
|
|
||||||
NM_SIGNALS = [ "DeviceNoLongerActive",
|
NM_SIGNALS = [ "DeviceNoLongerActive",
|
||||||
"DeviceNowActive",
|
"DeviceNowActive",
|
||||||
"DeviceActivating",
|
"DeviceActivating",
|
||||||
@@ -107,24 +111,27 @@ class NetworkManager:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
active_device = self.nm_object.getActiveDevice()
|
active_device = self.nm_object.getActiveDevice()
|
||||||
active_device_status = self.nm_object.status()
|
|
||||||
|
|
||||||
if device == active_device:
|
if device == active_device:
|
||||||
d["nm.status"] = active_device_status
|
d["nm.status"] = self.nm_object.status()
|
||||||
else:
|
else:
|
||||||
d["nm.status"] = "not connected"
|
d["nm.status"] = self.DISCONNECTED
|
||||||
|
|
||||||
|
# we already have this device cached, so just update the status
|
||||||
if device in self.__devices:
|
if device in self.__devices:
|
||||||
for k,v in d.iteritems():
|
for k,v in d.iteritems():
|
||||||
self.__devices[device][k] = v
|
self.__devices[device][k] = v
|
||||||
return self.__devices[device]
|
# it's a new device so get the info from HAL
|
||||||
else:
|
else:
|
||||||
hal = self._get_hal_info(d["nm.udi"])
|
hal = self._get_hal_info(d["nm.udi"])
|
||||||
for k,v in hal.iteritems():
|
for k,v in hal.iteritems():
|
||||||
d[k] = v
|
d[k] = v
|
||||||
self.__devices[device] = d
|
self.__devices[device] = d
|
||||||
return self.__devices[device]
|
|
||||||
except:
|
return self.__devices[device]
|
||||||
|
|
||||||
|
except Error, e:
|
||||||
|
print e
|
||||||
return None
|
return None
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -148,17 +155,30 @@ class NetworkManager:
|
|||||||
def get_all_devices(self):
|
def get_all_devices(self):
|
||||||
return self.__devices.values()
|
return self.__devices.values()
|
||||||
|
|
||||||
def _has_type_device (self, type):
|
def has_type_device (self, type):
|
||||||
for device in self.get_devices():
|
for device in self.get_devices():
|
||||||
if device["nm.type"] == type:
|
if device["nm.type"] == type:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def number_device_types(self, type):
|
||||||
|
count = 0
|
||||||
|
for device in self.get_devices():
|
||||||
|
if device["nm.type"] == type:
|
||||||
|
count = count + 1
|
||||||
|
return count
|
||||||
|
|
||||||
|
def number_wired_devices(self):
|
||||||
|
return self.number_device_types(self.WIRED_DEVICE)
|
||||||
|
|
||||||
|
def number_wireless_devices(self):
|
||||||
|
return self.number_device_types(self.WIRELESS_DEVICE)
|
||||||
|
|
||||||
def has_wired_device(self):
|
def has_wired_device(self):
|
||||||
return self._has_type_device(WIRED_DEVICE)
|
return self.has_type_device(self.WIRED_DEVICE)
|
||||||
|
|
||||||
def has_wireless_device(self):
|
def has_wireless_device(self):
|
||||||
return self._has_type_device(WIRELESS_DEVICE)
|
return self.has_type_device(self.WIRELESS_DEVICE)
|
||||||
|
|
||||||
def _get_hal_info(self, udi):
|
def _get_hal_info(self, udi):
|
||||||
hal_devices = self._hal_manager.FindDeviceStringMatch("info.udi",
|
hal_devices = self._hal_manager.FindDeviceStringMatch("info.udi",
|
||||||
|
@@ -30,10 +30,9 @@ class network_tray:
|
|||||||
|
|
||||||
def _add_label_item(self, label):
|
def _add_label_item(self, label):
|
||||||
menuitem = gtk.MenuItem()
|
menuitem = gtk.MenuItem()
|
||||||
menuitem.set_right_justified(gtk.TRUE)
|
|
||||||
menuitem.set_sensitive(gtk.FALSE)
|
menuitem.set_sensitive(gtk.FALSE)
|
||||||
gtklabel = gtk.Label()
|
gtklabel = gtk.Label()
|
||||||
gtklabel.set_justify(gtk.JUSTIFY_RIGHT)
|
|
||||||
gtklabel.set_markup("<span size=\"small\" foreground=\"#aaaaaa\" weight=\"ultralight\">%s</span>" % label)
|
gtklabel.set_markup("<span size=\"small\" foreground=\"#aaaaaa\" weight=\"ultralight\">%s</span>" % label)
|
||||||
gtklabel.set_selectable(gtk.FALSE)
|
gtklabel.set_selectable(gtk.FALSE)
|
||||||
hbox = gtk.HBox(homogeneous=gtk.TRUE, spacing=6)
|
hbox = gtk.HBox(homogeneous=gtk.TRUE, spacing=6)
|
||||||
@@ -41,26 +40,48 @@ class network_tray:
|
|||||||
menuitem.add(hbox)
|
menuitem.add(hbox)
|
||||||
self._menu.append(menuitem)
|
self._menu.append(menuitem)
|
||||||
menuitem.show_all()
|
menuitem.show_all()
|
||||||
|
|
||||||
def _add_device_menu_item(self, device, active=gtk.FALSE):
|
def _add_other_wireless_item(self):
|
||||||
menuitem = gtk.MenuItem()
|
menuitem = gtk.MenuItem()
|
||||||
hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=6)
|
menuitem.set_sensitive(gtk.TRUE)
|
||||||
hbox.pack_start(self._get_icon(device), expand=gtk.FALSE, fill=gtk.FALSE)
|
gtklabel = gtk.Label()
|
||||||
label = gtk.Label()
|
gtklabel.set_alignment(0,0)
|
||||||
label.set_justify(gtk.JUSTIFY_LEFT)
|
gtklabel.set_label("Other Wireless Networks...")
|
||||||
if active == gtk.TRUE:
|
hbox = gtk.HBox(homogeneous=gtk.TRUE, spacing=6)
|
||||||
label.set_markup("<span weight=\"bold\">%s</span>" % device["info.product"])
|
hbox.pack_end(gtklabel,expand=gtk.TRUE, fill=gtk.TRUE, padding=6)
|
||||||
else:
|
menuitem.add(hbox)
|
||||||
label.set_text(device["info.product"])
|
tt = "Add a wireless network that does not appear on the list"
|
||||||
hbox.pack_start(label, expand=gtk.FALSE, fill=gtk.FALSE)
|
self._tooltips.set_tip(menuitem,tt)
|
||||||
menuitem.add(hbox)
|
|
||||||
hbox.show()
|
|
||||||
self._menu.append(menuitem)
|
self._menu.append(menuitem)
|
||||||
menuitem.show_all()
|
menuitem.show_all()
|
||||||
|
|
||||||
def _add_network_menu_item(self, network):
|
def _add_device_menu_item(self, device):
|
||||||
menuitem = gtk.MenuItem()
|
if not self._is_wireless(device):
|
||||||
|
menuitem = gtk.RadioMenuItem(group=self.__radio_group)
|
||||||
|
if self._is_active(device):
|
||||||
|
menuitem.set_active(1)
|
||||||
|
else:
|
||||||
|
menuitem = gtk.MenuItem()
|
||||||
|
|
||||||
|
hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=6)
|
||||||
|
hbox.pack_start(self._get_icon(device), expand=gtk.FALSE, fill=gtk.FALSE, padding=6)
|
||||||
|
label = gtk.Label()
|
||||||
|
label.set_justify(gtk.JUSTIFY_LEFT)
|
||||||
|
label.set_text(self._get_device_name(device))
|
||||||
|
hbox.pack_start(label, expand=gtk.FALSE, fill=gtk.FALSE, padding=6)
|
||||||
|
menuitem.add(hbox)
|
||||||
|
hbox.show()
|
||||||
|
self._menu.append(menuitem)
|
||||||
|
tt = "IP: %d\nProduct Name: %s\nVendor: %s\nDevice Name: %s" % (device["nm.ip4"], device["pci.product"], device["info.vendor"], device["nm.name"] )
|
||||||
|
self._tooltips.set_tip(menuitem,tt)
|
||||||
|
menuitem.show_all()
|
||||||
|
|
||||||
|
def _add_network_menu_item(self, device, network, active_network):
|
||||||
|
menuitem = gtk.RadioMenuItem(group=self.__radio_group)
|
||||||
menuitem.set_right_justified(gtk.FALSE)
|
menuitem.set_right_justified(gtk.FALSE)
|
||||||
|
if active_network == gtk.TRUE:
|
||||||
|
menuitem.set_active(1)
|
||||||
|
|
||||||
hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=6)
|
hbox = gtk.HBox(homogeneous=gtk.FALSE, spacing=6)
|
||||||
menuitem.add(hbox)
|
menuitem.add(hbox)
|
||||||
label = gtk.Label(network["name"])
|
label = gtk.Label(network["name"])
|
||||||
@@ -68,20 +89,70 @@ class network_tray:
|
|||||||
label.show()
|
label.show()
|
||||||
hbox.pack_start(label,expand=gtk.TRUE, fill=gtk.TRUE)
|
hbox.pack_start(label,expand=gtk.TRUE, fill=gtk.TRUE)
|
||||||
progress = gtk.ProgressBar()
|
progress = gtk.ProgressBar()
|
||||||
progress.set_fraction(network["quality"])
|
progress.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
|
||||||
|
q = self._get_quality(device, network)
|
||||||
|
progress.set_fraction(q)
|
||||||
|
# progress.set_text("%s %%" % int(q*100))
|
||||||
progress.show()
|
progress.show()
|
||||||
hbox.pack_start(progress, expand=gtk.FALSE, fill=gtk.FALSE)
|
hbox.pack_start(progress, expand=gtk.FALSE, fill=gtk.FALSE)
|
||||||
icon = self._get_encrypted_icon()
|
icon = self._get_encrypted_icon()
|
||||||
if network["encrypted"] == 1:
|
if network["encrypted"] == 1:
|
||||||
icon.hide()
|
icon.hide()
|
||||||
|
hbox.pack_start(icon,expand=gtk.FALSE, fill=gtk.FALSE)
|
||||||
else:
|
else:
|
||||||
icon.show()
|
icon.show()
|
||||||
hbox.pack_start(icon,expand=gtk.FALSE, fill=gtk.FALSE)
|
|
||||||
hbox.show()
|
hbox.show()
|
||||||
self._menu.append(menuitem)
|
self._menu.append(menuitem)
|
||||||
|
tt = "Name: %s\nEncrypted: %d\nRate: %d\nFrequency: %f\nAddress: %s\nQuality: %d" % (network['name'], network['encrypted'], network['rate'],network['frequency'], network['address'], network['quality'])
|
||||||
|
self._tooltips.set_tip(menuitem,tt)
|
||||||
menuitem.show()
|
menuitem.show()
|
||||||
|
|
||||||
|
|
||||||
|
def _get_quality(self, device, network):
|
||||||
|
if network["quality"] == 0:
|
||||||
|
proc = "/proc/driver/aironet/%s/BSSList" % device["net.interface"]
|
||||||
|
import fileinput
|
||||||
|
for line in fileinput.input(proc):
|
||||||
|
dev_info = line.split()
|
||||||
|
if network["name"] in dev_info:
|
||||||
|
fileinput.close()
|
||||||
|
try:
|
||||||
|
qual = float(dev_info[4])
|
||||||
|
q = float(qual / 100)
|
||||||
|
return q
|
||||||
|
except ValueError:
|
||||||
|
return 0.0
|
||||||
|
fileinput.close()
|
||||||
|
else:
|
||||||
|
return float(network["quality"])
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
def _get_device_name(self, device):
|
||||||
|
if self._is_wireless(device):
|
||||||
|
if self._nm.number_wireless_devices() > 1:
|
||||||
|
return device["info.product"]
|
||||||
|
else:
|
||||||
|
return "Wireless Network"
|
||||||
|
else:
|
||||||
|
if self._nm.number_wired_devices() > 1:
|
||||||
|
return device["info.product"]
|
||||||
|
else:
|
||||||
|
return "Wired Network"
|
||||||
|
|
||||||
|
def _is_wireless(self,dev):
|
||||||
|
if dev["nm.type"] == self._nm.WIRELESS_DEVICE:
|
||||||
|
return gtk.TRUE
|
||||||
|
return gtk.FALSE
|
||||||
|
|
||||||
|
def _is_active(self, dev):
|
||||||
|
return dev["nm.status"] != self._nm.DISCONNECTED
|
||||||
|
|
||||||
|
def _number_wired_devices(self, devices):
|
||||||
|
return self._number_x_devices(devices, self._nm.WIRED_DEVICE)
|
||||||
|
|
||||||
|
def _number_wireless_devices(self, devices):
|
||||||
|
return self._number_x_devices(devices, self._nm.WIRELESS_DEVICE)
|
||||||
|
|
||||||
def _network_event(self, interface, signal_name,
|
def _network_event(self, interface, signal_name,
|
||||||
service, path, message):
|
service, path, message):
|
||||||
|
|
||||||
@@ -91,25 +162,34 @@ class network_tray:
|
|||||||
devices = self._nm.get_devices()
|
devices = self._nm.get_devices()
|
||||||
active_device = self._nm.get_active_device()
|
active_device = self._nm.get_active_device()
|
||||||
tt = ""
|
tt = ""
|
||||||
self._add_label_item("Network Connections")
|
|
||||||
for device in devices:
|
|
||||||
if device == active_device:
|
|
||||||
active = gtk.TRUE
|
|
||||||
else:
|
|
||||||
active = gtk.FALSE
|
|
||||||
|
|
||||||
self._add_device_menu_item(device, active)
|
wireless = gtk.FALSE
|
||||||
|
for device in devices:
|
||||||
|
|
||||||
|
if self._is_wireless(device) and wireless == gtk.FALSE:
|
||||||
|
wireless = gtk.TRUE
|
||||||
|
self._add_separator_item()
|
||||||
|
self._add_label_item("Wireless Networks")
|
||||||
|
else:
|
||||||
|
self._add_device_menu_item(device)
|
||||||
tt = "%s%s [%s]\n"%(tt,device["info.product"],device["nm.status"])
|
tt = "%s%s [%s]\n"%(tt,device["info.product"],device["nm.status"])
|
||||||
|
|
||||||
self._tooltips.set_tip(self._top_level_menu,tt)
|
self._tooltips.set_tip(self._top_level_menu,tt)
|
||||||
|
|
||||||
if active_device["nm.type"] == self._nm.WIRELESS_DEVICE:
|
if self._is_wireless(device):
|
||||||
self._add_separator_item()
|
for name, network in active_device["nm.networks"].iteritems():
|
||||||
self._add_label_item("Wireless Networks")
|
try:
|
||||||
for name, network in active_device["nm.networks"].iteritems():
|
if active_device["nm.active_network"] == name:
|
||||||
self._add_network_menu_item(network)
|
active_network = gtk.TRUE
|
||||||
|
else:
|
||||||
|
active_network = gtk.FALSE
|
||||||
|
except:
|
||||||
|
active_network = gtk.FALSE
|
||||||
|
self._add_network_menu_item(device,network,active_network)
|
||||||
|
|
||||||
|
if wireless == gtk.TRUE:
|
||||||
|
self._add_other_wireless_item()
|
||||||
|
|
||||||
self._current_icon = self._get_icon(active_device)
|
self._current_icon = self._get_icon(active_device)
|
||||||
|
|
||||||
self._current_icon.show()
|
self._current_icon.show()
|
||||||
@@ -170,7 +250,10 @@ class network_tray:
|
|||||||
self._top_level_menu.add(self._current_icon)
|
self._top_level_menu.add(self._current_icon)
|
||||||
self._menu_bar.show()
|
self._menu_bar.show()
|
||||||
self._top_level_menu.show()
|
self._top_level_menu.show()
|
||||||
self._menu.show()
|
self._menu.show()
|
||||||
|
|
||||||
|
self.__radio_group = gtk.RadioMenuItem()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
nt = network_tray()
|
nt = network_tray()
|
||||||
|
Reference in New Issue
Block a user