Skip to content

Commit

Permalink
Present image load errors as message boxes
Browse files Browse the repository at this point in the history
This also provides instructions for how users may install dectris-compression.

Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery committed May 17, 2024
1 parent e7df698 commit dca8716
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
19 changes: 6 additions & 13 deletions hexrdgui/image_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,10 @@ def load_dummy_images(self, initial=False):
def load_images(self, detectors, file_names, options=None):
HexrdConfig().imageseries_dict.clear()
for name, f in zip(detectors, file_names):
try:
if isinstance(f, list):
f = f[0]
ims = self.open_file(f, options)
HexrdConfig().imageseries_dict[name] = ims
except (Exception, IOError):
exc_str = traceback.format_exc()
msg = f'ERROR - Could not read file: \n{exc_str}'
HexrdConfig().logger.critical(msg)
# Since this is a non-gui thread, we can't use QMessageBox
# here, or we will have a segmentation fault.
return
if isinstance(f, list):
f = f[0]
ims = self.open_file(f, options)
HexrdConfig().imageseries_dict[name] = ims

# Save the path if it should be remembered
if self.remember:
Expand All @@ -85,7 +77,8 @@ def open_file(self, f, options=None):
if ims_type not in registry:
msg = (
'"dectris-compression" must be installed to load '
'eiger stream files'
'eiger stream files.\n\n'
'Try `pip install dectris-compression`'
)
raise Exception(msg)

Expand Down
7 changes: 7 additions & 0 deletions hexrdgui/image_load_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def begin_processing(self, postprocess=False):
worker.signals.progress.connect(progress_dialog.setValue)
# On completion load imageseries nd close loading dialog
worker.signals.result.connect(self.finish_processing_ims)
worker.signals.error.connect(self.on_process_ims_error)
worker.signals.finished.connect(progress_dialog.accept)
progress_dialog.exec()

Expand Down Expand Up @@ -229,6 +230,12 @@ def finish_processing_ims(self):
if self.transformed_images:
HexrdConfig().deep_rerender_needed.emit()

def on_process_ims_error(self, error):
exctype, value, tb = error
msg = f'Failed to process imageseries.\n\n{value}'
QMessageBox.critical(None, 'Error', msg)
HexrdConfig().logger.critical(tb)

def get_dark_aggr_op(self, ims, idx):
"""
Returns a tuple of the form (function, frames), where func is the
Expand Down
8 changes: 7 additions & 1 deletion hexrdgui/simple_image_series_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ def select_images(self):
if selected_files:
self.update_allowed = False
self.reset_data()
self.load_image_data(selected_files)

try:
self.load_image_data(selected_files)
except Exception as e:
QMessageBox.critical(self.ui, 'Failed to load files', str(e))
raise

self.create_table()
self.setup_gui()
self.enable_read()
Expand Down

0 comments on commit dca8716

Please sign in to comment.