Skip to content

Commit

Permalink
Now fix the typing issues that surfaced.
Browse files Browse the repository at this point in the history
I opted to workaround select_multiple as adding this to Gtk.pyi is not
trivial.
  • Loading branch information
infirit committed Dec 19, 2024
1 parent d97ac7b commit 5b02600
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion blueman/gui/DeviceSelectorDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from blueman.bluez.Device import Device
from blueman.gui.DeviceList import DeviceList
from blueman.gui.DeviceSelectorWidget import DeviceSelectorWidget
from blueman.bluemantyping import ObjectPath

import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk


class DeviceSelectorDialog(Gtk.Dialog):
selection: tuple[str, Device | None] | None
selection: tuple[ObjectPath, Device | None] | None

def __init__(self, title: str = _("Select Device"), parent: Gtk.Container | None = None, discover: bool = True,
adapter_name: str | None = None) -> None:
Expand Down
19 changes: 11 additions & 8 deletions blueman/main/Sendto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import os
import time
import logging
from argparse import Namespace
from gettext import ngettext
from collections.abc import Iterable
from collections.abc import Iterable, Sequence

from blueman.bluez.Device import Device
from blueman.bluez.errors import BluezDBusException, DBusNoSuchAdapterError
Expand All @@ -28,7 +29,7 @@


class SendTo:
def __init__(self, parsed_args):
def __init__(self, parsed_args: Namespace) -> None:
setup_icon_path()

check_bluetooth_status(_("Bluetooth needs to be turned on for file sending to work"), bmexit)
Expand Down Expand Up @@ -64,7 +65,7 @@ def __init__(self, parsed_args):
self.adapter_path = adapter.get_object_path()

if parsed_args.delete:
def delete_files():
def delete_files() -> None:
for file in self.files:
os.unlink(file)
atexit.register(delete_files)
Expand All @@ -83,21 +84,23 @@ def delete_files():
self.device = d
self.do_send()

def do_send(self):
def do_send(self) -> None:
if not self.files:
logging.warning("No files to send")
bmexit()

assert self.device is not None
sender = Sender(self.device, self.adapter_path, self.files)

def on_result(sender, res):
def on_result(_sender: Sender, _res: bool) -> None:
Gtk.main_quit()

sender.connect("result", on_result)

@staticmethod
def select_files():
d = Gtk.FileChooserDialog(title=_("Select files to send"), icon_name='blueman-send-symbolic', select_multiple=True)
def select_files() -> Sequence[str]:
d = Gtk.FileChooserDialog(title=_("Select files to send"), icon_name='blueman-send-symbolic')
d.set_select_multiple(True) # this avoids type error when using keyword arg above
d.add_buttons(_("_Cancel"), Gtk.ResponseType.REJECT, _("_OK"), Gtk.ResponseType.ACCEPT)
resp = d.run()

Expand All @@ -109,7 +112,7 @@ def select_files():
d.destroy()
quit()

def select_device(self):
def select_device(self) -> bool:
adapter_name = os.path.split(self.adapter_path)[-1]
d = DeviceSelectorDialog(discover=True, adapter_name=adapter_name)
resp = d.run()
Expand Down

0 comments on commit 5b02600

Please sign in to comment.