def _get_net_stats(): ifs = {} nets = gtop.netlist() for net in nets: netload = gtop.netload(net) ifs[net] = [netload.bytes_in, netload.bytes_out] nets.insert(0, "Net") return ifs, nets
def action_performed(self, binding): if self.page and self.page.is_visible(): if binding.action == g15driver.PREVIOUS_SELECTION and self.use_vnstat is True: if self.loadpage == 'vnstat_daily': self.gconf_client.set_string( self.gconf_key + "/vnstat_view", "vnstat_monthly") else: self.gconf_client.set_string( self.gconf_key + "/vnstat_view", "vnstat_daily") return True elif binding.action == g15driver.NEXT_SELECTION: if self.networkdevice is not None: # get all network devices self.net_data = gtop.netlist() # set network device id +1, to get next device idx = self.net_data.index(self.networkdevice) + 1 # if next device id is not present, take first device if idx >= len(self.net_data): idx = 0 self.gconf_client.set_string( self.gconf_key + "/networkdevice", self.net_data[idx]) return True
def show_preferences(parent, driver, gconf_client, gconf_key): widget_tree = gtk.Builder() widget_tree.add_from_file( os.path.join(os.path.dirname(__file__), "trafficstats.ui")) dialog = widget_tree.get_object("TrafficStats") # Resets the value of the use_vnstat flag if vnstat is not installed vnstat_installed = g15os.is_program_in_path('vnstat') if not vnstat_installed: gconf_client.set_bool("%s/use_vnstat" % gconf_key, False) # Displays a warning message to the user if vnstat is not installed warning = widget_tree.get_object("NoVnstatMessage") warning.set_visible(not vnstat_installed) # Disables the vnstat checkbox if vnstat is not installed use_vnstat = widget_tree.get_object('UseVnstat') use_vnstat.set_sensitive(vnstat_installed) g15uigconf.configure_checkbox_from_gconf(gconf_client, gconf_key + "/use_vnstat", "UseVnstat", vnstat_installed, widget_tree) ndevice = widget_tree.get_object("NetDevice") for netdev in gtop.netlist(): ndevice.append([netdev]) g15uigconf.configure_combo_from_gconf(gconf_client, gconf_key + "/networkdevice", "NetworkDevice", "lo", widget_tree) g15uigconf.configure_adjustment_from_gconf(gconf_client, gconf_key + "/refresh_interval", "RefreshingScale", 10.0, widget_tree) dialog.set_transient_for(parent) dialog.run() dialog.hide()