Add escape key functionality to CropDialog and improve window handling in StepDialog

This commit is contained in:
2025-07-03 16:58:09 +02:00
parent e3c52b1d34
commit b2ef81beba
+25 -10
View File
@@ -107,6 +107,12 @@ class CropDialog(QtWidgets.QDialog):
self.selection_rect = self.rubber_band.geometry() self.selection_rect = self.rubber_band.geometry()
self.accept() self.accept()
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key.Key_Escape:
self.reject()
else:
super().keyPressEvent(event)
class MainWindow(QtWidgets.QMainWindow): class MainWindow(QtWidgets.QMainWindow):
def automation_loop(self): def automation_loop(self):
logger.info('Automation loop started.') logger.info('Automation loop started.')
@@ -501,22 +507,28 @@ class StepDialog(QtWidgets.QDialog):
def add_image_to_step(self): def add_image_to_step(self):
main_window = self.parent()
step_name = self.name_edit.text() step_name = self.name_edit.text()
if not step_name: if not step_name:
QtWidgets.QMessageBox.warning(self, "Step Name Required", "Please enter a name for the step before adding an image.") QtWidgets.QMessageBox.warning(self, "Step Name Required", "Please enter a name for the step before adding an image.")
return return
main_window.hide() all_windows = QtWidgets.QApplication.topLevelWidgets()
time.sleep(0.3) for w in all_windows:
w.setWindowState(QtCore.Qt.WindowState.WindowMinimized)
time.sleep(0.5)
try: try:
screen = QtWidgets.QApplication.primaryScreen() screen = QtWidgets.QApplication.primaryScreen()
if not screen: if not screen:
raise Exception("Could not get primary screen.") raise Exception("Could not get primary screen.")
full_screenshot_pixmap = screen.grabWindow(0) full_screenshot_pixmap = screen.grabWindow(0)
finally: finally:
main_window.show() for w in all_windows:
w.setWindowState(QtCore.Qt.WindowState.WindowNoState)
w.showNormal()
w.activateWindow()
crop_dialog = CropDialog(full_screenshot_pixmap, self) crop_dialog = CropDialog(full_screenshot_pixmap, self)
if crop_dialog.exec(): if crop_dialog.exec():
@@ -577,10 +589,11 @@ class StepDialog(QtWidgets.QDialog):
if idx < 0: if idx < 0:
return return
main_window = self.parent() all_windows = QtWidgets.QApplication.topLevelWidgets()
self.hide() for w in all_windows:
main_window.hide() w.setWindowState(QtCore.Qt.WindowState.WindowMinimized)
time.sleep(0.3)
time.sleep(0.5)
try: try:
screen = QtWidgets.QApplication.primaryScreen() screen = QtWidgets.QApplication.primaryScreen()
@@ -588,8 +601,10 @@ class StepDialog(QtWidgets.QDialog):
raise Exception("Could not get primary screen.") raise Exception("Could not get primary screen.")
full_screenshot_pixmap = screen.grabWindow(0) full_screenshot_pixmap = screen.grabWindow(0)
finally: finally:
main_window.show() for w in all_windows:
self.show() w.setWindowState(QtCore.Qt.WindowState.WindowNoState)
w.showNormal()
w.activateWindow()
crop_dialog = CropDialog(full_screenshot_pixmap, self) crop_dialog = CropDialog(full_screenshot_pixmap, self)
if crop_dialog.exec(): if crop_dialog.exec():