Commit 11954875 authored by Damien Naudet's avatar Damien Naudet

Started work on the colorbar.

parent ee2cfcac
......@@ -29,19 +29,63 @@ __authors__ = ["D. Naudet"]
__license__ = "MIT"
__date__ = "15/09/2016"
import weakref
import numpy as np
from matplotlib import cm
from silx.gui import qt as Qt
from silx.gui.plot import PlotWindow
from silx.gui.icons import getQIcon
from ...gui.icons import getQIcon as getKmapIcon
from ..widgets.RangeSlider import RangeSlider
from ..widgets.Input import StyledLineEdit
from ..widgets.Containers import GroupBox
class XsocsPlot2DColorDialog(Qt.QDialog):
"""
Color dialog for the XsocsPlot2D.
"""
def __init__(self, plot, **kwargs):
super(XsocsPlot2DColorDialog, self).__init__(plot, **kwargs)
self.__plot = weakref.ref(plot)
layout = Qt.QVBoxLayout(self)
grpBox = GroupBox('Colormap')
grpBoxLayout = Qt.QHBoxLayout(grpBox)
cmapCBox = Qt.QComboBox()
cmapCBox.addItems(['jet'])
grpBoxLayout.addWidget(cmapCBox)
layout.addWidget(grpBox)
grpBox = GroupBox('Range')
grpBoxLayout = Qt.QGridLayout(grpBox)
rngSlider = RangeSlider()
grpBoxLayout.addWidget(rngSlider, 0, 0, 1, 2)
minLabel = StyledLineEdit(nChar=6)
maxLabel = StyledLineEdit(nChar=6)
grpBoxLayout.addWidget(minLabel, 1, 0)
grpBoxLayout.addWidget(maxLabel, 1, 1)
layout.addWidget(grpBox)
bnBox = Qt.QDialogButtonBox(Qt.QDialogButtonBox.Close)
bnBox.button(Qt.QDialogButtonBox.Close).clicked.connect(self.accept)
layout.addWidget(bnBox)
class XsocsPlot2D(PlotWindow):
def __init__(self, *args, **kwargs):
super(XsocsPlot2D, self).__init__(*args, **kwargs)
def __init__(self, **kwargs):
super(XsocsPlot2D, self).__init__(**kwargs)
self.setActiveCurveHandling(False)
self.setKeepDataAspectRatio(True)
......@@ -59,6 +103,41 @@ class XsocsPlot2D(PlotWindow):
self.__optionsBase = optionsBase = Qt.QWidget(centralWid)
optionsLayout = Qt.QHBoxLayout(optionsBase)
optionsLayout.setContentsMargins(0, 0, 0, 0)
optionsLayout.setSpacing(0)
style = Qt.QApplication.style()
size = style.pixelMetric(Qt.QStyle.PM_SmallIconSize)
icon = style.standardIcon(Qt.QStyle.SP_ArrowRight)
showBarBn = Qt.QToolButton()
showBarBn.setIcon(icon)
showBarBn.setFixedWidth(size)
showBarBn.clicked.connect(self.__showBarBnClicked)
showBarBn.setAutoFillBackground(True)
self.__hidden = True
self.__firstShow = True
self.__optionsBaseA = optionsBaseA = Qt.QWidget()
optionsLayoutA = Qt.QHBoxLayout(optionsBaseA)
optionsLayoutA.setContentsMargins(0, 0, 0, 0)
optionsLayoutA.setSpacing(0)
rstZoomAction = self.resetZoomAction
rstToolBn = Qt.QToolButton()
rstToolBn.setDefaultAction(rstZoomAction)
optionsLayoutA.addWidget(rstToolBn)
optionsLayoutA.addWidget(showBarBn)
self.__optionsBaseB = optionsBaseB = Qt.QWidget()
optionsLayoutB = Qt.QHBoxLayout(optionsBaseB)
optionsLayoutB.setContentsMargins(0, 0, 0, 0)
optionsLayoutB.setSpacing(0)
# colormap dialog action
self.__colormapBn = colormapBn = Qt.QToolButton()
colormapBn.setDisabled(True)
colormapBn.setIcon(getQIcon('colormap'))
colormapBn.clicked.connect(self.__colormapBnClicked)
optionsLayoutB.addWidget(colormapBn)
icon = getKmapIcon('gears')
options = Qt.QToolButton()
......@@ -69,15 +148,6 @@ class XsocsPlot2D(PlotWindow):
menu = Qt.QMenu()
# apply log values
# self.__logAction = logAction = menu.addAction('Log')
self.__logAction = logAction = Qt.QAction('Log', self)
logAction.setIconVisibleInMenu(True)
logAction.setDisabled(True)
logAction.setCheckable(True)
logAction.triggered.connect(self.__logActionTriggered)
# menu.addAction(logAction)
# save to file action
self.saveAction.setIconVisibleInMenu(True)
menu.addAction(self.saveAction)
......@@ -134,33 +204,72 @@ class XsocsPlot2D(PlotWindow):
options.setMenu(menu)
rstZoomAction = self.resetZoomAction
rstToolBn = Qt.QToolButton()
rstToolBn.setDefaultAction(rstZoomAction)
optionsLayoutB.addWidget(options)
optionsLayout.addWidget(options)
optionsLayout.addWidget(rstToolBn)
optionsLayout.addWidget(optionsBaseB)
optionsLayout.addWidget(optionsBaseA)
def showEvent(self, event):
super(XsocsPlot2D, self).showEvent(event)
if self.__firstShow:
self.__moveOptionBar()
self.__firstShow = False
def resizeEvent(self, event):
super(XsocsPlot2D, self).resizeEvent(event)
self.__moveOptionBar()
def __moveOptionBar(self):
optionsBase = self.__optionsBase
optionsBaseB = self.__optionsBaseB
geom = self.centralWidget().geometry()
newPos = Qt.QPoint(0, geom.height() - optionsBase.height())
optionsBase.move(newPos)
def __logActionTriggered(self, checked):
for curve, values in self.__values.items():
info = self.getCurve(curve)
if info is None:
continue
if checked:
values = np.log(values - values.min() + 1)
min_, max_ = values.min(), values.max()
colormap = cm.jet
colors = colormap(
(values.astype(np.float64) - min_) / (max_ - min_))
self.addCurve(info[0], info[1], color=colors, legend=curve,
resetzoom=False)
if self.__hidden:
newPos = Qt.QPoint(0 - optionsBaseB.width(),
geom.height() - optionsBase.height())
else:
newPos = Qt.QPoint(0,
geom.height() - optionsBase.height())
if optionsBase.pos() != newPos:
optionsBase.move(newPos)
def __showBarBnClicked(self):
style = Qt.QApplication.style()
optionsBase = self.__optionsBase
optionsBaseB = self.__optionsBaseB
geom = self.centralWidget().geometry()
hiddenGeom = Qt.QPoint(0 - optionsBaseB.width(),
geom.height() - optionsBaseB.height())
visibleGeom = Qt.QPoint(0,
geom.height() - optionsBaseB.height())
if self.__hidden:
icon = Qt.QStyle.SP_ArrowLeft
startVal = hiddenGeom
endVal = visibleGeom
else:
icon = Qt.QStyle.SP_ArrowRight
startVal = visibleGeom
endVal = hiddenGeom
icon = style.standardIcon(icon)
self.sender().setIcon(icon)
self.__hidden = not self.__hidden
animation = Qt.QPropertyAnimation(optionsBase, 'pos', self)
animation.setDuration(300)
animation.setStartValue(startVal)
animation.setEndValue(endVal)
animation.start(Qt.QAbstractAnimation.DeleteWhenStopped)
def __colormapBnClicked(self):
dialog = XsocsPlot2DColorDialog(self)
self.setAttribute(Qt.Qt.WA_DeleteOnClose)
dialog.exec_()
def removeCurve(self, *args, **kwargs):
super(XsocsPlot2D, self).removeCurve(*args, **kwargs)
......@@ -172,7 +281,7 @@ class XsocsPlot2D(PlotWindow):
del self.__values[curve]
if len(self.__values) > 0:
self.__logAction.setDisabled(True)
self.__colormapBn.setDisabled(True)
def setPlotData(self, x, y,
values=None,
......@@ -200,9 +309,11 @@ class XsocsPlot2D(PlotWindow):
linestyle=linestyle,
resetzoom=resetzoom,
**kwargs)
if values is not None:
self.__values[legend] = values
if len(self.__values) > 0:
self.__logAction.setDisabled(False)
self.__colormapBn.setDisabled(False)
return legend
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment