Skip to content

Commit

Permalink
Fix device-selected handlers
Browse files Browse the repository at this point in the history
The device argument is actually optional.
  • Loading branch information
cschramm committed Dec 12, 2023
1 parent 1477f2e commit 76cdb50
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions blueman/gui/DeviceSelectorDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, title: str = _("Select Device"), parent: Optional[Gtk.Contain
self.selector = DeviceSelectorWidget(adapter_name=adapter_name, visible=True)
self.vbox.pack_start(self.selector, True, True, 0)

self.selection: Optional[Tuple[str, Device]] = None
self.selection: Optional[Tuple[str, Optional[Device]]] = None

self.selector.List.connect("device-selected", self.on_device_selected)
self.selector.List.connect("adapter-changed", self.on_adapter_changed)
Expand All @@ -45,6 +45,6 @@ def on_row_activated(self, _treeview: Gtk.TreeView, _path: Gtk.TreePath, _view_c
def on_adapter_changed(self, _devlist: DeviceList, _adapter: str) -> None:
self.selection = None

def on_device_selected(self, devlist: DeviceList, device: Device, _tree_iter: Gtk.TreeIter) -> None:
def on_device_selected(self, devlist: DeviceList, device: Optional[Device], _tree_iter: Gtk.TreeIter) -> None:
assert devlist.Adapter is not None
self.selection = (devlist.Adapter.get_object_path(), device)
2 changes: 1 addition & 1 deletion blueman/gui/manager/ManagerMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _on_settings_changed(self, settings: Gio.Settings, key: str) -> None:
logging.debug("refilter")
self.blueman.List.filter.refilter()

def on_device_selected(self, _lst: ManagerDeviceList, device: Device, tree_iter: Gtk.TreeIter) -> None:
def on_device_selected(self, _lst: ManagerDeviceList, device: Optional[Device], tree_iter: Gtk.TreeIter) -> None:
if tree_iter and device:
self.item_device.props.sensitive = True

Expand Down
9 changes: 7 additions & 2 deletions blueman/gui/manager/ManagerToolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ def on_adapter_changed(self, _lst: ManagerDeviceList, adapter_path: Optional[str
logging.debug(f"toolbar adapter {adapter_path}")
self._update_buttons(None if adapter_path is None else Adapter(obj_path=adapter_path))

def on_device_selected(self, dev_list: ManagerDeviceList, device: Device, _tree_iter: Gtk.TreeIter) -> None:
self._update_buttons(Adapter(obj_path=device["Adapter"]))
def on_device_selected(
self,
dev_list: ManagerDeviceList,
device: Optional[Device],
_tree_iter: Gtk.TreeIter,
) -> None:
self._update_buttons(None if device is None else Adapter(obj_path=device["Adapter"]))

def _update_buttons(self, adapter: Optional[Adapter]) -> None:
powered = adapter is not None and adapter["Powered"]
Expand Down

0 comments on commit 76cdb50

Please sign in to comment.