diff --git a/main_window.py b/main_window.py index be978ac..953ab49 100644 --- a/main_window.py +++ b/main_window.py @@ -617,7 +617,12 @@ class MainWindow(QMainWindow): def open_background_dialog(self) -> None: dialog = BackgroundDialog(self.document.background, self) - if dialog.exec() != BackgroundDialog.Accepted: + self._disable_shortcuts() + try: + res = dialog.exec() + finally: + self._enable_shortcuts() + if res != BackgroundDialog.Accepted: return background = dialog.background() if not background.path: @@ -711,7 +716,12 @@ class MainWindow(QMainWindow): def open_settings(self) -> None: dialog = SettingsDialog(self.settings, self) - if dialog.exec() != SettingsDialog.Accepted: + self._disable_shortcuts() + try: + res = dialog.exec() + finally: + self._enable_shortcuts() + if res != SettingsDialog.Accepted: return self.settings = dialog.settings() self.settings.save() @@ -1099,7 +1109,14 @@ class MainWindow(QMainWindow): buttons.accepted.connect(dialog.accept) buttons.rejected.connect(dialog.reject) layout.addWidget(buttons) - if dialog.exec() != QDialog.Accepted: + + self._disable_shortcuts() + try: + res = dialog.exec() + finally: + self._enable_shortcuts() + + if res != QDialog.Accepted: return self.update_point_coordinates(point_id, x_spin.value(), y_spin.value(), source="dialog") @@ -1724,13 +1741,17 @@ class MainWindow(QMainWindow): block = self._find_block_or_none(line_id, block_id) if block is None: return - new_name, ok = QInputDialog.getText( - self, - "Переименовать блок", - "Введите новое имя блока:", - QLineEdit.EchoMode.Normal, - block.name - ) + self._disable_shortcuts() + try: + new_name, ok = QInputDialog.getText( + self, + "Переименовать блок", + "Введите новое имя блока:", + QLineEdit.EchoMode.Normal, + block.name + ) + finally: + self._enable_shortcuts() if ok and new_name.strip() and new_name.strip() != block.name: self._push_undo() block.name = new_name.strip() @@ -2238,6 +2259,14 @@ class MainWindow(QMainWindow): self._dirty, ) + def _disable_shortcuts(self) -> None: + for action in self.actions.values(): + action.setShortcutContext(Qt.WidgetShortcut) + + def _enable_shortcuts(self) -> None: + for action in self.actions.values(): + action.setShortcutContext(Qt.ApplicationShortcut) + def _restore_state(self, state: tuple[MappingDocument, int | None, list[int], bool]) -> None: document, active_line_id, selected_point_ids, dirty = state self.document = document