Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More edit_node fixes #7

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gmc/file_widgets/one_source_one_destination.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, Dict, List, Sequence
from typing import Any, Callable, Sequence
from PyQt5 import QtCore, QtWidgets, QtGui
from ..utils import separator, new_action
from ..views.filesystem_widget import SingleFilesystemWidget, FilesystemTitle
Expand All @@ -14,7 +14,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: dict[str, Any]
) -> QtWidgets.QSplitter:
"""
:param cls: like `gmc.schemas.tagged_objects.TaggedObjects`
Expand Down Expand Up @@ -174,7 +174,7 @@ def __init__(
dst_dir: QtCore.QDir,
src_dir: QtCore.QDir,
file_path: str,
all_files: List[str],
all_files: list[str],
schema,
):
"""
Expand Down
308 changes: 119 additions & 189 deletions gmc/i18n/gmc_ru.ts

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions gmc/i18n/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pylupdate5 \
gmc/markup_objects/rect.py \
gmc/markup_objects/tags.py \
gmc/mdi_area.py \
gmc/schemas/number_plates/__init__.py \
gmc/schemas/number_plates/plate_frame.py \
gmc/schemas/tagged_objects/__init__.py \
gmc/schemas/tagged_objects/markup_interpolation.py \
gmc/settings/dialog.py \
Expand Down
5 changes: 2 additions & 3 deletions gmc/main_window.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
from typing import Any, Dict, Optional, Type
from PyQt5 import QtCore, QtWidgets, QtGui
from .mdi_area import MdiArea
from .schemas import MarkupSchema, load_schema_cls, iter_schemas
Expand All @@ -14,7 +13,7 @@


class MainWindow(QtWidgets.QMainWindow):
_schema_cls: Optional[Type[MarkupSchema]] = None
_schema_cls: type[MarkupSchema] | None = None
_extra_args: GMCArguments

def __init__(
Expand Down Expand Up @@ -74,7 +73,7 @@ def _setup_ui(self):

self.setCentralWidget(self._main_splitter)

def _sub_window_changed(self, window):
def _sub_window_changed(self, window: QtWidgets.QMdiSubWindow | None):
if window is not None:
try:
on_activate = window.widget().on_activate
Expand Down
4 changes: 2 additions & 2 deletions gmc/markup_objects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import Any, ClassVar, Dict, Tuple
from typing import Any, ClassVar
from PyQt5 import QtGui, QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QGraphicsView, QGraphicsSceneMouseEvent
Expand All @@ -13,7 +13,7 @@ class MarkupObjectMeta:
PEN_SELECTED_DASHED = QtGui.QPen(
Qt.GlobalColor.blue, 0, Qt.PenStyle.DashLine
)
ACTION_KEYS: ClassVar[Dict[Qt.Key, Tuple[int, ...]]] = {}
ACTION_KEYS: ClassVar[dict[Qt.Key, tuple[int, ...]]] = {}

def __init__(self, *args: Any, **kwargs: Any) -> None:
assert not hasattr(self, "_edit_mode")
Expand Down
4 changes: 2 additions & 2 deletions gmc/markup_objects/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ..views.image_view import ImageView
from . import MarkupObjectMeta
from typing import Callable, Optional
from typing import Callable
from PyQt5.QtCore import Qt, QRectF, QPointF, QCoreApplication

tr: Callable[[str], str] = lambda text: QCoreApplication.translate(
Expand All @@ -16,7 +16,7 @@ class MarkupPoint(QtWidgets.QGraphicsItem, MarkupObjectMeta):
PEN_SELECTED = QtGui.QPen(Qt.GlobalColor.yellow, 4)
CURSOR = QtGui.QCursor(QtGui.QPixmap("gmc:cursors/add_point.svg"), 6, 6)

def __init__(self, pos: Optional[QPointF] = None):
def __init__(self, pos: QPointF | None = None):
super(MarkupPoint, self).__init__()
if pos is None:
pos = QPointF()
Expand Down
9 changes: 5 additions & 4 deletions gmc/markup_objects/polygon.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations
from PyQt5 import QtGui, QtWidgets

from ..views.image_view import ImageView
from . import MarkupObjectMeta
from .moveable_diamond import MoveableDiamond
from math import hypot
from typing import Any, Optional, List, Callable
from typing import Any, Callable
from PyQt5.QtCore import Qt, QPointF, QCoreApplication, QRectF

tr: Callable[[str], str] = lambda text: QCoreApplication.translate(
Expand All @@ -22,7 +23,7 @@ class MarkupPolygon(QtWidgets.QGraphicsItem, MarkupObjectMeta):
CURSOR = QtGui.QCursor(QtGui.QPixmap("gmc:cursors/add_line.svg"), 6, 6)
UNDO = True # Allow subclasses to disable undoing

def __init__(self, polygon: Optional[QtGui.QPolygonF]) -> None:
def __init__(self, polygon: QtGui.QPolygonF | None) -> None:
super().__init__()
if polygon is None:
polygon = QtGui.QPolygonF()
Expand Down Expand Up @@ -170,7 +171,7 @@ def mouseDoubleClickEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
MarkupObjectMeta.mouseDoubleClickEvent(self, event)

def notify_delete(self) -> None:
indices: List[int] = []
indices: list[int] = []
for item in self.childItems():
if isinstance(item, MoveableDiamond) and item.isSelected():
indices.append(item.idx)
Expand Down Expand Up @@ -296,7 +297,7 @@ def undo(self) -> None:

class UndoPolygonDelPoints(QtWidgets.QUndoCommand):
def __init__(
self, markup_polygon: MarkupPolygon, indices: List[int]
self, markup_polygon: MarkupPolygon, indices: list[int]
) -> None:
indices.sort(reverse=True)
polygon = markup_polygon._polygon
Expand Down
2 changes: 1 addition & 1 deletion gmc/markup_objects/quadrangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def notify_delete(self) -> None:
for item in self.childItems()
if isinstance(item, MoveableDiamond)
):
self.stop_edit_nodes()
self.ensure_edition_canceled()
self.scene().removeItem(self)

def _finish(self, view: ImageView):
Expand Down
14 changes: 7 additions & 7 deletions gmc/markup_objects/rect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Tuple
from typing import Any
from PyQt5 import QtGui, QtWidgets
from PyQt5.QtCore import Qt, QRectF, QPointF, QSizeF, QElapsedTimer

Expand All @@ -23,7 +23,7 @@ class MarkupRect(QtWidgets.QGraphicsItem, MarkupObjectMeta):
}
CURSOR = QtGui.QCursor(QtGui.QPixmap("gmc:cursors/add_rect.svg"), 6, 6)

def __init__(self, rect: Optional[QRectF] = None):
def __init__(self, rect: QRectF | None = None):
super().__init__()
if rect is None:
rect = QRectF()
Expand Down Expand Up @@ -83,7 +83,7 @@ def notify_delete(self) -> None:
for item in self.childItems()
if isinstance(item, MoveableDiamond)
):
self.stop_edit_nodes()
self.ensure_edition_canceled()
self.scene().removeItem(self)

