summaryrefslogtreecommitdiff
path: root/silx/gui/plot/actions
diff options
context:
space:
mode:
Diffstat (limited to 'silx/gui/plot/actions')
-rwxr-xr-x[-rw-r--r--]silx/gui/plot/actions/control.py2
-rw-r--r--silx/gui/plot/actions/fit.py22
-rw-r--r--silx/gui/plot/actions/histogram.py1
-rw-r--r--silx/gui/plot/actions/io.py42
4 files changed, 39 insertions, 28 deletions
diff --git a/silx/gui/plot/actions/control.py b/silx/gui/plot/actions/control.py
index ec4a3de..e2fa6b1 100644..100755
--- a/silx/gui/plot/actions/control.py
+++ b/silx/gui/plot/actions/control.py
@@ -360,8 +360,8 @@ class ColormapAction(PlotAction):
# Run the dialog listening to colormap change
if checked is True:
- self._dialog.show()
self._updateColormap()
+ self._dialog.show()
else:
self._dialog.hide()
diff --git a/silx/gui/plot/actions/fit.py b/silx/gui/plot/actions/fit.py
index cb70733..6fc5c75 100644
--- a/silx/gui/plot/actions/fit.py
+++ b/silx/gui/plot/actions/fit.py
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2004-2017 European Synchrotron Radiation Facility
+# Copyright (c) 2004-2019 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -98,18 +98,15 @@ class FitAction(PlotToolAction):
plot, icon='math-fit', text='Fit curve',
tooltip='Open a fit dialog',
parent=parent)
- self.fit_widget = None
def _createToolWindow(self):
- window = qt.QMainWindow(parent=self.plot)
# import done here rather than at module level to avoid circular import
# FitWidget -> BackgroundWidget -> PlotWindow -> actions -> fit -> FitWidget
from ...fit.FitWidget import FitWidget
- fit_widget = FitWidget(parent=window)
- window.setCentralWidget(fit_widget)
- fit_widget.guibuttons.DismissButton.clicked.connect(window.close)
- fit_widget.sigFitWidgetSignal.connect(self.handle_signal)
- self.fit_widget = fit_widget
+
+ window = FitWidget(parent=self.plot)
+ window.setWindowFlags(qt.Qt.Window)
+ window.sigFitWidgetSignal.connect(self.handle_signal)
return window
def _connectPlot(self, window):
@@ -158,8 +155,8 @@ class FitAction(PlotToolAction):
self.x = item.getXData(copy=False)
self.y = item.getYData(copy=False)
- self.fit_widget.setData(self.x, self.y,
- xmin=self.xmin, xmax=self.xmax)
+ window.setData(self.x, self.y,
+ xmin=self.xmin, xmax=self.xmax)
window.setWindowTitle(
"Fitting " + self.legend +
" on x range %f-%f" % (self.xmin, self.xmax))
@@ -171,7 +168,10 @@ class FitAction(PlotToolAction):
fit_curve = self.plot.getCurve(fit_legend)
if ddict["event"] == "FitFinished":
- y_fit = self.fit_widget.fitmanager.gendata()
+ fit_widget = self._getToolWindow()
+ if fit_widget is None:
+ return
+ y_fit = fit_widget.fitmanager.gendata()
if fit_curve is None:
self.plot.addCurve(x_fit, y_fit,
fit_legend,
diff --git a/silx/gui/plot/actions/histogram.py b/silx/gui/plot/actions/histogram.py
index 9181f53..3bb3e6a 100644
--- a/silx/gui/plot/actions/histogram.py
+++ b/silx/gui/plot/actions/histogram.py
@@ -134,6 +134,7 @@ class PixelIntensitiesHistoAction(PlotToolAction):
window = Plot1D(parent=self.plot)
window.setWindowFlags(qt.Qt.Window)
window.setWindowTitle('Image Intensity Histogram')
+ window.setDataMargins(0.1, 0.1, 0.1, 0.1)
window.getXAxis().setLabel("Value")
window.getYAxis().setLabel("Count")
return window
diff --git a/silx/gui/plot/actions/io.py b/silx/gui/plot/actions/io.py
index 09e4a99..43b3b3a 100644
--- a/silx/gui/plot/actions/io.py
+++ b/silx/gui/plot/actions/io.py
@@ -131,6 +131,7 @@ class SaveAction(PlotAction):
IMAGE_FILTER_CSV_TAB = 'Image data as tab-separated CSV (*.csv)'
IMAGE_FILTER_RGB_PNG = 'Image as PNG (*.png)'
IMAGE_FILTER_NXDATA = 'Image as NXdata (%s)' % _NEXUS_HDF5_EXT_STR
+
DEFAULT_IMAGE_FILTERS = (IMAGE_FILTER_EDF,
IMAGE_FILTER_TIFF,
IMAGE_FILTER_NUMPY,
@@ -156,6 +157,8 @@ class SaveAction(PlotAction):
'image': OrderedDict(),
'scatter': OrderedDict()}
+ self._appendFilters = list(self.DEFAULT_APPEND_FILTERS)
+
# Initialize filters
for nameFilter in self.DEFAULT_ALL_FILTERS:
self.setFileFilter(
@@ -185,10 +188,11 @@ class SaveAction(PlotAction):
self.setShortcut(qt.QKeySequence.Save)
self.setShortcutContext(qt.Qt.WidgetShortcut)
- def _errorMessage(self, informativeText=''):
+ @staticmethod
+ def _errorMessage(informativeText='', parent=None):
"""Display an error message."""
# TODO issue with QMessageBox size fixed and too small
- msg = qt.QMessageBox(self.plot)
+ msg = qt.QMessageBox(parent)
msg.setIcon(qt.QMessageBox.Critical)
msg.setInformativeText(informativeText + ' ' + str(sys.exc_info()[1]))
msg.setDetailedText(traceback.format_exc())
@@ -220,7 +224,8 @@ class SaveAction(PlotAction):
ylabel = item.getYLabel() or self.plot.getYAxis().getLabel()
return xlabel, ylabel
- def _selectWriteableOutputGroup(self, filename):
+ @staticmethod
+ def _selectWriteableOutputGroup(filename, parent):
if os.path.exists(filename) and os.path.isfile(filename) \
and os.access(filename, os.W_OK):
entryPath = selectOutputGroup(filename)
@@ -232,11 +237,11 @@ class SaveAction(PlotAction):
# create new entry in new file
return "/entry"
else:
- self._errorMessage('Save failed (file access issue)\n')
+ SaveAction._errorMessage('Save failed (file access issue)\n', parent=parent)
return None
def _saveCurveAsNXdata(self, curve, filename):
- entryPath = self._selectWriteableOutputGroup(filename)
+ entryPath = self._selectWriteableOutputGroup(filename, parent=self.plot)
if entryPath is None:
return False
@@ -273,7 +278,7 @@ class SaveAction(PlotAction):
if curve is None:
curves = plot.getAllCurves()
if not curves:
- self._errorMessage("No curve to be saved")
+ self._errorMessage("No curve to be saved", parent=self.plot)
return False
curve = curves[0]
@@ -299,7 +304,7 @@ class SaveAction(PlotAction):
fmt=fmt, csvdelim=csvdelim,
autoheader=autoheader)
except IOError:
- self._errorMessage('Save failed\n')
+ self._errorMessage('Save failed\n', parent=self.plot)
return False
return True
@@ -317,7 +322,7 @@ class SaveAction(PlotAction):
curves = plot.getAllCurves()
if not curves:
- self._errorMessage("No curves to be saved")
+ self._errorMessage("No curves to be saved", parent=self.plot)
return False
curve = curves[0]
@@ -334,7 +339,7 @@ class SaveAction(PlotAction):
write_file_header=True,
close_file=False)
except IOError:
- self._errorMessage('Save failed\n')
+ self._errorMessage('Save failed\n', parent=self.plot)
return False
for curve in curves[1:]:
@@ -351,7 +356,7 @@ class SaveAction(PlotAction):
write_file_header=False,
close_file=False)
except IOError:
- self._errorMessage('Save failed\n')
+ self._errorMessage('Save failed\n', parent=self.plot)
return False
specfile.close()
@@ -391,12 +396,12 @@ class SaveAction(PlotAction):
try:
numpy.save(filename, data)
except IOError:
- self._errorMessage('Save failed\n')
+ self._errorMessage('Save failed\n', parent=self.plot)
return False
return True
elif nameFilter == self.IMAGE_FILTER_NXDATA:
- entryPath = self._selectWriteableOutputGroup(filename)
+ entryPath = self._selectWriteableOutputGroup(filename, parent=self.plot)
if entryPath is None:
return False
xorigin, yorigin = image.getOrigin()
@@ -438,7 +443,7 @@ class SaveAction(PlotAction):
autoheader=True)
except IOError:
- self._errorMessage('Save failed\n')
+ self._errorMessage('Save failed\n', parent=self.plot)
return False
return True
@@ -471,7 +476,7 @@ class SaveAction(PlotAction):
return False
if nameFilter == self.SCATTER_FILTER_NXDATA:
- entryPath = self._selectWriteableOutputGroup(filename)
+ entryPath = self._selectWriteableOutputGroup(filename, parent=self.plot)
if entryPath is None:
return False
scatter = plot.getScatter()
@@ -502,7 +507,7 @@ class SaveAction(PlotAction):
axes_errors=[xerror, yerror],
title=plot.getGraphTitle())
- def setFileFilter(self, dataKind, nameFilter, func, index=None):
+ def setFileFilter(self, dataKind, nameFilter, func, index=None, appendToFile=False):
"""Set a name filter to add/replace a file format support
:param str dataKind:
@@ -513,10 +518,15 @@ class SaveAction(PlotAction):
:param callable func: The function to call to perform saving.
Expected signature is:
bool func(PlotWidget plot, str filename, str nameFilter)
+ :param bool appendToFile: True to append the data into the selected
+ file.
:param integer index: Index of the filter in the final list (or None)
"""
assert dataKind in ('all', 'curve', 'curves', 'image', 'scatter')
+ if appendToFile:
+ self._appendFilters.append(nameFilter)
+
# first append or replace the new filter to prevent colissions
self._filters[dataKind][nameFilter] = func
if index is None:
@@ -601,7 +611,7 @@ class SaveAction(PlotAction):
def onFilterSelection(filt_):
# disable overwrite confirmation for NXdata types,
# because we append the data to existing files
- if filt_ in self.DEFAULT_APPEND_FILTERS:
+ if filt_ in self._appendFilters:
dialog.setOption(dialog.DontConfirmOverwrite)
else:
dialog.setOption(dialog.DontConfirmOverwrite, False)