Skip to content

Commit

Permalink
refactor: more typing bits
Browse files Browse the repository at this point in the history
  • Loading branch information
senyai committed Sep 27, 2024
1 parent 747894a commit 948c242
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 3 additions & 1 deletion gmc/file_widgets/multiple_sources_one_destination.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from typing import Callable
from PyQt5 import QtCore, QtWidgets
from ..utils import separator, get_icon
Expand All @@ -7,6 +8,7 @@
FilesystemTitle,
)
from itertools import zip_longest
from ..application import GMCArguments

Qt = QtCore.Qt
tr: Callable[[str], str] = lambda text: QtCore.QCoreApplication.translate(
Expand All @@ -19,7 +21,7 @@ class MultipleSourcesOneDestination:
SOURCE_TITLES = ["First Image", "Second Image"]

@classmethod
def create_data_widget(cls, mdi_area, settings, extra_args):
def create_data_widget(cls, mdi_area, settings, extra_args: GMCArguments):
def _on_open_src(view_idx, new_tab):
view = cls._source_widget.views()[view_idx]
dst_dir = cls._destination_widget.get_root_qdir()
Expand Down
18 changes: 10 additions & 8 deletions gmc/file_widgets/one_source_one_destination.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Any, Callable, Sequence
from __future__ import annotations
from typing import Callable, Sequence
from PyQt5 import QtCore, QtWidgets, QtGui
from ..utils import separator, new_action
from ..views.filesystem_widget import SingleFilesystemWidget, FilesystemTitle
from ..settings import settings
from ..application import GMCArguments

Qt = QtCore.Qt
MB = QtWidgets.QMessageBox
Expand All @@ -14,7 +16,7 @@
class OneSourceOneDestination:
@classmethod
def create_data_widget(
cls, mdi_area: QtWidgets.QMdiArea, extra_args: dict[str, Any]
cls, mdi_area: QtWidgets.QMdiArea, extra_args: GMCArguments
) -> QtWidgets.QSplitter:
"""
:param cls: like `gmc.schemas.tagged_objects.TaggedObjects`
Expand Down Expand Up @@ -197,32 +199,32 @@ def __init__(
def _get_default_actions(self):
""":returns: actions, every markup window should have"""

def mod(*keys: int) -> tuple[int, ...]:
def mod(*keys: Qt.Key) -> tuple[Qt.Key, ...]:
return (
keys
+ tuple(key + Qt.SHIFT for key in keys)
+ tuple(key + Qt.ALT for key in keys)
+ tuple(key + Qt.Modifier.SHIFT for key in keys)
+ tuple(key + Qt.Modifier.ALT for key in keys)
)

self._prev_action = new_action(
self,
"prev",
tr("Previous File"),
mod(Qt.Key_P, Qt.Key_PageUp, Qt.Key_Backspace),
mod(Qt.Key.Key_P, Qt.Key.Key_PageUp, Qt.Key.Key_Backspace),
triggered=lambda: self._go(-1),
)
self._next_action = new_action(
self,
"next",
tr("Next File"),
mod(Qt.Key_N, Qt.Key_PageDown, Qt.Key_Space),
mod(Qt.Key.Key_N, Qt.Key.Key_PageDown, Qt.Key.Key_Space),
triggered=lambda: self._go(1),
)
_save_action = new_action(
self,
"save",
tr("Save"),
(Qt.CTRL + Qt.Key_S,),
(Qt.Modifier.CTRL + Qt.Key.Key_S,),
triggered=lambda: self._schema.save_markup(),
)

Expand Down
3 changes: 2 additions & 1 deletion gmc/schemas/tagged_objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ...utils.read_properties import read_properties
from ...utils import get_icon, separator, new_action, tr, clipboard
from ...file_widgets.one_source_one_destination import OneSourceOneDestination
from ...application import GMCArguments

Qt = QtCore.Qt
MB = QtWidgets.QMessageBox
Expand Down Expand Up @@ -360,7 +361,7 @@ def __init__(self, markup_window, default_actions):

@classmethod
def create_data_widget(
cls, mdi_area: QtWidgets.QMdiArea, extra_args: dict[str, Any]
cls, mdi_area: QtWidgets.QMdiArea, extra_args: GMCArguments
):
splitter = super().create_data_widget(mdi_area, extra_args)
iterpolate_act = new_action(
Expand Down
2 changes: 1 addition & 1 deletion gmc/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def new_action(
parent: QObject,
icon: str | QIcon,
text: str,
shortcuts: tuple[str | QKeySequence.StandardKey | Qt.Key, ...] = (),
shortcuts: tuple[str | QKeySequence.StandardKey | Qt.Key | int, ...] = (),
**kwargs: Any,
) -> QAction:
sequences = [QKeySequence(s) for s in shortcuts]
Expand Down

0 comments on commit 948c242

Please sign in to comment.