2012-09-09 23:07:36 +00:00
|
|
|
from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE
|
2012-07-12 19:35:58 +00:00
|
|
|
from pyqtgraph.python2_3 import asUnicode
|
2012-03-02 02:55:32 +00:00
|
|
|
from pyqtgraph.WidgetGroup import WidgetGroup
|
2012-09-09 23:07:36 +00:00
|
|
|
|
|
|
|
if USE_PYSIDE:
|
|
|
|
from .axisCtrlTemplate_pyside import Ui_Form as AxisCtrlTemplate
|
|
|
|
else:
|
|
|
|
from .axisCtrlTemplate_pyqt import Ui_Form as AxisCtrlTemplate
|
|
|
|
|
2012-06-18 18:00:19 +00:00
|
|
|
import weakref
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
class ViewBoxMenu(QtGui.QMenu):
|
|
|
|
def __init__(self, view):
|
|
|
|
QtGui.QMenu.__init__(self)
|
|
|
|
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view = weakref.ref(view) ## keep weakref to view to avoid circular reference (don't know why, but this prevents the ViewBox from being collected)
|
2012-03-02 02:55:32 +00:00
|
|
|
self.valid = False ## tells us whether the ui needs to be updated
|
2012-06-18 18:00:19 +00:00
|
|
|
self.viewMap = weakref.WeakValueDictionary() ## weakrefs to all views listed in the link combos
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
self.setTitle("ViewBox options")
|
|
|
|
self.viewAll = QtGui.QAction("View All", self)
|
|
|
|
self.viewAll.triggered.connect(self.autoRange)
|
|
|
|
self.addAction(self.viewAll)
|
|
|
|
|
|
|
|
self.axes = []
|
|
|
|
self.ctrl = []
|
|
|
|
self.widgetGroups = []
|
|
|
|
self.dv = QtGui.QDoubleValidator(self)
|
|
|
|
for axis in 'XY':
|
|
|
|
m = QtGui.QMenu()
|
|
|
|
m.setTitle("%s Axis" % axis)
|
|
|
|
w = QtGui.QWidget()
|
|
|
|
ui = AxisCtrlTemplate()
|
|
|
|
ui.setupUi(w)
|
|
|
|
a = QtGui.QWidgetAction(self)
|
|
|
|
a.setDefaultWidget(w)
|
|
|
|
m.addAction(a)
|
|
|
|
self.addMenu(m)
|
|
|
|
self.axes.append(m)
|
|
|
|
self.ctrl.append(ui)
|
|
|
|
wg = WidgetGroup(w)
|
|
|
|
self.widgetGroups.append(w)
|
|
|
|
|
|
|
|
connects = [
|
|
|
|
(ui.mouseCheck.toggled, 'MouseToggled'),
|
|
|
|
(ui.manualRadio.clicked, 'ManualClicked'),
|
|
|
|
(ui.minText.editingFinished, 'MinTextChanged'),
|
|
|
|
(ui.maxText.editingFinished, 'MaxTextChanged'),
|
|
|
|
(ui.autoRadio.clicked, 'AutoClicked'),
|
|
|
|
(ui.autoPercentSpin.valueChanged, 'AutoSpinChanged'),
|
|
|
|
(ui.linkCombo.currentIndexChanged, 'LinkComboChanged'),
|
2012-04-30 22:20:27 +00:00
|
|
|
(ui.autoPanCheck.toggled, 'AutoPanToggled'),
|
|
|
|
(ui.visibleOnlyCheck.toggled, 'VisibleOnlyToggled')
|
2012-03-02 02:55:32 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for sig, fn in connects:
|
|
|
|
sig.connect(getattr(self, axis.lower()+fn))
|
2012-06-18 18:00:19 +00:00
|
|
|
|
|
|
|
self.ctrl[0].invertCheck.hide() ## no invert for x-axis
|
|
|
|
self.ctrl[1].invertCheck.toggled.connect(self.yInvertToggled)
|
2012-03-11 15:59:45 +00:00
|
|
|
## exporting is handled by GraphicsScene now
|
|
|
|
#self.export = QtGui.QMenu("Export")
|
|
|
|
#self.setExportMethods(view.exportMethods)
|
|
|
|
#self.addMenu(self.export)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
self.leftMenu = QtGui.QMenu("Mouse Mode")
|
|
|
|
group = QtGui.QActionGroup(self)
|
|
|
|
pan = self.leftMenu.addAction("3 button", self.set3ButtonMode)
|
|
|
|
zoom = self.leftMenu.addAction("1 button", self.set1ButtonMode)
|
|
|
|
pan.setCheckable(True)
|
|
|
|
zoom.setCheckable(True)
|
|
|
|
pan.setActionGroup(group)
|
|
|
|
zoom.setActionGroup(group)
|
|
|
|
self.mouseModes = [pan, zoom]
|
|
|
|
self.addMenu(self.leftMenu)
|
|
|
|
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().sigStateChanged.connect(self.viewStateChanged)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
self.updateState()
|
|
|
|
|
|
|
|
def copy(self):
|
|
|
|
m = QtGui.QMenu()
|
|
|
|
for sm in self.subMenus():
|
|
|
|
if isinstance(sm, QtGui.QMenu):
|
|
|
|
m.addMenu(sm)
|
|
|
|
else:
|
|
|
|
m.addAction(sm)
|
|
|
|
m.setTitle(self.title())
|
|
|
|
return m
|
|
|
|
|
|
|
|
def subMenus(self):
|
|
|
|
if not self.valid:
|
|
|
|
self.updateState()
|
2012-03-11 15:59:45 +00:00
|
|
|
return [self.viewAll] + self.axes + [self.leftMenu]
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setExportMethods(self, methods):
|
|
|
|
self.exportMethods = methods
|
|
|
|
self.export.clear()
|
2012-05-11 22:05:41 +00:00
|
|
|
for opt, fn in methods.items():
|
2012-03-02 02:55:32 +00:00
|
|
|
self.export.addAction(opt, self.exportMethod)
|
|
|
|
|
|
|
|
|
|
|
|
def viewStateChanged(self):
|
|
|
|
self.valid = False
|
|
|
|
if self.ctrl[0].minText.isVisible() or self.ctrl[1].minText.isVisible():
|
|
|
|
self.updateState()
|
|
|
|
|
|
|
|
def updateState(self):
|
2012-06-18 18:00:19 +00:00
|
|
|
## Something about the viewbox has changed; update the menu GUI
|
|
|
|
|
|
|
|
state = self.view().getState(copy=False)
|
2012-03-02 02:55:32 +00:00
|
|
|
if state['mouseMode'] == ViewBox.PanMode:
|
|
|
|
self.mouseModes[0].setChecked(True)
|
|
|
|
else:
|
|
|
|
self.mouseModes[1].setChecked(True)
|
|
|
|
|
2012-06-18 18:00:19 +00:00
|
|
|
for i in [0,1]: # x, y
|
2012-03-02 02:55:32 +00:00
|
|
|
tr = state['targetRange'][i]
|
|
|
|
self.ctrl[i].minText.setText("%0.5g" % tr[0])
|
|
|
|
self.ctrl[i].maxText.setText("%0.5g" % tr[1])
|
|
|
|
if state['autoRange'][i] is not False:
|
|
|
|
self.ctrl[i].autoRadio.setChecked(True)
|
2012-05-08 21:56:55 +00:00
|
|
|
if state['autoRange'][i] is not True:
|
|
|
|
self.ctrl[i].autoPercentSpin.setValue(state['autoRange'][i]*100)
|
2012-03-02 02:55:32 +00:00
|
|
|
else:
|
|
|
|
self.ctrl[i].manualRadio.setChecked(True)
|
|
|
|
self.ctrl[i].mouseCheck.setChecked(state['mouseEnabled'][i])
|
|
|
|
|
2012-06-18 18:00:19 +00:00
|
|
|
## Update combo to show currently linked view
|
2012-03-02 02:55:32 +00:00
|
|
|
c = self.ctrl[i].linkCombo
|
|
|
|
c.blockSignals(True)
|
|
|
|
try:
|
2012-06-18 18:00:19 +00:00
|
|
|
view = state['linkedViews'][i] ## will always be string or None
|
2012-03-02 02:55:32 +00:00
|
|
|
if view is None:
|
|
|
|
view = ''
|
2012-03-21 02:39:37 +00:00
|
|
|
|
2012-06-18 18:00:19 +00:00
|
|
|
ind = c.findText(view)
|
2012-03-21 02:39:37 +00:00
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
if ind == -1:
|
|
|
|
ind = 0
|
|
|
|
c.setCurrentIndex(ind)
|
|
|
|
finally:
|
|
|
|
c.blockSignals(False)
|
|
|
|
|
2012-05-08 21:56:55 +00:00
|
|
|
self.ctrl[i].autoPanCheck.setChecked(state['autoPan'][i])
|
|
|
|
self.ctrl[i].visibleOnlyCheck.setChecked(state['autoVisibleOnly'][i])
|
2012-06-18 18:00:19 +00:00
|
|
|
|
|
|
|
self.ctrl[1].invertCheck.setChecked(state['yInverted'])
|
2012-03-02 02:55:32 +00:00
|
|
|
self.valid = True
|
|
|
|
|
|
|
|
|
|
|
|
def autoRange(self):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().autoRange() ## don't let signal call this directly--it'll add an unwanted argument
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def xMouseToggled(self, b):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setMouseEnabled(x=b)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def xManualClicked(self):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().enableAutoRange(ViewBox.XAxis, False)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def xMinTextChanged(self):
|
|
|
|
self.ctrl[0].manualRadio.setChecked(True)
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setXRange(float(self.ctrl[0].minText.text()), float(self.ctrl[0].maxText.text()), padding=0)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def xMaxTextChanged(self):
|
|
|
|
self.ctrl[0].manualRadio.setChecked(True)
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setXRange(float(self.ctrl[0].minText.text()), float(self.ctrl[0].maxText.text()), padding=0)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def xAutoClicked(self):
|
|
|
|
val = self.ctrl[0].autoPercentSpin.value() * 0.01
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().enableAutoRange(ViewBox.XAxis, val)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def xAutoSpinChanged(self, val):
|
|
|
|
self.ctrl[0].autoRadio.setChecked(True)
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().enableAutoRange(ViewBox.XAxis, val*0.01)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def xLinkComboChanged(self, ind):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setXLink(str(self.ctrl[0].linkCombo.currentText()))
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2012-04-30 22:20:27 +00:00
|
|
|
def xAutoPanToggled(self, b):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setAutoPan(x=b)
|
2012-04-30 22:20:27 +00:00
|
|
|
|
|
|
|
def xVisibleOnlyToggled(self, b):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setAutoVisible(x=b)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def yMouseToggled(self, b):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setMouseEnabled(y=b)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def yManualClicked(self):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().enableAutoRange(ViewBox.YAxis, False)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def yMinTextChanged(self):
|
|
|
|
self.ctrl[1].manualRadio.setChecked(True)
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setYRange(float(self.ctrl[1].minText.text()), float(self.ctrl[1].maxText.text()), padding=0)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def yMaxTextChanged(self):
|
|
|
|
self.ctrl[1].manualRadio.setChecked(True)
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setYRange(float(self.ctrl[1].minText.text()), float(self.ctrl[1].maxText.text()), padding=0)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def yAutoClicked(self):
|
|
|
|
val = self.ctrl[1].autoPercentSpin.value() * 0.01
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().enableAutoRange(ViewBox.YAxis, val)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def yAutoSpinChanged(self, val):
|
|
|
|
self.ctrl[1].autoRadio.setChecked(True)
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().enableAutoRange(ViewBox.YAxis, val*0.01)
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def yLinkComboChanged(self, ind):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setYLink(str(self.ctrl[1].linkCombo.currentText()))
|
2012-03-02 02:55:32 +00:00
|
|
|
|
2012-04-30 22:20:27 +00:00
|
|
|
def yAutoPanToggled(self, b):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setAutoPan(y=b)
|
2012-04-30 22:20:27 +00:00
|
|
|
|
|
|
|
def yVisibleOnlyToggled(self, b):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setAutoVisible(y=b)
|
2012-04-30 22:20:27 +00:00
|
|
|
|
2012-06-18 18:00:19 +00:00
|
|
|
def yInvertToggled(self, b):
|
|
|
|
self.view().invertY(b)
|
2012-04-30 22:20:27 +00:00
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def exportMethod(self):
|
|
|
|
act = self.sender()
|
|
|
|
self.exportMethods[str(act.text())]()
|
|
|
|
|
|
|
|
|
|
|
|
def set3ButtonMode(self):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setLeftButtonAction('pan')
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
def set1ButtonMode(self):
|
2012-06-18 18:00:19 +00:00
|
|
|
self.view().setLeftButtonAction('rect')
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setViewList(self, views):
|
2012-06-18 18:00:19 +00:00
|
|
|
names = ['']
|
|
|
|
self.viewMap.clear()
|
|
|
|
|
|
|
|
## generate list of views to show in the link combo
|
|
|
|
for v in views:
|
|
|
|
name = v.name
|
|
|
|
if name is None: ## unnamed views do not show up in the view list (although they are linkable)
|
|
|
|
continue
|
|
|
|
names.append(name)
|
|
|
|
self.viewMap[name] = v
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
for i in [0,1]:
|
|
|
|
c = self.ctrl[i].linkCombo
|
2012-05-11 22:05:41 +00:00
|
|
|
current = asUnicode(c.currentText())
|
2012-03-02 02:55:32 +00:00
|
|
|
c.blockSignals(True)
|
|
|
|
changed = True
|
|
|
|
try:
|
|
|
|
c.clear()
|
2012-06-18 18:00:19 +00:00
|
|
|
for name in names:
|
|
|
|
c.addItem(name)
|
|
|
|
if name == current:
|
2012-03-02 02:55:32 +00:00
|
|
|
changed = False
|
|
|
|
c.setCurrentIndex(c.count()-1)
|
|
|
|
finally:
|
|
|
|
c.blockSignals(False)
|
|
|
|
|
|
|
|
if changed:
|
|
|
|
c.setCurrentIndex(0)
|
|
|
|
c.currentIndexChanged.emit(c.currentIndex())
|
|
|
|
|
2012-05-11 22:05:41 +00:00
|
|
|
from .ViewBox import ViewBox
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
|