Skip to content

Commit

Permalink
Merge pull request #803 from vasole/batch
Browse files Browse the repository at this point in the history
Verify risk of overwriting input file when choosing output directory
  • Loading branch information
vasole authored Apr 9, 2021
2 parents bb8c49e + 4d7311a commit e54f744
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
8 changes: 8 additions & 0 deletions PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ def __init__(self, parent=None, mca=False, buttons=False):
self._BUTTONS = buttons
self.build()

def sizeHint(self):
originalHint = qt.QWidget.sizeHint(self)
if isinstance(self.parent(), qt.QDialog):
return qt.QSize(2 * originalHint.width(),
originalHint.height())
else:
return qt.QSize(originalHint.width(),
originalHint.height())
def build(self):
self.mainLayout = qt.QVBoxLayout(self)
self.mainLayout.setContentsMargins(5, 5, 5, 0)
Expand Down
16 changes: 16 additions & 0 deletions PyMca5/PyMcaGui/pymca/PyMcaBatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,22 @@ def __goodOutputDir(self,outputdir):
else:
self.raise_()
return False
if len(self.fileList) == 1:
if HDF5SUPPORT:
try:
if h5py.is_hdf5(self.fileList[0]):
if os.path.dirname(os.path.abspath(self.fileList[0])) == \
os.path.abspath(outputdir):
msg = "Please specify a different output directory.\n"
msg += "Risk of overwritting input file."
qt.QMessageBox.critical(self,"ERROR", msg)
if QTVERSION < '4.0.0':
self.raiseW()
else:
self.raise_()
return False
except:
_logger.warning("Cannot verify suitability of output directory")
return True

def __getFileType(self,inputfile):
Expand Down
9 changes: 7 additions & 2 deletions PyMca5/PyMcaPhysics/xrf/McaAdvancedFitBatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# The PyMca X-Ray Fluorescence Toolkit
#
# Copyright (c) 2004-2020 European Synchrotron Radiation Facility
# Copyright (c) 2004-2021 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
Expand Down Expand Up @@ -330,8 +330,13 @@ def getFileHandle(self, inputfile):
# if (len(self._filelist) == 1) && (self.mcaStep > 1)
# it should attempt to avoid loading many times
# the stack into memory in case of multiple processes
if len(self._filelist) == 1:
scanlist = self.selection.get("entry", None)
else:
scanlist = None
return HDF5Stack1D.HDF5Stack1D(self._filelist,
self.selection)
self.selection,
scanlist=scanlist)
except:
raise

Expand Down

0 comments on commit e54f744

Please sign in to comment.