Minor changes and fixes:
- documentation updates - PlotItem informs all items when switching to log mode - GradientEditorItem has sigGradientChangeFinished - ParameterTree list types check linits on initialization - Fixed RuntimeError in TreeWidget.clear()
This commit is contained in:
parent
b09182d19a
commit
679de86509
@ -208,6 +208,10 @@ class DockArea(Container, QtGui.QWidget, DockDrop):
|
|||||||
def restoreState(self, state):
|
def restoreState(self, state):
|
||||||
"""
|
"""
|
||||||
Restore Dock configuration as generated by saveState.
|
Restore Dock configuration as generated by saveState.
|
||||||
|
|
||||||
|
Note that this function does not create any Docks--it will only
|
||||||
|
restore the arrangement of an existing set of Docks.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
## 1) make dict of all docks and list of existing containers
|
## 1) make dict of all docks and list of existing containers
|
||||||
@ -240,8 +244,11 @@ class DockArea(Container, QtGui.QWidget, DockDrop):
|
|||||||
typ, contents, state = state
|
typ, contents, state = state
|
||||||
pfx = " " * depth
|
pfx = " " * depth
|
||||||
if typ == 'dock':
|
if typ == 'dock':
|
||||||
obj = docks[contents]
|
try:
|
||||||
del docks[contents]
|
obj = docks[contents]
|
||||||
|
del docks[contents]
|
||||||
|
except KeyError:
|
||||||
|
raise Exception('Cannot restore dock state; no dock with name "%s"' % contents)
|
||||||
else:
|
else:
|
||||||
obj = self.makeContainer(typ)
|
obj = self.makeContainer(typ)
|
||||||
|
|
||||||
@ -270,7 +277,7 @@ class DockArea(Container, QtGui.QWidget, DockDrop):
|
|||||||
|
|
||||||
if isinstance(obj, Dock):
|
if isinstance(obj, Dock):
|
||||||
d[obj.name()] = obj
|
d[obj.name()] = obj
|
||||||
else:
|
elif obj is not None:
|
||||||
c.append(obj)
|
c.append(obj)
|
||||||
for i in range(obj.count()):
|
for i in range(obj.count()):
|
||||||
o2 = obj.widget(i)
|
o2 = obj.widget(i)
|
||||||
|
@ -165,6 +165,9 @@ class TickSliderItem(GraphicsWidget):
|
|||||||
tick.setPos(pos)
|
tick.setPos(pos)
|
||||||
self.ticks[tick] = float(newX) / self.length
|
self.ticks[tick] = float(newX) / self.length
|
||||||
|
|
||||||
|
def tickMoveFinished(self, tick):
|
||||||
|
pass
|
||||||
|
|
||||||
def tickClicked(self, tick, ev):
|
def tickClicked(self, tick, ev):
|
||||||
if ev.button() == QtCore.Qt.RightButton:
|
if ev.button() == QtCore.Qt.RightButton:
|
||||||
self.removeTick(tick)
|
self.removeTick(tick)
|
||||||
@ -340,16 +343,18 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
customizable by the user. :class: `GradientWidget <pyqtgraph.GradientWidget>` provides a widget
|
customizable by the user. :class: `GradientWidget <pyqtgraph.GradientWidget>` provides a widget
|
||||||
with a GradientEditorItem that can be added to a GUI.
|
with a GradientEditorItem that can be added to a GUI.
|
||||||
|
|
||||||
======================== ===========================================================
|
================================ ===========================================================
|
||||||
**Signals**
|
**Signals**
|
||||||
sigGradientChanged(self) Signal is emitted anytime the gradient changes. The signal
|
sigGradientChanged(self) Signal is emitted anytime the gradient changes. The signal
|
||||||
is emitted in real time while ticks are being dragged or
|
is emitted in real time while ticks are being dragged or
|
||||||
colors are being changed.
|
colors are being changed.
|
||||||
======================== ===========================================================
|
sigGradientChangeFinished(self) Signal is emitted when the gradient is finished changing.
|
||||||
|
================================ ===========================================================
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
sigGradientChanged = QtCore.Signal(object)
|
sigGradientChanged = QtCore.Signal(object)
|
||||||
|
sigGradientChangeFinished = QtCore.Signal(object)
|
||||||
|
|
||||||
def __init__(self, *args, **kargs):
|
def __init__(self, *args, **kargs):
|
||||||
"""
|
"""
|
||||||
@ -381,6 +386,7 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
|
|
||||||
self.colorDialog.currentColorChanged.connect(self.currentColorChanged)
|
self.colorDialog.currentColorChanged.connect(self.currentColorChanged)
|
||||||
self.colorDialog.rejected.connect(self.currentColorRejected)
|
self.colorDialog.rejected.connect(self.currentColorRejected)
|
||||||
|
self.colorDialog.accepted.connect(self.currentColorAccepted)
|
||||||
|
|
||||||
self.backgroundRect.setParentItem(self)
|
self.backgroundRect.setParentItem(self)
|
||||||
self.gradRect.setParentItem(self)
|
self.gradRect.setParentItem(self)
|
||||||
@ -508,6 +514,9 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
self.setTickColor(self.currentTick, self.currentTickColor)
|
self.setTickColor(self.currentTick, self.currentTickColor)
|
||||||
self.updateGradient()
|
self.updateGradient()
|
||||||
|
|
||||||
|
def currentColorAccepted(self):
|
||||||
|
self.sigGradientChangeFinished.emit(self)
|
||||||
|
|
||||||
def tickClicked(self, tick, ev):
|
def tickClicked(self, tick, ev):
|
||||||
#private
|
#private
|
||||||
if ev.button() == QtCore.Qt.LeftButton:
|
if ev.button() == QtCore.Qt.LeftButton:
|
||||||
@ -533,6 +542,9 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
TickSliderItem.tickMoved(self, tick, pos)
|
TickSliderItem.tickMoved(self, tick, pos)
|
||||||
self.updateGradient()
|
self.updateGradient()
|
||||||
|
|
||||||
|
def tickMoveFinished(self, tick):
|
||||||
|
self.sigGradientChangeFinished.emit(self)
|
||||||
|
|
||||||
|
|
||||||
def getGradient(self):
|
def getGradient(self):
|
||||||
"""Return a QLinearGradient object."""
|
"""Return a QLinearGradient object."""
|
||||||
@ -669,7 +681,7 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
TickSliderItem.mouseReleaseEvent(self, ev)
|
TickSliderItem.mouseReleaseEvent(self, ev)
|
||||||
self.updateGradient()
|
self.updateGradient()
|
||||||
|
|
||||||
def addTick(self, x, color=None, movable=True):
|
def addTick(self, x, color=None, movable=True, finish=True):
|
||||||
"""
|
"""
|
||||||
Add a tick to the gradient. Return the tick.
|
Add a tick to the gradient. Return the tick.
|
||||||
|
|
||||||
@ -688,7 +700,17 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
t = TickSliderItem.addTick(self, x, color=color, movable=movable)
|
t = TickSliderItem.addTick(self, x, color=color, movable=movable)
|
||||||
t.colorChangeAllowed = True
|
t.colorChangeAllowed = True
|
||||||
t.removeAllowed = True
|
t.removeAllowed = True
|
||||||
|
|
||||||
|
if finish:
|
||||||
|
self.sigGradientChangeFinished.emit(self)
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
def removeTick(self, tick, finish=True):
|
||||||
|
TickSliderItem.removeTick(self, tick)
|
||||||
|
if finish:
|
||||||
|
self.sigGradientChangeFinished.emit(self)
|
||||||
|
|
||||||
|
|
||||||
def saveState(self):
|
def saveState(self):
|
||||||
"""
|
"""
|
||||||
@ -723,13 +745,14 @@ class GradientEditorItem(TickSliderItem):
|
|||||||
## public
|
## public
|
||||||
self.setColorMode(state['mode'])
|
self.setColorMode(state['mode'])
|
||||||
for t in list(self.ticks.keys()):
|
for t in list(self.ticks.keys()):
|
||||||
self.removeTick(t)
|
self.removeTick(t, finish=False)
|
||||||
for t in state['ticks']:
|
for t in state['ticks']:
|
||||||
c = QtGui.QColor(*t[1])
|
c = QtGui.QColor(*t[1])
|
||||||
self.addTick(t[0], c)
|
self.addTick(t[0], c, finish=False)
|
||||||
self.updateGradient()
|
self.updateGradient()
|
||||||
|
self.sigGradientChangeFinished.emit(self)
|
||||||
|
|
||||||
|
|
||||||
class Tick(GraphicsObject):
|
class Tick(GraphicsObject):
|
||||||
## private class
|
## private class
|
||||||
|
|
||||||
@ -791,6 +814,7 @@ class Tick(GraphicsObject):
|
|||||||
if ev.isFinish():
|
if ev.isFinish():
|
||||||
self.moving = False
|
self.moving = False
|
||||||
self.sigMoved.emit(self)
|
self.sigMoved.emit(self)
|
||||||
|
self.view().tickMoveFinished(self)
|
||||||
|
|
||||||
def mouseClickEvent(self, ev):
|
def mouseClickEvent(self, ev):
|
||||||
if ev.button() == QtCore.Qt.RightButton and self.moving:
|
if ev.button() == QtCore.Qt.RightButton and self.moving:
|
||||||
|
@ -361,9 +361,11 @@ class PlotDataItem(GraphicsObject):
|
|||||||
|
|
||||||
self.updateItems()
|
self.updateItems()
|
||||||
prof.mark('update items')
|
prof.mark('update items')
|
||||||
|
|
||||||
view = self.getViewBox()
|
view = self.getViewBox()
|
||||||
if view is not None:
|
if view is not None:
|
||||||
view.itemBoundsChanged(self) ## inform view so it can update its range if it wants
|
view.itemBoundsChanged(self) ## inform view so it can update its range if it wants
|
||||||
|
|
||||||
self.sigPlotChanged.emit(self)
|
self.sigPlotChanged.emit(self)
|
||||||
prof.mark('emit')
|
prof.mark('emit')
|
||||||
prof.finish()
|
prof.finish()
|
||||||
|
@ -506,12 +506,14 @@ class PlotItem(GraphicsWidget):
|
|||||||
self.curves.append(item)
|
self.curves.append(item)
|
||||||
#self.addItem(c)
|
#self.addItem(c)
|
||||||
|
|
||||||
|
if hasattr(item, 'setLogMode'):
|
||||||
|
item.setLogMode(self.ctrl.logXCheck.isChecked(), self.ctrl.logYCheck.isChecked())
|
||||||
|
|
||||||
if isinstance(item, PlotDataItem):
|
if isinstance(item, PlotDataItem):
|
||||||
## configure curve for this plot
|
## configure curve for this plot
|
||||||
(alpha, auto) = self.alphaState()
|
(alpha, auto) = self.alphaState()
|
||||||
item.setAlpha(alpha, auto)
|
item.setAlpha(alpha, auto)
|
||||||
item.setFftMode(self.ctrl.fftCheck.isChecked())
|
item.setFftMode(self.ctrl.fftCheck.isChecked())
|
||||||
item.setLogMode(self.ctrl.logXCheck.isChecked(), self.ctrl.logYCheck.isChecked())
|
|
||||||
item.setDownsampling(self.downsampleMode())
|
item.setDownsampling(self.downsampleMode())
|
||||||
item.setPointMode(self.pointMode())
|
item.setPointMode(self.pointMode())
|
||||||
|
|
||||||
@ -526,6 +528,7 @@ class PlotItem(GraphicsWidget):
|
|||||||
#c.connect(c, QtCore.SIGNAL('plotChanged'), self.plotChanged)
|
#c.connect(c, QtCore.SIGNAL('plotChanged'), self.plotChanged)
|
||||||
#item.sigPlotChanged.connect(self.plotChanged)
|
#item.sigPlotChanged.connect(self.plotChanged)
|
||||||
#self.plotChanged()
|
#self.plotChanged()
|
||||||
|
|
||||||
|
|
||||||
def addDataItem(self, item, *args):
|
def addDataItem(self, item, *args):
|
||||||
print("PlotItem.addDataItem is deprecated. Use addItem instead.")
|
print("PlotItem.addDataItem is deprecated. Use addItem instead.")
|
||||||
@ -878,8 +881,9 @@ class PlotItem(GraphicsWidget):
|
|||||||
def updateLogMode(self):
|
def updateLogMode(self):
|
||||||
x = self.ctrl.logXCheck.isChecked()
|
x = self.ctrl.logXCheck.isChecked()
|
||||||
y = self.ctrl.logYCheck.isChecked()
|
y = self.ctrl.logYCheck.isChecked()
|
||||||
for c in self.curves:
|
for i in self.items:
|
||||||
c.setLogMode(x,y)
|
if hasattr(i, 'setLogMode'):
|
||||||
|
i.setLogMode(x,y)
|
||||||
self.getAxis('bottom').setLogMode(x)
|
self.getAxis('bottom').setLogMode(x)
|
||||||
self.getAxis('top').setLogMode(x)
|
self.getAxis('top').setLogMode(x)
|
||||||
self.getAxis('left').setLogMode(y)
|
self.getAxis('left').setLogMode(y)
|
||||||
|
@ -516,6 +516,7 @@ class ListParameter(Parameter):
|
|||||||
if opts.get('limits', None) is None:
|
if opts.get('limits', None) is None:
|
||||||
opts['limits'] = []
|
opts['limits'] = []
|
||||||
Parameter.__init__(self, **opts)
|
Parameter.__init__(self, **opts)
|
||||||
|
self.setLimits(opts['limits'])
|
||||||
|
|
||||||
def setLimits(self, limits):
|
def setLimits(self, limits):
|
||||||
self.forward, self.reverse = self.mapping(limits)
|
self.forward, self.reverse = self.mapping(limits)
|
||||||
|
@ -11,6 +11,7 @@ __all__ = ['TickSlider', 'GradientWidget', 'BlackWhiteSlider']
|
|||||||
class GradientWidget(GraphicsView):
|
class GradientWidget(GraphicsView):
|
||||||
|
|
||||||
sigGradientChanged = QtCore.Signal(object)
|
sigGradientChanged = QtCore.Signal(object)
|
||||||
|
sigGradientChangeFinished = QtCore.Signal(object)
|
||||||
|
|
||||||
def __init__(self, parent=None, orientation='bottom', *args, **kargs):
|
def __init__(self, parent=None, orientation='bottom', *args, **kargs):
|
||||||
GraphicsView.__init__(self, parent, useOpenGL=False, background=None)
|
GraphicsView.__init__(self, parent, useOpenGL=False, background=None)
|
||||||
@ -18,6 +19,7 @@ class GradientWidget(GraphicsView):
|
|||||||
kargs['tickPen'] = 'k'
|
kargs['tickPen'] = 'k'
|
||||||
self.item = GradientEditorItem(*args, **kargs)
|
self.item = GradientEditorItem(*args, **kargs)
|
||||||
self.item.sigGradientChanged.connect(self.sigGradientChanged)
|
self.item.sigGradientChanged.connect(self.sigGradientChanged)
|
||||||
|
self.item.sigGradientChangeFinished.connect(self.sigGradientChangeFinished)
|
||||||
self.setCentralItem(self.item)
|
self.setCentralItem(self.item)
|
||||||
self.setOrientation(orientation)
|
self.setOrientation(orientation)
|
||||||
self.setCacheMode(self.CacheNone)
|
self.setCacheMode(self.CacheNone)
|
||||||
|
@ -201,8 +201,10 @@ class TreeWidget(QtGui.QTreeWidget):
|
|||||||
for item in items:
|
for item in items:
|
||||||
self.prepareMove(item)
|
self.prepareMove(item)
|
||||||
QtGui.QTreeWidget.clear(self)
|
QtGui.QTreeWidget.clear(self)
|
||||||
for item in items:
|
|
||||||
self.informTreeWidgetChange(item)
|
## Why do we want to do this? It causes RuntimeErrors.
|
||||||
|
#for item in items:
|
||||||
|
#self.informTreeWidgetChange(item)
|
||||||
|
|
||||||
|
|
||||||
class TreeWidgetItem(QtGui.QTreeWidgetItem):
|
class TreeWidgetItem(QtGui.QTreeWidgetItem):
|
||||||
|
Loading…
Reference in New Issue
Block a user