From 4ae153b7d782d75b596b0bf36beb02409ccdd3c6 Mon Sep 17 00:00:00 2001 From: Rebecca Breu <rebecca@rbreu.de> Date: Wed, 6 Dec 2023 21:31:16 +0100 Subject: [PATCH] Activating 'Move window' shortcut during window move ends the action --- beeref/main_controls.py | 10 ++++++++-- beeref/view.py | 7 ++----- tests/test_view.py | 8 ++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/beeref/main_controls.py b/beeref/main_controls.py index e4fc8a5..fbaccc6 100644 --- a/beeref/main_controls.py +++ b/beeref/main_controls.py @@ -36,13 +36,19 @@ class MainControlsMixin: def init_main_controls(self, main_window): self.main_window = main_window - self.setContextMenuPolicy( - Qt.ContextMenuPolicy.CustomContextMenu) + self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) self.customContextMenuRequested.connect( self.control_target.on_context_menu) self.setAcceptDrops(True) self.movewin_active = False + def on_action_movewin_mode(self): + if self.movewin_active: + # Pressing the same shortcut again should end the action + self.exit_movewin_mode() + else: + self.enter_movewin_mode() + def enter_movewin_mode(self): logger.debug('Entering movewin mode') self.setMouseTracking(True) diff --git a/beeref/view.py b/beeref/view.py index 2501a12..b21532d 100644 --- a/beeref/view.py +++ b/beeref/view.py @@ -222,9 +222,9 @@ def on_action_show_titlebar(self, checked): def on_action_move_window(self): if self.welcome_overlay.isHidden(): - self.enter_movewin_mode() + self.on_action_movewin_mode() else: - self.welcome_overlay.enter_movewin_mode() + self.welcome_overlay.on_action_movewin_mode() def on_action_undo(self): logger.debug('Undo: %s' % self.undo_stack.undoText()) @@ -404,9 +404,6 @@ def on_action_export_scene(self): filter=';;'.join(('Image Files (*.png *.jpg *.jpeg)', 'PNG (*.png)', 'JPEG (*.jpg *.jpeg)'))) - print(';;'.join(('Image Files (*.png *.jpg *.jpeg)', - 'PNG (*.png)', - 'JPEG (*.jpg *.jpeg)'))) if filename: logger.debug(f'Got export filename {filename}') exporter = SceneToPixmapExporter(self.scene) diff --git a/tests/test_view.py b/tests/test_view.py index 943e02d..29b7cf1 100644 --- a/tests/test_view.py +++ b/tests/test_view.py @@ -657,6 +657,14 @@ def test_on_action_move_window_when_welcome_overlay(cursor_mock, view): assert view.welcome_overlay.event_start == QtCore.QPointF(10.0, 20.0) +def test_on_action_move_window_when_already_active(view): + view.welcome_overlay.event_start = QtCore.QPointF(10.0, 20.0) + view.welcome_overlay.movewin_active = True + view.on_action_move_window() + assert view.welcome_overlay.movewin_active is False + assert view.welcome_overlay.event_start == QtCore.QPointF(10.0, 20.0) + + @patch('beeref.view.BeeGraphicsView.cursor') def test_on_action_move_window_when_scene(cursor_mock, view): cursor_mock.return_value = MagicMock(