diff --git a/src/trayicon.py b/src/trayicon.py index 3ecd7df..0de29a1 100755 --- a/src/trayicon.py +++ b/src/trayicon.py @@ -73,52 +73,43 @@ def nm_menu(self): cards = self.cardinfo['cards'] for netcard in cards: connection_state = cards[netcard]['state']["connection"] + status_item = Gtk.MenuItem() + status_item.set_sensitive(False) + self.menu.append(status_item) if "wlan" not in netcard: if connection_state == "Connected": - wired_item = Gtk.MenuItem(_("Wired %s Connected") % cardnum) - wired_item.set_sensitive(False) - self.menu.append(wired_item) disconnect_item = Gtk.ImageMenuItem(_("Disable")) disconnect_item.connect("activate", self.disconnectcard, netcard) self.menu.append(disconnect_item) elif connection_state == "Disconnected": - notonline = Gtk.MenuItem(_("Wired %s Disconnected") % cardnum) - notonline.set_sensitive(False) - self.menu.append(notonline) wired_item = Gtk.MenuItem(_("Enable")) wired_item.connect("activate", self.connectcard, netcard) self.menu.append(wired_item) else: - disconnected = Gtk.MenuItem(_("Wired %s Unplug") % cardnum) - disconnected.set_sensitive(False) - self.menu.append(disconnected) + connection_state = "Unplug" + status_item.set_label(_(f"Wired {cardnum} {connection_state}")) cardnum += 1 - self.menu.append(Gtk.SeparatorMenuItem()) elif "wlan" in netcard: if connection_state == "Disabled": - wd_title = Gtk.MenuItem() - wd_title.set_label(_("WiFi %s Disabled") % wifinum) - wd_title.set_sensitive(False) - self.menu.append(wd_title) - enawifi = Gtk.MenuItem(_("Enable Wifi %s") % wifinum) - enawifi.connect("activate", self.enable_Wifi, netcard) - self.menu.append(enawifi) + wifi = { + "action": self.enable_Wifi, + "label": "Enable", + } elif connection_state == "Disconnected": - d_title = Gtk.MenuItem() - d_title.set_label(_("WiFi %s Disconnected") % wifinum) - d_title.set_sensitive(False) - self.menu.append(d_title) self.wifiListMenu(netcard, None, False, cards) - diswifi = Gtk.MenuItem(_("Disable Wifi %s") % wifinum) - diswifi.connect("activate", self.disable_Wifi, netcard) - self.menu.append(diswifi) + wifi = { + "action": self.disable_Wifi, + "label": "Disable", + } else: + connection_state = "Connected" + wifi = { + "action": self.disable_Wifi, + "label": "Disable", + } ssid = cards[netcard]['state']["ssid"] bar = cards[netcard]['info'][ssid][4] - wc_title = Gtk.MenuItem(_("WiFi %s Connected") % wifinum) - wc_title.set_sensitive(False) - self.menu.append(wc_title) connection_item = Gtk.ImageMenuItem(ssid) connection_item.set_image(self.wifi_signal_icon(bar)) connection_item.show() @@ -128,11 +119,12 @@ def nm_menu(self): self.menu.append(connection_item) self.menu.append(disconnect_item) self.wifiListMenu(netcard, ssid, True, cards) - diswifi = Gtk.MenuItem(_("Disable Wifi %s") % wifinum) - diswifi.connect("activate", self.disable_Wifi, netcard) - self.menu.append(diswifi) - self.menu.append(Gtk.SeparatorMenuItem()) + status_item.set_label(_(f"WiFi {wifinum} {connection_state}")) + action_item = Gtk.MenuItem(_(f"{wifi['label']} Wifi {wifinum}")) + action_item.connect("activate", wifi['action'], netcard) + self.menu.append(action_item) wifinum += 1 + self.menu.append(Gtk.SeparatorMenuItem()) if openrc: if not self.cardinfo['service']: