Skip to content

Commit 1a2538c

Browse files
committed
typing: update type hints
1 parent 51982b2 commit 1a2538c

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

gmc/file_widgets/multiple_sources_one_destination.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
from __future__ import annotations
2-
from typing import Callable
3-
from PyQt5 import QtCore, QtWidgets
4-
from ..utils import separator, get_icon
2+
from PyQt5 import QtCore, QtWidgets, QtGui
3+
from ..utils import separator, get_icon, tr
54
from ..views.filesystem_widget import (
65
MultipleFilesystemWidget,
76
SingleFilesystemWidget,
87
FilesystemTitle,
98
)
109
from itertools import zip_longest
1110
from ..application import GMCArguments
11+
from ..mdi_area import MdiArea
1212

1313
Qt = QtCore.Qt
14-
tr: Callable[[str], str] = lambda text: QtCore.QCoreApplication.translate(
15-
"@default", text
16-
)
1714

1815

1916
class MultipleSourcesOneDestination:
2017
NSOURCES = 2
2118
SOURCE_TITLES = ["First Image", "Second Image"]
2219

2320
@classmethod
24-
def create_data_widget(cls, mdi_area, settings, extra_args: GMCArguments):
25-
def _on_open_src(view_idx, new_tab):
21+
def create_data_widget(
22+
cls, mdi_area: MdiArea, settings, extra_args: GMCArguments
23+
):
24+
def _on_open_src(view_idx: int, new_tab: bool) -> None:
2625
view = cls._source_widget.views()[view_idx]
2726
dst_dir = cls._destination_widget.get_root_qdir()
2827
if dst_dir is None:
@@ -50,15 +49,15 @@ def _on_open_src(view_idx, new_tab):
5049
)
5150
new_tab = True
5251

53-
def _on_open_dst(self, new=False):
54-
def selected_files(root_path):
52+
def _on_open_dst(self, new: bool = False) -> None:
53+
def selected_files(root_path: QtCore.QFileInfo):
5554
for path in self._destination_view.selected_files_relative:
5655
path = path[: -len(".json")]
5756
yield root_path.filePath(path)
5857

5958
self._on_open(selected_files, new)
6059

61-
def _on_view_dst_file():
60+
def _on_view_dst_file() -> None:
6261
for path in cls._destination_widget.view().selected_files():
6362
f = QtCore.QFile(path)
6463
if not f.open(f.ReadOnly | f.Text):
@@ -139,7 +138,7 @@ def _on_view_dst_file():
139138
return splitter
140139

141140
@classmethod
142-
def save_settings(cls, settings):
141+
def save_settings(cls, settings) -> None:
143142
settings.setValue(
144143
cls.__name__ + "_src_dir", cls._source_widget.get_root_string()
145144
)
@@ -172,7 +171,9 @@ def __init__(self, schema):
172171
self._all_files = [None] * schema.NSOURCES
173172
self._idx = [None] * schema.NSOURCES
174173

175-
def _create_go_actions(self, n, actions_name, actions, icon, where):
174+
def _create_go_actions(
175+
self, n: int, actions_name: str, actions, icon: QtGui.QIcon, where: int
176+
):
176177
for idx, (caption, shortcuts) in zip_longest(
177178
range(n), actions, fillvalue=(actions_name, None)
178179
):
@@ -186,7 +187,7 @@ def _create_go_actions(self, n, actions_name, actions, icon, where):
186187
shortcuts and action.setShortcuts(shortcuts)
187188
yield action
188189

