mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-17 17:42:20 +03:00
hotkey: Final mypy lints
* Ignore types on the darwin stuff in-class if from platform specific imports. * None of the HotkeyMgr __init__ methods take any args, so don't try to pass any through. Stops mypy complaints.
This commit is contained in:
parent
9f1ae40775
commit
6a403a5482
28
hotkey.py
28
hotkey.py
@ -107,14 +107,14 @@ class MacHotkeyMgr(AbstractHotkeyMgr):
|
|||||||
# Monkey-patch tk (tkMacOSXKeyEvent.c)
|
# Monkey-patch tk (tkMacOSXKeyEvent.c)
|
||||||
if not self.tkProcessKeyEvent_old:
|
if not self.tkProcessKeyEvent_old:
|
||||||
sel = b'tkProcessKeyEvent:'
|
sel = b'tkProcessKeyEvent:'
|
||||||
cls = NSApplication.sharedApplication().class__()
|
cls = NSApplication.sharedApplication().class__() # type: ignore
|
||||||
self.tkProcessKeyEvent_old = NSApplication.sharedApplication().methodForSelector_(sel)
|
self.tkProcessKeyEvent_old = NSApplication.sharedApplication().methodForSelector_(sel) # type: ignore
|
||||||
newmethod = objc.selector(
|
newmethod = objc.selector( # type: ignore
|
||||||
self.tkProcessKeyEvent,
|
self.tkProcessKeyEvent,
|
||||||
selector=self.tkProcessKeyEvent_old.selector,
|
selector=self.tkProcessKeyEvent_old.selector,
|
||||||
signature=self.tkProcessKeyEvent_old.signature
|
signature=self.tkProcessKeyEvent_old.signature
|
||||||
)
|
)
|
||||||
objc.classAddMethod(cls, sel, newmethod)
|
objc.classAddMethod(cls, sel, newmethod) # type: ignore
|
||||||
|
|
||||||
def tkProcessKeyEvent(self, cls, the_event): # noqa: N802
|
def tkProcessKeyEvent(self, cls, the_event): # noqa: N802
|
||||||
"""
|
"""
|
||||||
@ -444,9 +444,9 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr):
|
|||||||
0xa6: u'⇦', 0xa7: u'⇨', 0xa9: u'⊗', 0xab: u'☆', 0xac: u'⌂', 0xb4: u'✉',
|
0xa6: u'⇦', 0xa7: u'⇨', 0xa9: u'⊗', 0xab: u'☆', 0xac: u'⌂', 0xb4: u'✉',
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
self.root = None
|
self.root: tk.Tk = None # type: ignore
|
||||||
self.thread = None
|
self.thread: threading.Thread = None # type: ignore
|
||||||
with open(pathlib.Path(config.respath) / 'snd_good.wav', 'rb') as sg:
|
with open(pathlib.Path(config.respath) / 'snd_good.wav', 'rb') as sg:
|
||||||
self.snd_good = sg.read()
|
self.snd_good = sg.read()
|
||||||
with open(pathlib.Path(config.respath) / 'snd_bad.wav', 'rb') as sb:
|
with open(pathlib.Path(config.respath) / 'snd_bad.wav', 'rb') as sb:
|
||||||
@ -479,7 +479,7 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr):
|
|||||||
|
|
||||||
if thread:
|
if thread:
|
||||||
logger.debug('Thread is/was running')
|
logger.debug('Thread is/was running')
|
||||||
self.thread = None
|
self.thread = None # type: ignore
|
||||||
logger.debug('Telling thread WM_QUIT')
|
logger.debug('Telling thread WM_QUIT')
|
||||||
PostThreadMessage(thread.ident, WM_QUIT, 0, 0)
|
PostThreadMessage(thread.ident, WM_QUIT, 0, 0)
|
||||||
logger.debug('Joining thread')
|
logger.debug('Joining thread')
|
||||||
@ -496,7 +496,7 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr):
|
|||||||
# Hotkey must be registered by the thread that handles it
|
# Hotkey must be registered by the thread that handles it
|
||||||
if not RegisterHotKey(None, 1, modifiers | MOD_NOREPEAT, keycode):
|
if not RegisterHotKey(None, 1, modifiers | MOD_NOREPEAT, keycode):
|
||||||
logger.debug("We're not the right thread?")
|
logger.debug("We're not the right thread?")
|
||||||
self.thread = None
|
self.thread = None # type: ignore
|
||||||
return
|
return
|
||||||
|
|
||||||
fake = INPUT(INPUT_KEYBOARD, INPUTUNION(ki=KEYBDINPUT(keycode, keycode, 0, 0, None)))
|
fake = INPUT(INPUT_KEYBOARD, INPUTUNION(ki=KEYBDINPUT(keycode, keycode, 0, 0, None)))
|
||||||
@ -539,7 +539,7 @@ class WindowsHotkeyMgr(AbstractHotkeyMgr):
|
|||||||
|
|
||||||
logger.debug('Exited GetMessage() loop.')
|
logger.debug('Exited GetMessage() loop.')
|
||||||
UnregisterHotKey(None, 1)
|
UnregisterHotKey(None, 1)
|
||||||
self.thread = None
|
self.thread = None # type: ignore
|
||||||
logger.debug('Done.')
|
logger.debug('Done.')
|
||||||
|
|
||||||
def acquire_start(self) -> None:
|
def acquire_start(self) -> None:
|
||||||
@ -677,7 +677,7 @@ class LinuxHotKeyMgr(AbstractHotkeyMgr):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_hotkeymgr(*args, **kwargs) -> AbstractHotkeyMgr:
|
def get_hotkeymgr() -> AbstractHotkeyMgr:
|
||||||
"""
|
"""
|
||||||
Determine platform-specific HotkeyMgr.
|
Determine platform-specific HotkeyMgr.
|
||||||
|
|
||||||
@ -687,13 +687,13 @@ def get_hotkeymgr(*args, **kwargs) -> AbstractHotkeyMgr:
|
|||||||
:raises ValueError: If unsupported platform.
|
:raises ValueError: If unsupported platform.
|
||||||
"""
|
"""
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
return MacHotkeyMgr(*args, **kwargs)
|
return MacHotkeyMgr()
|
||||||
|
|
||||||
elif sys.platform == 'win32':
|
elif sys.platform == 'win32':
|
||||||
return WindowsHotkeyMgr(*args, **kwargs)
|
return WindowsHotkeyMgr()
|
||||||
|
|
||||||
elif sys.platform == 'linux':
|
elif sys.platform == 'linux':
|
||||||
return LinuxHotKeyMgr(*args, **kwargs)
|
return LinuxHotKeyMgr()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(f'Unknown platform: {sys.platform}')
|
raise ValueError(f'Unknown platform: {sys.platform}')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user