Skip to content

Commit

Permalink
refactor: more typing
Browse files Browse the repository at this point in the history
  • Loading branch information
senyai committed Sep 27, 2024
1 parent 948c242 commit e2bbc2e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions gmc/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,18 @@ def _menu_button(self):
self,
"help",
tr("&Help"),
shortcuts=(Qt.Key_F1,),
shortcuts=(Qt.Key.Key_F1,),
triggered=self._on_help,
shortcutContext=Qt.WindowShortcut,
shortcutContext=Qt.ShortcutContext.WindowShortcut,
)
)
settings_act = new_action(
self,
"gears",
tr("Se&ttings"),
shortcuts=(Qt.CTRL + Qt.Key_Comma,),
shortcuts=(Qt.Modifier.CTRL + Qt.Key.Key_Comma,),
triggered=self._on_settings,
shortcutContext=Qt.WindowShortcut,
shortcutContext=Qt.ShortcutContext.WindowShortcut,
)
main_menu.addAction(settings_act)
self.addAction(settings_act)
Expand All @@ -191,7 +191,7 @@ def _menu_button(self):
tr("E&xit"),
self,
triggered=QtWidgets.qApp.quit,
shortcut=Qt.CTRL + Qt.Key_Q,
shortcut=Qt.Modifier.CTRL + Qt.Ket.Key_Q,
menuRole=QtWidgets.QAction.QuitRole,
)
)
Expand All @@ -207,7 +207,7 @@ def _on_help(self):
webbrowser.open("file://" + path)
else:
msg = tr("Help not bundled. {} does not exist.").format(path)
MB.warning(self, self.windowTitle(), msg, MB.Ok)
MB.warning(self, self.windowTitle(), msg, MB.StandardButton.Ok)

def _on_settings(self):
from .settings.dialog import create_setting_dialog
Expand Down
7 changes: 5 additions & 2 deletions gmc/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from typing import Any
from PyQt5.QtWidgets import QAction
from PyQt5.QtGui import QIcon, QKeySequence
Expand Down Expand Up @@ -30,20 +31,22 @@ def new_action(
icon: str | QIcon,
text: str,
shortcuts: tuple[str | QKeySequence.StandardKey | Qt.Key | int, ...] = (),
shortcutContext: Qt.ShortcutContext = Qt.ShortcutContext.WidgetShortcut,
**kwargs: Any,
) -> QAction:
sequences = [QKeySequence(s) for s in shortcuts]
shrtctext = "; ".join(
s.toString(format=QKeySequence.NativeText) for s in sequences
s.toString(format=QKeySequence.SequenceFormat.NativeText)
for s in sequences
)
kwargs.setdefault("shortcutContext", Qt.ShortcutContext.WidgetShortcut)
if not isinstance(icon, QIcon):
icon = get_icon(icon)
action = QAction(
icon,
f"{text}\t{shrtctext}",
parent,
toolTip=f"{text.replace('&', '')} ({shrtctext})",
shortcutContext=shortcutContext,
**kwargs, # type: ignore[call-overload]
)
action.setShortcuts(sequences)
Expand Down
2 changes: 1 addition & 1 deletion gmc/utils/svg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from PyQt5 import QtGui


def icon_from_data(data):
def icon_from_data(data: bytes):
return QtGui.QIcon(QtGui.QPixmap.fromImage(QtGui.QImage.fromData(data)))

0 comments on commit e2bbc2e

Please sign in to comment.