Skip to content

Commit

Permalink
Factorise warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kif committed Jan 31, 2025
1 parent 529905d commit 20a72ca
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/pyFAI/gui/pilx/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
from .widgets.MapPlotWidget import MapPlotWidget
from .widgets.TitleWidget import TitleWidget
from ...io.integration_config import WorkerConfig

logger = logging.getLogger(__name__)

class MainWindow(qt.QMainWindow):
sigFileChanged = qt.Signal(str)
Expand Down Expand Up @@ -175,23 +175,15 @@ def initData(self,
try:
image_grp = h5file[path]
except KeyError:
error_msg = f"Cannot access diffraction images at {path}: no such path."
logging.warning(error_msg)
status_bar = self.statusBar()
if status_bar:
status_bar.showMessage(error_msg)
self.warning(f"Cannot access diffraction images at {path}: no such path.")
else:
if isinstance(image_grp, h5py.Group):
lst = []
for key in image_grp:
try:
ds = image_grp[key]
except:
error_msg = f"Cannot access diffraction images at {path}/{key}: not a valid dataset."
logging.warning(error_msg)
status_bar = self.statusBar()
if status_bar:
status_bar.showMessage(error_msg)
self.warning(f"Cannot access diffraction images at {path}/{key}: not a valid dataset.")
else:
if key.startswith(base) and isinstance(ds, h5py.Dataset):
lst.append(key)
Expand All @@ -200,11 +192,7 @@ def initData(self,
for key in lst:
self._dataset_paths[posixpath.join(path, key)] = len(image_grp[key])
else:
error_msg = f"Cannot access diffraction images at {path}: not a group."
logging.warning(error_msg)
status_bar = self.statusBar()
if status_bar:
status_bar.showMessage(error_msg)
self.warning(f"Cannot access diffraction images at {path}: not a group.")

self._radial_matrix = compute_radial_values(self.worker_config)
self._delta_radial_over_2 = delta_radial / 2
Expand Down Expand Up @@ -262,20 +250,20 @@ def displayImageAtIndices(self, indices: ImageIndices):
nxprocess = h5file[self._nxprocess_path]
map_shape = get_dataset(nxprocess, "result/intensity").shape
image_index = row * map_shape[1] + col + self._offset
image_dset = None
for dataset_path, size in self._dataset_paths.items():
if image_index < size:
break
else:
image_index -= size
if image_dset is None:
self.warning(f"No diffraction data images found in {self._file_name}")
return
try:
image_dset = get_dataset(h5file, dataset_path)
except KeyError:
image_link = h5file.get(dataset_path, getlink=True)
error_msg = f"Cannot access diffraction images at {image_link}"
logging.warning(error_msg)
status_bar = self.statusBar()
if status_bar:
status_bar.showMessage(error_msg)
self.warning(f"Cannot access diffraction images at {image_link}")
return

if image_index >= len(image_dset):
Expand Down Expand Up @@ -474,3 +462,13 @@ def setNewBackgroundCurve(self, x: float, y: float):
def clearPoints(self):
for indices in self._fixed_indices.copy():
self.removeMapPoint(indices=indices)

def warning(self, error_msg):
"""Log a warning both in the terminal and in the status bar if possible
:param error_msg: string with the message
"""
logger.warning(error_msg)
status_bar = self.statusBar()
if status_bar:
status_bar.showMessage(error_msg)

0 comments on commit 20a72ca

Please sign in to comment.