feat: wireless network interface selector

This commit is contained in:
Alfredo Monclus committed 2026-03-08 12:13:51 -03:00
1 parent 33c11992f0
commit ee0b5f00e6
2 files changed
+32 -4

No files matched your search

+11 -1
View File
@@ -1,5 +1,4 @@
# This is the backend of the UI panel that communicates to sdbus-networkmanager
# TODO device selection/swtichability
# Alfredo Monclus (alfrix) 2024
import logging
import subprocess
@@ -394,3 +393,14 @@ class SdbusNm:
def enable_monitoring(self, enable):
self.monitor_connection = enable
def set_wlan_device(self, iface_name):
for wireless in self.get_wireless_interfaces():
if wireless.interface == iface_name:
if wireless.state == enums.DeviceState.UNMANAGED:
self.popup(f"{iface_name} is not managed by NetworkManager and cannot be controlled by this app")
return
self.wlan_device = wireless
logging.debug(f"Switched wlan_device to {iface_name}")
return
raise ValueError(f"No Wi‑Fi interface named '{iface_name}' found.")
+21 -3
View File
@@ -64,10 +64,21 @@ class Panel(ScreenPanel):
self.interface = self.sdbus_nm.get_primary_interface()
logging.info(f"Primary interface: {self.interface}")
self.labels['interface'] = Gtk.Label(hexpand=True)
iface_label = Gtk.Label(_("Interface") + ": ")
if len(self.wireless_interfaces) <= 1:
self.labels['interface'] = Gtk.Label(hexpand=True, halign=Gtk.Align.START)
if self.interface is not None:
self.labels['interface'].set_text(f'{self.interface}')
else:
self.labels['interface'] = Gtk.ComboBoxText()
self.labels['interface'].connect("changed", self.iface_changed)
for iface in self.wireless_interfaces:
self.labels['interface'].append(iface, iface)
if self.interface is not None:
self.labels['interface'].set_active_id(self.interface)
self.labels['ip'] = Gtk.Label(hexpand=True)
if self.interface is not None:
self.labels['interface'].set_text(_("Interface") + f': {self.interface}')
self.labels['ip'].set_text(f"IP: {self.sdbus_nm.get_ip_address()}")
self.reload_button = self._gtk.Button("refresh", None, "color1", self.bts)
@@ -86,6 +97,8 @@ class Panel(ScreenPanel):
wifi_toggle.add(self.wifi_toggle_switch)
sbox = Gtk.Box(hexpand=True, vexpand=False)
if (self._screen.width > 400):
sbox.add(iface_label)
sbox.add(self.labels['interface'])
sbox.add(self.labels['ip'])
sbox.add(self.reload_button)
@@ -174,6 +187,12 @@ class Panel(ScreenPanel):
self.network_list.add(self.network_rows[bssid])
def iface_changed(self, combo):
selected_iface = combo.get_active_id()
logging.info(f"Selected interace: {selected_iface}")
self.interace = selected_iface
self.sdbus_nm.set_wlan_device(selected_iface)
def remove_confirm_dialog(self, widget, ssid, bssid):
label = Gtk.Label(wrap=True, vexpand=True)
@@ -353,7 +372,6 @@ class Panel(ScreenPanel):
def update_all_networks(self):
self.interface = self.sdbus_nm.get_primary_interface()
self.labels['interface'].set_text(_("Interface") + f': {self.interface}')
self.labels['ip'].set_text(f"IP: {self.sdbus_nm.get_ip_address()}")
nets = self.sdbus_nm.get_networks()
remove = [bssid for bssid in self.network_rows.keys() if bssid not in [net['BSSID'] for net in nets]]