From 3f38ca5eea34c29d93514afff001a19e68808c3e Mon Sep 17 00:00:00 2001 From: Kevin Woo Date: Sun, 22 Mar 2009 02:59:25 -0400 Subject: [PATCH 1/9] Reapplied connection-summary branch to new 1.6 branch --- wicd/monitor.py | 3 +- wicd/translations.py | 4 + wicd/wicd-client.py | 237 +++++++++++++++++++++++++++++++------------ wicd/wicd-daemon.py | 1 + 4 files changed, 179 insertions(+), 66 deletions(-) diff --git a/wicd/monitor.py b/wicd/monitor.py index 7333724..9cdaa45 100755 --- a/wicd/monitor.py +++ b/wicd/monitor.py @@ -259,7 +259,8 @@ class ConnectionStatus(object): self.reconnect_tries = 0 info = [str(wifi_ip), str(wireless.GetCurrentNetwork(iwconfig)), str(self._get_printable_sig_strength()), - str(wireless.GetCurrentNetworkID(iwconfig))] + str(wireless.GetCurrentNetworkID(iwconfig)), + wireless.GetCurrentGitrate(iwconfig)] elif state == misc.WIRED: self.reconnect_tries = 0 info = [str(wired_ip)] diff --git a/wicd/translations.py b/wicd/translations.py index 308d620..489988f 100644 --- a/wicd/translations.py +++ b/wicd/translations.py @@ -81,8 +81,12 @@ language['wired_interface'] = _('Wired Interface') language['hidden_network'] = _('Hidden Network') language['hidden_network_essid'] = _('Hidden Network ESSID') language['connected_to_wireless'] = _('Connected to $A at $B (IP: $C)') +language['tray_connected_to_wireless'] = _('Wireless Network\n$A at $B\nSpeed: $C\nIP %D') language['connected_to_wired'] = _('Connected to wired network (IP: $A)') +language['tray_connected_to_wired'] = _('Wired Network\nIP: %A\n') language['not_connected'] = _('Not connected') +language['conn_info_wired'] = _('Wired\nIP: $A\nRX: $B KB/s\nTX: $C KB/s') +language['conn_info_wireless'] = _('Wireless\nSSID: $A\nSpeed $B\nIP: $C\nStrength: $D\nRX: $E KB/s\nTX: $F KB/s') language['no_wireless_networks_found'] = _('No wireless networks found.') language['killswitch_enabled'] = _('Wireless Kill Switch Enabled') language['key'] = _('Key') diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index 8cac87e..0b0037e 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -113,40 +113,87 @@ class TrayIcon(object): """ def __init__(self, animate): + self.cur_sndbytes = -1 + self.cur_rcvbytes = -1 + self.last_sndbytes = -1 + self.last_rcvbytes = -1 + self.max_snd_gain = 10000 + self.max_rcv_gain = 10000 + if USE_EGG: - self.tr = self.EggTrayIconGUI() + self.tr = self.EggTrayIconGUI(self) else: - self.tr = self.StatusTrayIconGUI() - self.icon_info = self.TrayConnectionInfo(self.tr, animate) + self.tr = self.StatusTrayIconGUI(self) + self.icon_info = self.TrayConnectionInfo(self, self.tr, animate) def is_embedded(self): if USE_EGG: raise NotImplementedError else: return self.tr.is_embedded() - + + def get_bandwidth_bytes(self): + dev_dir = '/sys/class/net/' + iface = daemon.GetCurrentInterface() + + for fldr in os.listdir(dev_dir): + if fldr == iface: + dev_dir = dev_dir + fldr + "/statistics/" + break + + try: + self.cur_rcvbytes = int(open(dev_dir + "rx_bytes", "r").read().strip()) + self.cur_sndbytes = int(open(dev_dir + "tx_bytes", "r").read().strip()) + except: + self.cur_sndbytes = -1 + self.cur.rcvbytes = -1 class TrayConnectionInfo(object): """ Class for updating the tray icon status. """ - def __init__(self, tr, animate=True): + def __init__(self, parent, tr, animate=True): """ Initialize variables needed for the icon status methods. """ self.last_strength = -2 - self.still_wired = False - self.network = '' self.tried_reconnect = False self.connection_lost_counter = 0 self.tr = tr - self.last_sndbytes = -1 - self.last_rcvbytes = -1 - self.max_snd_gain = 10000 - self.max_rcv_gain = 10000 self.animate = animate + self.parent = parent + + self.network_name = '' # SSID + self.network_type = 'none' # Wired/Wireless/None + self.network_str = '' # Signal Strength + self.network_addr = '0.0.0.0' # IP Address + self.network_br = '' # Bitrate + if DBUS_AVAIL: self.update_tray_icon() else: handle_no_dbus() self.set_not_connected_state() + """ Initial update of the tooltip """ + self.update_tooltip + + def update_tooltip(self): + if (self.network_type == "none"): + self.tr.set_tooltip(language['not_Connected']) + elif (self.network_type == "wireless"): + self.tr.set_tooltip(language['tray_connected_to_wireless'] + .replace('$A', self.network_name) + .replace('$B', self.network_str) + .replace('$C', self.network_br) + .replace('$D', self.network_addr)) + elif (self.network_type == "wired"): + self.tr.set_tooltip(language['tray_connected_to_wired'] + .replace('$A', self.network_addr)) + elif (self.network_type == "killswitch"): + self.tr.set_tooltip(language['not_connected'] + "(" + + language['killswitched_enabled'] + ")") + elif (self.network_type == "no_daemon"): + self.tr.set_tooltip(language['no_daemon_tooltip']) + + return True + @catchdbus def wired_profile_chooser(self): """ Launch the wired profile chooser. """ @@ -156,37 +203,37 @@ class TrayIcon(object): def set_wired_state(self, info): """ Sets the icon info for a wired state. """ wired_ip = info[0] + self.network_addr = str(info[0]) + self.network_type = "wired" self.tr.set_from_file(os.path.join(wpath.images, "wired.png")) - self.tr.set_tooltip(language['connected_to_wired'].replace('$A', - wired_ip)) - + self.update_tooltip() + @catchdbus def set_wireless_state(self, info): """ Sets the icon info for a wireless state. """ lock = '' - wireless_ip = info[0] - self.network = info[1] - strength = info[2] cur_net_id = int(info[3]) - sig_string = daemon.FormatSignalForPrinting(str(strength)) + sig_string = daemon.FormatSignalForPrinting(str(info[2])) + self.network_type = "wireless" + self.network_addr = str(info[0]) + self.network_name = info[1] + self.network_str = sig_string + self.network_br = info[4] + self.set_signal_image(int(info[2]), lock) if wireless.GetWirelessProperty(cur_net_id, "encryption"): lock = "-lock" - self.tr.set_tooltip(language['connected_to_wireless'] - .replace('$A', self.network) - .replace('$B', sig_string) - .replace('$C', str(wireless_ip))) - self.set_signal_image(int(strength), lock) + self.update_tooltip() def set_connecting_state(self, info): """ Sets the icon info for a connecting state. """ - if info[0] == 'wired' and len(info) == 1: - cur_network = language['wired_network'] - else: - cur_network = info[1] - self.tr.set_tooltip(language['connecting'] + " to " + - cur_network + "...") + self.network_type = info[0] + + if info[0] == 'wireless': + self.network_name = info[1] + + self.update_tooltip() self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png")) @catchdbus @@ -194,14 +241,13 @@ class TrayIcon(object): """ Set the icon info for the not connected state. """ self.tr.set_from_file(wpath.images + "no-signal.png") if not DBUS_AVAIL: - status = language['no_daemon_tooltip'] + self.network_type = "no_daemon" elif wireless.GetKillSwitchEnabled(): - status = (language['not_connected'] + " (" + - language['killswitch_enabled'] + ")") + self.network_type = "killswitch" else: - status = language['not_connected'] - self.tr.set_tooltip(status) + self.network_type = "none" + self.update_tooltip() @catchdbus def update_tray_icon(self, state=None, info=None): """ Updates the tray icon and current connection status. """ @@ -227,7 +273,8 @@ class TrayIcon(object): def set_signal_image(self, wireless_signal, lock): """ Sets the tray icon image for an active wireless connection. """ if self.animate: - prefix = self.get_bandwidth_state() + TrayIcon.get_bandwidth_bytes(self.parent) + prefix = self.get_bandwidth_activity() else: prefix = 'idle-' if daemon.GetSignalDisplayType() == 0: @@ -253,40 +300,26 @@ class TrayIcon(object): self.tr.set_from_file(img_file) @catchdbus - def get_bandwidth_state(self): + def get_bandwidth_activity(self): """ Determines what network activity state we are in. """ transmitting = False receiving = False - dev_dir = '/sys/class/net/' - wiface = daemon.GetWirelessInterface() - for fldr in os.listdir(dev_dir): - if fldr == wiface: - dev_dir = dev_dir + fldr + "/statistics/" - break - try: - rcvbytes = int(open(dev_dir + "rx_bytes", "r").read().strip()) - sndbytes = int(open(dev_dir + "tx_bytes", "r").read().strip()) - except IOError: - sndbytes = None - rcvbytes = None - - if not rcvbytes or not sndbytes: - return 'idle-' - # Figure out receiving data info. - activity = self.is_network_active(rcvbytes, self.max_rcv_gain, - self.last_rcvbytes) + activity = self.is_network_active(self.parent.cur_rcvbytes, + self.parent.max_rcv_gain, + self.parent.last_rcvbytes) receiving = activity[0] - self.max_rcv_gain = activity[1] - self.last_rcvbytes = activity[2] + self.parent.max_rcv_gain = activity[1] + self.parent.last_rcvbytes = activity[2] # Figure out out transmitting data info. - activity = self.is_network_active(sndbytes, self.max_snd_gain, - self.last_sndbytes) + activity = self.is_network_active(self.parent.cur_sndbytes, + self.parent.max_snd_gain, + self.parent.last_sndbytes) transmitting = activity[0] - self.max_snd_gain = activity[1] - self.last_sndbytes = activity[2] + self.parent.max_snd_gain = activity[1] + self.parent.last_sndbytes = activity[2] if transmitting and receiving: return 'both-' @@ -332,7 +365,7 @@ class TrayIcon(object): tray icons. """ - def __init__(self): + def __init__(self, parent): menu = """ @@ -340,6 +373,7 @@ class TrayIcon(object): + @@ -349,6 +383,9 @@ class TrayIcon(object): actions = [ ('Menu', None, 'Menu'), ('Connect', gtk.STOCK_CONNECT, "Connect"), + ('Info', gtk.STOCK_INFO, "_Connection Info", None, + 'Information about the current connection', + self.on_conn_info), ('About', gtk.STOCK_ABOUT, '_About...', None, 'About wicd-tray-icon', self.on_about), ('Quit',gtk.STOCK_QUIT,'_Quit',None,'Quit wicd-tray-icon', @@ -367,6 +404,11 @@ class TrayIcon(object): net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/") net_menuitem.connect("activate", self.on_net_menu_activate) + self.parent = parent + self.time = 2 + self.cont = 'Stop' + self.conn_info_txt = '' + def tray_scan_started(self): """ Callback for when a wireless scan is started. """ if not DBUS_AVAIL: return @@ -400,6 +442,71 @@ class TrayIcon(object): dialog.set_website('http://wicd.net') dialog.run() dialog.destroy() + + def on_conn_info(self, data=None): + """ Opens the Connection Information Dialog """ + window = gtk.Dialog("Wicd Connection Info", None, 0, (gtk.STOCK_OK, gtk.RESPONSE_CLOSE)) + + msg = gtk.Label() + msg.show() + + """ Start updates """ + self.cont = 'Go' + gobject.timeout_add(5000, self.update_conn_info_win, msg) + self.update_conn_info_win(msg) + + """ Setup Window """ + content = window.get_content_area() + content.pack_start(msg, True, True, 0) + content.visible = True + + window.run() + + """ Destroy window and stop updates """ + window.destroy() + self.cont = 'Stop' + + def update_conn_info_win(self, msg): + + if (self.cont == "Stop"): + return False + + [state, info] = daemon.GetConnectionStatus() + [rx, tx] = self.get_current_bandwidth() + + if state == misc.WIRED: + text = (language['conn_info_wired'] + .replace('$A', str(info[0])) + .replace('$B', str(rx)) + .replace('$C', str(tx))) + elif state == misc.WIRELESS: + text = (language['conn_info_wireless'] + .replace('$A', info[1]) + .replace('$B', info[4]) + .replace('$C', str(info[0])) + .replace('$D', daemon.FormatSignalForPrinting(str(info[2]))) + .replace('$E', str(rx)) + .replace('$F', str(tx))) + elif state == misc.CONNECTING: + text = (language['connecting']) + elif state in (misc.SUSPENDED, misc.NOT_CONNECTED): + text = (language['not_connected']) + + msg.set_text(text) + return True + + def get_current_bandwidth(self): + self.parent.get_bandwidth_bytes() + rxb = self.parent.cur_rcvbytes - self.parent.last_rcvbytes + txb = self.parent.cur_sndbytes - self.parent.last_sndbytes + + self.parent.last_rcvbytes = self.parent.cur_rcvbytes + self.parent.last_sndbytes = self.parent.cur_sndbytes + + rx_rate = float(rxb / (self.time * 1024)) + tx_rate = float(txb / (self.time * 1024)) + + return (rx_rate, tx_rate) def _add_item_to_menu(self, net_menu, lbl, type_, n_id, is_connecting, is_active): @@ -572,9 +679,9 @@ class TrayIcon(object): for machines running versions of GTK < 2.10. """ - def __init__(self): + def __init__(self, parent): """Initializes the tray icon""" - TrayIcon.TrayIconGUI.__init__(self) + TrayIcon.TrayIconGUI.__init__(self, parent) self.tooltip = gtk.Tooltips() self.eb = gtk.EventBox() self.tray = egg.trayicon.TrayIcon("WicdTrayIcon") @@ -616,8 +723,8 @@ class TrayIcon(object): Uses gtk.StatusIcon to implement a tray icon. """ - def __init__(self): - TrayIcon.TrayIconGUI.__init__(self) + def __init__(self, parent): + TrayIcon.TrayIconGUI.__init__(self, parent) gtk.StatusIcon.__init__(self) self.current_icon_path = '' diff --git a/wicd/wicd-daemon.py b/wicd/wicd-daemon.py index 6525f27..07b310c 100644 --- a/wicd/wicd-daemon.py +++ b/wicd/wicd-daemon.py @@ -549,6 +549,7 @@ class WicdDaemon(dbus.service.Object): info[1] = essid info[2] = signal strength info[3] = internal networkid + info[4] = bitrate SUSPENDED - info[0] = "" From e7ee6273c5112ab757e36155c4567bfed2407601 Mon Sep 17 00:00:00 2001 From: Kevin Woo Date: Sun, 22 Mar 2009 03:13:02 -0400 Subject: [PATCH 2/9] Fixed bugs from typos. --- wicd/monitor.py | 2 +- wicd/translations.py | 4 ++-- wicd/wicd-client.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wicd/monitor.py b/wicd/monitor.py index 9cdaa45..f9724b0 100755 --- a/wicd/monitor.py +++ b/wicd/monitor.py @@ -260,7 +260,7 @@ class ConnectionStatus(object): info = [str(wifi_ip), str(wireless.GetCurrentNetwork(iwconfig)), str(self._get_printable_sig_strength()), str(wireless.GetCurrentNetworkID(iwconfig)), - wireless.GetCurrentGitrate(iwconfig)] + wireless.GetCurrentBitrate(iwconfig)] elif state == misc.WIRED: self.reconnect_tries = 0 info = [str(wired_ip)] diff --git a/wicd/translations.py b/wicd/translations.py index 489988f..c298791 100644 --- a/wicd/translations.py +++ b/wicd/translations.py @@ -81,9 +81,9 @@ language['wired_interface'] = _('Wired Interface') language['hidden_network'] = _('Hidden Network') language['hidden_network_essid'] = _('Hidden Network ESSID') language['connected_to_wireless'] = _('Connected to $A at $B (IP: $C)') -language['tray_connected_to_wireless'] = _('Wireless Network\n$A at $B\nSpeed: $C\nIP %D') +language['tray_connected_to_wireless'] = _('Wireless Network\n$A at $B\nSpeed: $C\nIP $D') language['connected_to_wired'] = _('Connected to wired network (IP: $A)') -language['tray_connected_to_wired'] = _('Wired Network\nIP: %A\n') +language['tray_connected_to_wired'] = _('Wired Network\nIP: $A') language['not_connected'] = _('Not connected') language['conn_info_wired'] = _('Wired\nIP: $A\nRX: $B KB/s\nTX: $C KB/s') language['conn_info_wireless'] = _('Wireless\nSSID: $A\nSpeed $B\nIP: $C\nStrength: $D\nRX: $E KB/s\nTX: $F KB/s') diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index 0b0037e..a94e1e9 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -146,7 +146,7 @@ class TrayIcon(object): self.cur_sndbytes = int(open(dev_dir + "tx_bytes", "r").read().strip()) except: self.cur_sndbytes = -1 - self.cur.rcvbytes = -1 + self.cur_rcvbytes = -1 class TrayConnectionInfo(object): """ Class for updating the tray icon status. """ @@ -176,7 +176,7 @@ class TrayIcon(object): def update_tooltip(self): if (self.network_type == "none"): - self.tr.set_tooltip(language['not_Connected']) + self.tr.set_tooltip(language['not_connected']) elif (self.network_type == "wireless"): self.tr.set_tooltip(language['tray_connected_to_wireless'] .replace('$A', self.network_name) From 76d5bc935a093080fa789bb5634dadde72435970 Mon Sep 17 00:00:00 2001 From: Kevin Woo Date: Fri, 24 Apr 2009 13:26:50 -0400 Subject: [PATCH 3/9] Cleaned up docstrings and aligned connection summary window text. --- wicd/translations.py | 4 ++-- wicd/wicd-client.py | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/wicd/translations.py b/wicd/translations.py index c298791..c690484 100644 --- a/wicd/translations.py +++ b/wicd/translations.py @@ -85,8 +85,8 @@ language['tray_connected_to_wireless'] = _('Wireless Network\n$A at $B\nSpeed: $ language['connected_to_wired'] = _('Connected to wired network (IP: $A)') language['tray_connected_to_wired'] = _('Wired Network\nIP: $A') language['not_connected'] = _('Not connected') -language['conn_info_wired'] = _('Wired\nIP: $A\nRX: $B KB/s\nTX: $C KB/s') -language['conn_info_wireless'] = _('Wireless\nSSID: $A\nSpeed $B\nIP: $C\nStrength: $D\nRX: $E KB/s\nTX: $F KB/s') +language['conn_info_wired'] = _('Wired\nIP:\t\t$A\nRX:\t\t$B KB/s\nTX:\t\t$C KB/s\n\n\n') +language['conn_info_wireless'] = _('Wireless\nSSID:\t$A\nSpeed\t$B\nIP:\t\t$C\nStrength:\t$D\nRX:\t\t$E KB/s\nTX:\t\t$F KB/s') language['no_wireless_networks_found'] = _('No wireless networks found.') language['killswitch_enabled'] = _('Wireless Kill Switch Enabled') language['key'] = _('Key') diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index a94e1e9..ee04674 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -133,6 +133,7 @@ class TrayIcon(object): return self.tr.is_embedded() def get_bandwidth_bytes(self): + """ Gets the amount of byte sent sine the last time I checked """ dev_dir = '/sys/class/net/' iface = daemon.GetCurrentInterface() @@ -151,7 +152,7 @@ class TrayIcon(object): class TrayConnectionInfo(object): """ Class for updating the tray icon status. """ def __init__(self, parent, tr, animate=True): - """ Initialize variables needed for the icon status methods. """ + # Initialize variables needed for the icon status methods. self.last_strength = -2 self.tried_reconnect = False self.connection_lost_counter = 0 @@ -171,10 +172,13 @@ class TrayIcon(object): handle_no_dbus() self.set_not_connected_state() - """ Initial update of the tooltip """ - self.update_tooltip + # Initial update of the tooltip + self.update_tooltip() def update_tooltip(self): + """ + Updates the trayicon tooltip based on current connection status + """ if (self.network_type == "none"): self.tr.set_tooltip(language['not_connected']) elif (self.network_type == "wireless"): @@ -405,7 +409,7 @@ class TrayIcon(object): net_menuitem.connect("activate", self.on_net_menu_activate) self.parent = parent - self.time = 2 + self.time = 2 # Time between updates self.cont = 'Stop' self.conn_info_txt = '' @@ -450,24 +454,24 @@ class TrayIcon(object): msg = gtk.Label() msg.show() - """ Start updates """ + # Start updates self.cont = 'Go' gobject.timeout_add(5000, self.update_conn_info_win, msg) self.update_conn_info_win(msg) - """ Setup Window """ + # Setup Window content = window.get_content_area() content.pack_start(msg, True, True, 0) content.visible = True window.run() - """ Destroy window and stop updates """ + # Destroy window and stop updates window.destroy() self.cont = 'Stop' def update_conn_info_win(self, msg): - + """ Updates the information in the connection summary window """ if (self.cont == "Stop"): return False @@ -496,6 +500,10 @@ class TrayIcon(object): return True def get_current_bandwidth(self): + """ + Calculates the current bandwidth based on sent/received bytes + divided over time. Unit is in KB/s + """ self.parent.get_bandwidth_bytes() rxb = self.parent.cur_rcvbytes - self.parent.last_rcvbytes txb = self.parent.cur_sndbytes - self.parent.last_sndbytes From 0d4c924790712758040c3285380fb0954e495970 Mon Sep 17 00:00:00 2001 From: Kevin Woo Date: Sun, 3 May 2009 04:30:57 -0400 Subject: [PATCH 4/9] Fixed the width of the connection summary window. Uses tables now. All information updated every couple of seconds. --- wicd/translations.py | 6 ++-- wicd/wicd-client.py | 65 +++++++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/wicd/translations.py b/wicd/translations.py index c690484..9971047 100644 --- a/wicd/translations.py +++ b/wicd/translations.py @@ -85,8 +85,10 @@ language['tray_connected_to_wireless'] = _('Wireless Network\n$A at $B\nSpeed: $ language['connected_to_wired'] = _('Connected to wired network (IP: $A)') language['tray_connected_to_wired'] = _('Wired Network\nIP: $A') language['not_connected'] = _('Not connected') -language['conn_info_wired'] = _('Wired\nIP:\t\t$A\nRX:\t\t$B KB/s\nTX:\t\t$C KB/s\n\n\n') -language['conn_info_wireless'] = _('Wireless\nSSID:\t$A\nSpeed\t$B\nIP:\t\t$C\nStrength:\t$D\nRX:\t\t$E KB/s\nTX:\t\t$F KB/s') +language['conn_info_wired_labels'] = _('Wired\nIP:\nRX:\nTX:\n\n\n') +language['conn_info_wireless_labels'] = _('Wireless\nSSID:\nSpeed:\nIP:\nStrength:\nRX:\nTX:') +language['conn_info_wired'] = _('\n$A\n$B KB/s\n$C KB/s\n\n\n') +language['conn_info_wireless'] = _('\n$A\n$B\n$C\n$D\n$E KB/s\n$F KB/s') language['no_wireless_networks_found'] = _('No wireless networks found.') language['killswitch_enabled'] = _('Wireless Kill Switch Enabled') language['key'] = _('Key') diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index ee04674..0b0ef5d 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -451,52 +451,73 @@ class TrayIcon(object): """ Opens the Connection Information Dialog """ window = gtk.Dialog("Wicd Connection Info", None, 0, (gtk.STOCK_OK, gtk.RESPONSE_CLOSE)) - msg = gtk.Label() - msg.show() + # Create labels + self.label = gtk.Label() + self.data = gtk.Label() + self.label.show() + self.data.show() + self.list = [] + self.list.append(self.data) + self.list.append(self.label) + + # Setup table + table = gtk.Table(1,2) + table.set_col_spacings(12) + table.attach(self.label, 0, 1, 0, 1) + table.attach(self.data, 1, 2, 0 ,1) + + # Setup Window + content = window.get_content_area() + content.pack_start(table, True, True, 0) + content.show_all() # Start updates self.cont = 'Go' - gobject.timeout_add(5000, self.update_conn_info_win, msg) - self.update_conn_info_win(msg) + gobject.timeout_add(5000, self.update_conn_info_win, self.list) + self.update_conn_info_win(self.list) - # Setup Window - content = window.get_content_area() - content.pack_start(msg, True, True, 0) - content.visible = True - window.run() # Destroy window and stop updates window.destroy() self.cont = 'Stop' - def update_conn_info_win(self, msg): + def update_conn_info_win(self, list): """ Updates the information in the connection summary window """ if (self.cont == "Stop"): return False [state, info] = daemon.GetConnectionStatus() [rx, tx] = self.get_current_bandwidth() - + + # Choose info for the data if state == misc.WIRED: text = (language['conn_info_wired'] - .replace('$A', str(info[0])) - .replace('$B', str(rx)) - .replace('$C', str(tx))) + .replace('$A', str(info[0])) #IP + .replace('$B', str(rx)) #RX + .replace('$C', str(tx))) #TX elif state == misc.WIRELESS: text = (language['conn_info_wireless'] - .replace('$A', info[1]) - .replace('$B', info[4]) - .replace('$C', str(info[0])) + .replace('$A', str(info[1])) #SSID + .replace('$B', str(info[4])) #Speed + .replace('$C', str(info[0])) #IP .replace('$D', daemon.FormatSignalForPrinting(str(info[2]))) .replace('$E', str(rx)) .replace('$F', str(tx))) - elif state == misc.CONNECTING: - text = (language['connecting']) - elif state in (misc.SUSPENDED, misc.NOT_CONNECTED): - text = (language['not_connected']) + else: + text = '' - msg.set_text(text) + # Choose info for the labels + self.list[0].set_text(text) + if state == misc.WIRED: + self.list[1].set_text(language['conn_info_wired_labels']) + elif state == misc.WIRELESS: + self.list[1].set_text(language['conn_info_wireless_labels']) + elif state == misc.CONNECTING: + self.list[1].set_text(language['connecting']) + elif state in (misc.SUSPENDED, misc.NOT_CONNECTED): + self.list[1].set_text(language['not_connected']) + return True def get_current_bandwidth(self): From ca7473d3f2ca6b50f754089ecd6a2b5434c1b539 Mon Sep 17 00:00:00 2001 From: Kevin Woo Date: Sun, 3 May 2009 12:34:43 -0400 Subject: [PATCH 5/9] Added some padding to keep the height constant. --- wicd/translations.py | 2 ++ wicd/wicd-client.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wicd/translations.py b/wicd/translations.py index 9971047..82fad11 100644 --- a/wicd/translations.py +++ b/wicd/translations.py @@ -89,6 +89,8 @@ language['conn_info_wired_labels'] = _('Wired\nIP:\nRX:\nTX:\n\n\n') language['conn_info_wireless_labels'] = _('Wireless\nSSID:\nSpeed:\nIP:\nStrength:\nRX:\nTX:') language['conn_info_wired'] = _('\n$A\n$B KB/s\n$C KB/s\n\n\n') language['conn_info_wireless'] = _('\n$A\n$B\n$C\n$D\n$E KB/s\n$F KB/s') +language['conn_info_not_connected'] = _('\n\nNot Connected\n\n\n\n') +language['conn_info_connecting'] = _('\n\nConnecting...\n\n\n\n') language['no_wireless_networks_found'] = _('No wireless networks found.') language['killswitch_enabled'] = _('Wireless Kill Switch Enabled') language['key'] = _('Key') diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index 0b0ef5d..1b92771 100755 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -514,9 +514,9 @@ class TrayIcon(object): elif state == misc.WIRELESS: self.list[1].set_text(language['conn_info_wireless_labels']) elif state == misc.CONNECTING: - self.list[1].set_text(language['connecting']) + self.list[1].set_text(language['conn_info_connecting']) elif state in (misc.SUSPENDED, misc.NOT_CONNECTED): - self.list[1].set_text(language['not_connected']) + self.list[1].set_text(language['conn_info_not_connected']) return True From 75d689d26929510e1c35616a16ac5ed1ec936008 Mon Sep 17 00:00:00 2001 From: Adam Blackburn Date: Wed, 12 Aug 2009 23:23:30 -0500 Subject: [PATCH 6/9] merged connection-info and 1.6. wicd-client working --- wicd/translations.py | 3 - wicd/wicd-client.py | 153 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 130 insertions(+), 26 deletions(-) diff --git a/wicd/translations.py b/wicd/translations.py index 9fbcde5..1cfd340 100644 --- a/wicd/translations.py +++ b/wicd/translations.py @@ -57,7 +57,6 @@ def get_gettext(): # Generated automatically on Sun, 05 Jul 2009 13:51:18 CDT _ = get_gettext() language = {} -<<<<<<< TREE language['connect'] = _('Connect') language['ip'] = _('IP') language['netmask'] = _('Netmask') @@ -236,7 +235,6 @@ language['ok'] = _('OK') language['cancel'] = _('Cancel') -======= language['resetting_ip_address'] = _('''Resetting IP address...''') language['prefs_help'] = _('''Preferences dialog''') language['no_dhcp_offers'] = _('''Connection Failed: No DHCP offers received.''') @@ -397,4 +395,3 @@ language['access_denied'] = _('''Unable to contact the Wicd daemon due to an acc language['disconnecting_active'] = _('''Disconnecting active connections...''') language['access_denied_wc'] = _('''ERROR: wicd-curses was denied access to the wicd daemon: please check that your user is in the "$A" group.''') language['post_disconnect_script'] = _('''Run post-disconnect script''') ->>>>>>> MERGE-SOURCE diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index f62e244..c45bc9d 100644 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -253,7 +253,7 @@ class TrayIcon(object): self.network_type = "wired" self.tr.set_from_file(os.path.join(wpath.images, "wired.png")) # status_string = language['connected_to_wired'].replace('$A', - wired_ip) + #wired_ip) # self.tr.set_tooltip(status_string) self._show_notification(language['wired_network'], language['connection_established'], @@ -280,9 +280,9 @@ class TrayIcon(object): if wireless.GetWirelessProperty(cur_net_id, "encryption"): lock = "-lock" # status_string = (language['connected_to_wireless'] - .replace('$A', self.network) - .replace('$B', sig_string) - .replace('$C', str(wireless_ip))) + #.replace('$A', self.network) + # .replace('$B', sig_string) + # .replace('$C', str(wireless_ip))) #self.tr.set_tooltip(status_string) self.set_signal_image(int(strength), lock) self._show_notification(self.network, @@ -361,7 +361,8 @@ class TrayIcon(object): def set_signal_image(self, wireless_signal, lock): """ Sets the tray icon image for an active wireless connection. """ if self.animate: - prefix = self.get_bandwidth_state() + TrayIcon.get_bandwidth_bytes(self.parent) + prefix = self.get_bandwidth_activity() else: prefix = 'idle-' if daemon.GetSignalDisplayType() == 0: @@ -387,7 +388,7 @@ class TrayIcon(object): self.tr.set_from_file(img_file) @catchdbus - def get_bandwidth_state(self): + def get_bandwidth_activity(self): """ Determines what network activity state we are in. """ transmitting = False receiving = False @@ -409,18 +410,20 @@ class TrayIcon(object): return 'idle-' # Figure out receiving data info. - activity = self.is_network_active(rcvbytes, self.max_rcv_gain, - self.last_rcvbytes) + activity = self.is_network_active(self.parent.cur_rcvbytes, + self.parent.max_rcv_gain, + self.parent.last_rcvbytes) receiving = activity[0] - self.max_rcv_gain = activity[1] - self.last_rcvbytes = activity[2] + self.parent.max_rcv_gain = activity[1] + self.parent.last_rcvbytes = activity[2] # Figure out out transmitting data info. - activity = self.is_network_active(sndbytes, self.max_snd_gain, - self.last_sndbytes) + activity = self.is_network_active(self.parent.cur_sndbytes, + self.parent.max_snd_gain, + self.parent.last_sndbytes) transmitting = activity[0] - self.max_snd_gain = activity[1] - self.last_sndbytes = activity[2] + self.parent.max_snd_gain = activity[1] + self.parent.last_sndbytes = activity[2] if transmitting and receiving: return 'both-' @@ -466,7 +469,7 @@ class TrayIcon(object): tray icons. """ - def __init__(self): + def __init__(self, parent): menu = """ @@ -474,6 +477,7 @@ class TrayIcon(object): + @@ -483,6 +487,9 @@ class TrayIcon(object): actions = [ ('Menu', None, 'Menu'), ('Connect', gtk.STOCK_CONNECT, "Connect"), + ('Info', gtk.STOCK_INFO, "_Connection Info", None, + 'Information about the current connection', + self.on_conn_info), ('About', gtk.STOCK_ABOUT, '_About...', None, 'About wicd-tray-icon', self.on_about), ('Quit',gtk.STOCK_QUIT,'_Quit',None,'Quit wicd-tray-icon', @@ -501,6 +508,11 @@ class TrayIcon(object): net_menuitem = self.manager.get_widget("/Menubar/Menu/Connect/") net_menuitem.connect("activate", self.on_net_menu_activate) + self.parent = parent + self.time = 2 # Time between updates + self.cont = 'Stop' + self.conn_info_txt = '' + def tray_scan_started(self): """ Callback for when a wireless scan is started. """ if not DBUS_AVAIL: return @@ -534,6 +546,96 @@ class TrayIcon(object): dialog.set_website('http://wicd.net') dialog.run() dialog.destroy() + + def on_conn_info(self, data=None): + """ Opens the Connection Information Dialog """ + window = gtk.Dialog("Wicd Connection Info", None, 0, (gtk.STOCK_OK, gtk.RESPONSE_CLOSE)) + + # Create labels + self.label = gtk.Label() + self.data = gtk.Label() + self.label.show() + self.data.show() + self.list = [] + self.list.append(self.data) + self.list.append(self.label) + + # Setup table + table = gtk.Table(1,2) + table.set_col_spacings(12) + table.attach(self.label, 0, 1, 0, 1) + table.attach(self.data, 1, 2, 0 ,1) + + # Setup Window + content = window.get_content_area() + content.pack_start(table, True, True, 0) + content.show_all() + + # Start updates + self.cont = 'Go' + gobject.timeout_add(5000, self.update_conn_info_win, self.list) + self.update_conn_info_win(self.list) + + window.run() + + # Destroy window and stop updates + window.destroy() + self.cont = 'Stop' + + def update_conn_info_win(self, list): + """ Updates the information in the connection summary window """ + if (self.cont == "Stop"): + return False + + [state, info] = daemon.GetConnectionStatus() + [rx, tx] = self.get_current_bandwidth() + + # Choose info for the data + if state == misc.WIRED: + text = (language['conn_info_wired'] + .replace('$A', str(info[0])) #IP + .replace('$B', str(rx)) #RX + .replace('$C', str(tx))) #TX + elif state == misc.WIRELESS: + text = (language['conn_info_wireless'] + .replace('$A', str(info[1])) #SSID + .replace('$B', str(info[4])) #Speed + .replace('$C', str(info[0])) #IP + .replace('$D', daemon.FormatSignalForPrinting(str(info[2]))) + .replace('$E', str(rx)) + .replace('$F', str(tx))) + else: + text = '' + + # Choose info for the labels + self.list[0].set_text(text) + if state == misc.WIRED: + self.list[1].set_text(language['conn_info_wired_labels']) + elif state == misc.WIRELESS: + self.list[1].set_text(language['conn_info_wireless_labels']) + elif state == misc.CONNECTING: + self.list[1].set_text(language['conn_info_connecting']) + elif state in (misc.SUSPENDED, misc.NOT_CONNECTED): + self.list[1].set_text(language['conn_info_not_connected']) + + return True + + def get_current_bandwidth(self): + """ + Calculates the current bandwidth based on sent/received bytes + divided over time. Unit is in KB/s + """ + self.parent.get_bandwidth_bytes() + rxb = self.parent.cur_rcvbytes - self.parent.last_rcvbytes + txb = self.parent.cur_sndbytes - self.parent.last_sndbytes + + self.parent.last_rcvbytes = self.parent.cur_rcvbytes + self.parent.last_sndbytes = self.parent.cur_sndbytes + + rx_rate = float(rxb / (self.time * 1024)) + tx_rate = float(txb / (self.time * 1024)) + + return (rx_rate, tx_rate) def _add_item_to_menu(self, net_menu, lbl, type_, n_id, is_connecting, is_active): @@ -598,14 +700,19 @@ class TrayIcon(object): signal_img = 'signal-25.png' return wpath.images + signal_img + @catchdbus def on_net_menu_activate(self, item): """ Trigger a background scan to populate the network menu. - Clear the network menu, and schedule a method to be - called in .8 seconds to trigger a scan if the menu - is still being moused over. + Called when the network submenu is moused over. We + sleep briefly, clear pending gtk events, and if + we're still being moused over we trigger a scan. + This is to prevent scans when the user is just + mousing past the menu to select another menu item. """ + def dummy(x=None): pass + if self._is_scanning: return True @@ -618,7 +725,7 @@ class TrayIcon(object): while gtk.events_pending(): gtk.main_iteration() if item.state != gtk.STATE_PRELIGHT: - return False + return True wireless.Scan(False) return False @@ -706,9 +813,9 @@ class TrayIcon(object): for machines running versions of GTK < 2.10. """ - def __init__(self): + def __init__(self, parent): """Initializes the tray icon""" - TrayIcon.TrayIconGUI.__init__(self) + TrayIcon.TrayIconGUI.__init__(self, parent) self.tooltip = gtk.Tooltips() self.eb = gtk.EventBox() self.tray = egg.trayicon.TrayIcon("WicdTrayIcon") @@ -762,8 +869,8 @@ class TrayIcon(object): Uses gtk.StatusIcon to implement a tray icon. """ - def __init__(self): - TrayIcon.TrayIconGUI.__init__(self) + def __init__(self, parent): + TrayIcon.TrayIconGUI.__init__(self, parent) gtk.StatusIcon.__init__(self) self.current_icon_path = '' From 2663f73f67a143c0c5a8ac5d0213f69d7f2c840b Mon Sep 17 00:00:00 2001 From: Adam Blackburn Date: Thu, 13 Aug 2009 11:45:47 -0500 Subject: [PATCH 7/9] modified bitrate regex to fit more cases --- wicd/wnettools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wicd/wnettools.py b/wicd/wnettools.py index a94617d..40bdf47 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -59,7 +59,7 @@ wpa2_pattern = re.compile('(WPA2)', _re_mode) #iwconfig-only regular expressions. ip_pattern = re.compile(r'inet [Aa]d?dr[^.]*:([^.]*\.[^.]*\.[^.]*\.[0-9]*)', re.S) bssid_pattern = re.compile('.*Access Point: (([0-9A-Z]{2}:){5}[0-9A-Z]{2})', _re_mode) -bitrate_pattern = re.compile('.*Bit Rate=(.*?/s)', _re_mode) +bitrate_pattern = re.compile('.*Bit Rate[=:](.*?/s)', _re_mode) opmode_pattern = re.compile('.*Mode:(.*?) ', _re_mode) authmethods_pattern = re.compile('.*Authentication capabilities :\n(.*?)Current', _re_mode) From 814d58d2e7da30316ea9fe168c38c21c6d085988 Mon Sep 17 00:00:00 2001 From: Adam Blackburn Date: Fri, 14 Aug 2009 09:01:32 -0500 Subject: [PATCH 8/9] added missing stuff --- in/wpath.py.in | 1 + 1 file changed, 1 insertion(+) create mode 120000 in/wpath.py.in diff --git a/in/wpath.py.in b/in/wpath.py.in new file mode 120000 index 0000000..920fa33 --- /dev/null +++ b/in/wpath.py.in @@ -0,0 +1 @@ +wicd=wpath.py.in \ No newline at end of file From 6ae2b5706ea3a38acf5b2394665e1b99ecca15f5 Mon Sep 17 00:00:00 2001 From: Adam Blackburn Date: Fri, 14 Aug 2009 22:09:04 -0500 Subject: [PATCH 9/9] changed tray tooltip back to old one --- wicd/wicd-client.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wicd/wicd-client.py b/wicd/wicd-client.py index c45bc9d..81e9353 100644 --- a/wicd/wicd-client.py +++ b/wicd/wicd-client.py @@ -210,11 +210,10 @@ class TrayIcon(object): if (self.network_type == "none"): self.tr.set_tooltip(language['not_connected']) elif (self.network_type == "wireless"): - self.tr.set_tooltip(language['tray_connected_to_wireless'] + self.tr.set_tooltip(language['connected_to_wireless'] .replace('$A', self.network_name) .replace('$B', self.network_str) - .replace('$C', self.network_br) - .replace('$D', self.network_addr)) + .replace('$C', self.network_addr)) elif (self.network_type == "wired"): self.tr.set_tooltip(language['tray_connected_to_wired'] .replace('$A', self.network_addr))