def itemChange(
Expand All @@ -96,7 +96,7 @@ def itemChange(
self.on_deselect()
return value

def _four_points(self) -> Tuple[QPointF, QPointF, QPointF, QPointF]:
def _four_points(self) -> tuple[QPointF, QPointF, QPointF, QPointF]:
p = self._rect.topLeft()
return (
p + QPointF(0.0, 0.0),
Expand Down Expand Up @@ -211,7 +211,7 @@ def redo(self) -> None:

def undo(self) -> None:
mr = self._markup_rect
mr.stop_edit_nodes()
mr.ensure_edition_canceled()
self._scene.removeItem(mr)


Expand All @@ -226,12 +226,12 @@ def __init__(

def redo(self) -> None:
mr = self._markup_rect
mr.stop_edit_nodes()
mr.ensure_edition_canceled()
mr._rect = QRectF(self._new_rect)
mr.update()

def undo(self) -> None:
mr = self._markup_rect
mr.stop_edit_nodes()
mr.ensure_edition_canceled()
mr._rect = QRectF(self._old_rect)
mr.update()
14 changes: 7 additions & 7 deletions gmc/markup_objects/tags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, DefaultDict, Dict, List, Sequence, Set
from typing import Any, Callable, Sequence
from PyQt5 import QtCore, QtGui, QtWidgets
from collections import defaultdict
from gmc.views.image_widget import ImageWidget
Expand Down Expand Up @@ -97,8 +97,8 @@ class HasTags:
del grad

def __init__(self, *args: Any, tags: Sequence[str] = (), **kwargs: Any):
self._tags: Set[str] = set(tags)
self._draws: List[Callable[[QtGui.QPainter], None]] = []
self._tags: set[str] = set(tags)
self._draws: list[Callable[[QtGui.QPainter], None]] = []
self._tag_polygon = QtGui.QPolygonF()
self._last_fm = None
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -127,7 +127,7 @@ def _on_tags_changed(self):
self.update()
pass # for overriding

def data(self) -> Dict[str, Any]:
def data(self) -> dict[str, Any]:
tags = sorted(self._tags)
ret = {"data": super().data()}
if tags:
Expand Down Expand Up @@ -217,7 +217,7 @@ def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:

def edit_tags(
parent: ImageWidget,
items: List[MarkupObjectMeta],
items: list[MarkupObjectMeta],
extra_tags: Sequence[str] = (),
) -> None:
"""
Expand All @@ -227,7 +227,7 @@ def edit_tags(
"""
if not items:
return
tags: DefaultDict[str, int] = defaultdict(
tags: defaultdict[str, int] = defaultdict(
int, {tag: 0 for tag in extra_tags}
)
for item in items:
Expand Down Expand Up @@ -323,7 +323,7 @@ def append_tag() -> None:

class UndoTagModification(QtWidgets.QUndoCommand):
def __init__(
self, items: List[HasTags], add: List[str], remove: List[str]
self, items: list[HasTags], add: list[str], remove: list[str]
):
self._items = items
self._add = add
Expand Down
35 changes: 20 additions & 15 deletions gmc/mdi_area.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from __future__ import annotations
from PyQt5 import QtGui, QtCore, QtWidgets
from .utils import get_icon, separator, new_action, tr

Expand Down Expand Up @@ -26,16 +26,16 @@ def eventFilter(


class MdiArea(QtWidgets.QMdiArea):
def __init__(self, parent: QtCore.QObject) -> None:
def __init__(self, parent: QtWidgets.QSplitter) -> None:
self._splitter = parent
super().__init__(
parent,
objectName="mdi_area",
viewMode=QtWidgets.QMdiArea.TabbedView,
viewMode=QtWidgets.QMdiArea.ViewMode.TabbedView,
)

# Setting elide mode
tab_bar: QtWidgets.QTabBar = self.findChild(QtWidgets.QTabBar)
tab_bar.setElideMode(Qt.ElideMiddle)
tab_bar.setElideMode(Qt.TextElideMode.ElideMiddle)
tab_bar.setMovable(True)
tab_bar.setTabsClosable(True)
self._renamer = TabRenamer()
Expand Down Expand Up @@ -111,20 +111,20 @@ def __init__(self, parent: QtCore.QObject) -> None:
triggered=self.cascadeSubWindows,
)

KS = QtGui.QKeySequence
SK = QtGui.QKeySequence.StandardKey
next_act = new_action(
self,
"next",
tr("Ne&xt"),
(KS.NextChild,),
(SK.NextChild,),
triggered=self.activateNextSubWindow,
)

previous_act = new_action(
self,
"prev",
tr("Pre&vious"),
(KS.PreviousChild,),
(SK.PreviousChild,),
triggered=self.activatePreviousSubWindow,
)

Expand Down Expand Up @@ -153,22 +153,20 @@ def close_others(self) -> None:

def fullscreen(self, state: bool) -> None:
if state: # go fullscreen
self.splitter: QtWidgets.QSplitter = self.parent()
self._splitter_state = self.splitter.saveState()
self.setParent(self.splitter.parent())
self._splitter_state = self._splitter.saveState()
self.setParent(self._splitter.parent())
self.setWindowFlags(Qt.Tool | Qt.FramelessWindowHint)
self.showFullScreen()
else:
self.setParent(self.splitter)
self.splitter.restoreState(self._splitter_state)
self.splitter = None
self.setParent(self._splitter)
self._splitter.restoreState(self._splitter_state)
self.showNormal()

def add(
self,
window: QtWidgets.QWidget,
new: bool = False,
icon: Optional[str] = None,
icon: str | None = None,
) -> None:
if (
not new
Expand Down Expand Up @@ -232,3 +230,10 @@ def keyPressEvent(self, event: QtGui.QKeyEvent) -> None:
self.fullscreen_act.setChecked(False)
else:
return QtWidgets.QMdiArea.keyPressEvent(self, event)

def paintEvent(self, event: QtGui.QPaintEvent) -> None:
super().paintEvent(event)
if not self._splitter.sizes()[0]:
with QtGui.QPainter(self.viewport()) as p:
p.setPen(Qt.GlobalColor.darkRed)
p.drawText(3, 20, tr("Drag side bar to make it visible"))
4 changes: 2 additions & 2 deletions gmc/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import abc
import importlib
from typing import Type, Iterable, Sequence
from typing import Iterable, Sequence
from PyQt5 import QtWidgets, QtCore
from ..application import GMCArguments

Expand Down Expand Up @@ -49,7 +49,7 @@ def create_data_widget(
raise NotImplementedError(cls)


def load_schema_cls(mod_name: str, path: str | None) -> Type[MarkupSchema]:
def load_schema_cls(mod_name: str, path: str | None) -> type[MarkupSchema]:
if path is None:
mod_path = "gmc.schemas." + mod_name
else:
Expand Down
Loading