189-
def _get_default_actions(self, n):
190+
def _get_default_actions(self, n: int):
190191
""":returns: actions, every markup window should have."""
191192
prev_shortcuts = (
192193
(
@@ -240,7 +241,14 @@ def _get_default_actions(self, n):
240241
):
241242
yield prev_action, next_action, separator(self), save_action
242243

243-
def open_current(self, view_idx, dst_dir, src_dir, file_path, all_files):
244+
def open_current(
245+
self,
246+
view_idx: int,
247+
dst_dir: QtCore.QDir,
248+
src_dir: QtCore.QDir,
249+
file_path: str,
250+
all_files,
251+
) -> None:
244252
"""The function is "public" only because it fixes focus issue."""
245253
self._dst_dir = dst_dir
246254
self._all_files[view_idx] = all_files

gmc/file_widgets/one_source_one_destination.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
from __future__ import annotations
2-
from typing import Callable, Sequence
2+
from typing import Sequence
33
from PyQt5 import QtCore, QtWidgets, QtGui
4-
from ..utils import separator, new_action
4+
from ..utils import separator, new_action, tr
55
from ..views.filesystem_widget import SingleFilesystemWidget, FilesystemTitle
66
from ..settings import settings
77
from ..application import GMCArguments
88

99
Qt = QtCore.Qt
1010
MB = QtWidgets.QMessageBox
11-
tr: Callable[[str], str] = lambda text: QtCore.QCoreApplication.translate(
12-
"@default", text
13-
)
1411

1512

1613
class OneSourceOneDestination:
@@ -73,7 +70,7 @@ def selected_files():
7370

7471
_on_open(selected_files(), new)
7572

76-
def _on_view_dst_file():
73+
def _on_view_dst_file() -> None:
7774
for path in cls._destination_widget.view().selected_files():
7875
f = QtCore.QFile(path)
7976
if not f.open(f.ReadOnly | f.Text):
@@ -177,7 +174,7 @@ def __init__(
177174
file_path: str,
178175
all_files: list[str],
179176
schema,
180-
):
177+
) -> None:
181178
"""
182179
:param dst_dir: `QDir` root destination path
183180
:param src_dir: `QDir` root source path

gmc/views/filesystem_view.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Any, Iterable
1+
from __future__ import annotations
2+
from typing import Any, Iterable, TYPE_CHECKING
23
from PyQt5 import QtCore, QtGui, QtWidgets
34
from ..utils import separator, new_action, tr
45

@@ -172,7 +173,7 @@ def _selected_info_map(self) -> Iterable[QtCore.QFileInfo]:
172173

173174
@property
174175
def selected_files_relative(self) -> list[str]:
175-
root_dir: QtCore.QDir = self.model().root_dir_qdir
176+
root_dir = self.model().root_dir_qdir
176177
return [
177178
root_dir.relativeFilePath(info.filePath())
178179
for info in self._selected_info_map
@@ -213,12 +214,12 @@ def contextMenuEvent(self, event: QtGui.QContextMenuEvent) -> None:
213214
menu.exec_(event.globalPos())
214215

215216
def set_path(self, path: str) -> None:
216-
model: MinimalFileSystemModel = self.model()
217+
model = self.model()
217218
index = model.setRootPath(path)
218219
self.setRootIndex(index)
219220

220221
def set_name_filters(self, name_filters: Iterable[str]):
221-
model: MinimalFileSystemModel = self.model()
222+
model = self.model()
222223
model.setNameFilters(name_filters)
223224

224225
def user_select_path(
@@ -234,6 +235,10 @@ def user_select_path(
234235
if path:
235236
callback(self, path)
236237

238+
if TYPE_CHECKING:
239+
240+
def model(self) -> MinimalFileSystemModel: ...
241+
237242

238243
class MinimalFileSystemModel(QtWidgets.QFileSystemModel):
239244
_sel_path: QtCore.QDir | None = None

gmc/views/filesystem_widget.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from typing import NamedTuple, Sequence
23
from PyQt5 import QtCore, QtWidgets
34
from .filesystem_view import FilesystemView
@@ -23,7 +24,7 @@ def __init__(
2324
parent: QtWidgets.QWidget,
2425
title: FilesystemTitle,
2526
actions: list[QtWidgets.QAction],
26-
):
27+
) -> None:
2728
assert isinstance(title, FilesystemTitle), title
2829
super().__init__(
2930
parent,
@@ -45,7 +46,7 @@ def __init__(
4546

4647
view.model().rootPathChanged.connect(self._root_changed)
4748

48-
def _root_changed(self):
49+
def _root_changed(self) -> None:
4950
self._view.model().rootPathChanged.disconnect(self._root_changed)
5051
self._layout.takeAt(1).widget().setParent(None)
5152
self._layout.addWidget(self._view)

0 commit comments

Comments
 (0)