Validate min/max text inputs in ViewBoxMenu (#1074)
This commit is contained in:
parent
6848824557
commit
f5e25622a7
@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
from ...Qt import QtCore, QtGui, QT_LIB
|
from ...Qt import QtCore, QtGui, QT_LIB
|
||||||
from ...python2_3 import asUnicode
|
from ...python2_3 import asUnicode
|
||||||
from ...WidgetGroup import WidgetGroup
|
from ...WidgetGroup import WidgetGroup
|
||||||
@ -48,8 +49,8 @@ class ViewBoxMenu(QtGui.QMenu):
|
|||||||
connects = [
|
connects = [
|
||||||
(ui.mouseCheck.toggled, 'MouseToggled'),
|
(ui.mouseCheck.toggled, 'MouseToggled'),
|
||||||
(ui.manualRadio.clicked, 'ManualClicked'),
|
(ui.manualRadio.clicked, 'ManualClicked'),
|
||||||
(ui.minText.editingFinished, 'MinTextChanged'),
|
(ui.minText.editingFinished, 'RangeTextChanged'),
|
||||||
(ui.maxText.editingFinished, 'MaxTextChanged'),
|
(ui.maxText.editingFinished, 'RangeTextChanged'),
|
||||||
(ui.autoRadio.clicked, 'AutoClicked'),
|
(ui.autoRadio.clicked, 'AutoClicked'),
|
||||||
(ui.autoPercentSpin.valueChanged, 'AutoSpinChanged'),
|
(ui.autoPercentSpin.valueChanged, 'AutoSpinChanged'),
|
||||||
(ui.linkCombo.currentIndexChanged, 'LinkComboChanged'),
|
(ui.linkCombo.currentIndexChanged, 'LinkComboChanged'),
|
||||||
@ -162,13 +163,9 @@ class ViewBoxMenu(QtGui.QMenu):
|
|||||||
def xManualClicked(self):
|
def xManualClicked(self):
|
||||||
self.view().enableAutoRange(ViewBox.XAxis, False)
|
self.view().enableAutoRange(ViewBox.XAxis, False)
|
||||||
|
|
||||||
def xMinTextChanged(self):
|
def xRangeTextChanged(self):
|
||||||
self.ctrl[0].manualRadio.setChecked(True)
|
self.ctrl[0].manualRadio.setChecked(True)
|
||||||
self.view().setXRange(float(self.ctrl[0].minText.text()), float(self.ctrl[0].maxText.text()), padding=0)
|
self.view().setXRange(*self._validateRangeText(0), padding=0)
|
||||||
|
|
||||||
def xMaxTextChanged(self):
|
|
||||||
self.ctrl[0].manualRadio.setChecked(True)
|
|
||||||
self.view().setXRange(float(self.ctrl[0].minText.text()), float(self.ctrl[0].maxText.text()), padding=0)
|
|
||||||
|
|
||||||
def xAutoClicked(self):
|
def xAutoClicked(self):
|
||||||
val = self.ctrl[0].autoPercentSpin.value() * 0.01
|
val = self.ctrl[0].autoPercentSpin.value() * 0.01
|
||||||
@ -194,13 +191,9 @@ class ViewBoxMenu(QtGui.QMenu):
|
|||||||
def yManualClicked(self):
|
def yManualClicked(self):
|
||||||
self.view().enableAutoRange(ViewBox.YAxis, False)
|
self.view().enableAutoRange(ViewBox.YAxis, False)
|
||||||
|
|
||||||
def yMinTextChanged(self):
|
def yRangeTextChanged(self):
|
||||||
self.ctrl[1].manualRadio.setChecked(True)
|
self.ctrl[1].manualRadio.setChecked(True)
|
||||||
self.view().setYRange(float(self.ctrl[1].minText.text()), float(self.ctrl[1].maxText.text()), padding=0)
|
self.view().setYRange(*self._validateRangeText(1), padding=0)
|
||||||
|
|
||||||
def yMaxTextChanged(self):
|
|
||||||
self.ctrl[1].manualRadio.setChecked(True)
|
|
||||||
self.view().setYRange(float(self.ctrl[1].minText.text()), float(self.ctrl[1].maxText.text()), padding=0)
|
|
||||||
|
|
||||||
def yAutoClicked(self):
|
def yAutoClicked(self):
|
||||||
val = self.ctrl[1].autoPercentSpin.value() * 0.01
|
val = self.ctrl[1].autoPercentSpin.value() * 0.01
|
||||||
@ -266,6 +259,20 @@ class ViewBoxMenu(QtGui.QMenu):
|
|||||||
c.setCurrentIndex(0)
|
c.setCurrentIndex(0)
|
||||||
c.currentIndexChanged.emit(c.currentIndex())
|
c.currentIndexChanged.emit(c.currentIndex())
|
||||||
|
|
||||||
|
def _validateRangeText(self, axis):
|
||||||
|
"""Validate range text inputs. Return current value(s) if invalid."""
|
||||||
|
inputs = (self.ctrl[axis].minText.text(),
|
||||||
|
self.ctrl[axis].maxText.text())
|
||||||
|
vals = self.view().viewRange()[axis]
|
||||||
|
for i, text in enumerate(inputs):
|
||||||
|
try:
|
||||||
|
vals[i] = float(text)
|
||||||
|
except ValueError:
|
||||||
|
# could not convert string to float
|
||||||
|
pass
|
||||||
|
return vals
|
||||||
|
|
||||||
|
|
||||||
from .ViewBox import ViewBox
|
from .ViewBox import ViewBox
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user