Skip to content

Commit

Permalink
BugFix: raises question to overwrite previous image twice
Browse files Browse the repository at this point in the history
  • Loading branch information
ullmannJan committed Sep 11, 2024
1 parent b163f39 commit 13b2ca1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
)
logger = logging.getLogger("Measury")
logger.setLevel(logging.DEBUG)
# measury.run(logger=logger)
measury.run(file_path=script_dir/r"tests/test_data/test_image.tif", logger=logger)
measury.run(logger=logger)
# measury.run(file_path=script_dir/r"tests/test_data/test_image.tif", logger=logger)
# measury.run(file_path=script_dir/r"tests/test_data/test_file_4.msry", logger=logger)
19 changes: 10 additions & 9 deletions src/measury/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@ def open_image_editor(self, image:QImage):

def open_image_from_clipboard(self):

clipboard = QGuiApplication.clipboard()

# if it is a file path, open it like a file
if clipboard.mimeData().hasUrls():
file_path = clipboard.mimeData().urls()[0].toLocalFile()
self.open_file(file_path)
return

# otherwise open the image as an image
reply = QMessageBox.StandardButton.Yes
try:
if self.img_data is not None:
Expand All @@ -378,14 +387,6 @@ def open_image_from_clipboard(self):

if reply == QMessageBox.StandardButton.Yes:

clipboard = QGuiApplication.clipboard()

# if it is a file path, open it like a file
if clipboard.mimeData().hasUrls():
file_path = clipboard.mimeData().urls()[0].toLocalFile()
self.open_file(file_path)
return

self.file_path = Path("clipboard")
self.delete_all_objects()
self.main_window.main_ui.reset_scaling()
Expand All @@ -399,7 +400,7 @@ def open_image_from_clipboard(self):

# Check if the image is in the correct format
if clipboard_data.format() != QImage.Format.Format_RGB32:
self.logger.info(f"Converting clipboard image from {clipboard_data.format()} to ARGB32 format")
self.logger.info(f"Converting clipboard image from {clipboard_data.format()} to RGB32 format")
clipboard_data = clipboard_data.convertToFormat(QImage.Format.Format_RGB32)

# Get the pointer to the pixel data
Expand Down

0 comments on commit 13b2ca1

Please sign in to comment.