forked from M-Labs/thermostat
Compare commits
14 Commits
f513875745
...
38099d6d7b
Author | SHA1 | Date | |
---|---|---|---|
38099d6d7b | |||
9a00c2b8f2 | |||
99d095ebb9 | |||
54db579825 | |||
3144ea2c9d | |||
8b68ff7652 | |||
fb977982f8 | |||
e54e161e4e | |||
39bc3179cd | |||
ada95ec243 | |||
7b899eca2a | |||
c4ced31d18 | |||
0d9e8a3bf2 | |||
05c1a8547d |
@ -4,7 +4,7 @@ from pyqtgraph.parametertree import (
|
||||
Parameter,
|
||||
registerParameterType,
|
||||
)
|
||||
import pytec.gui.view.pin_siPrefix
|
||||
import pytec.gui.view.unitful
|
||||
|
||||
|
||||
def set_tree_label_tips(tree):
|
||||
|
@ -262,8 +262,8 @@
|
||||
"limits": {
|
||||
"Off": null,
|
||||
"47 dB @ 10.41 Hz": 27.0,
|
||||
"62 dB @ 9.1 Hz": 21.25,
|
||||
"86 dB @ 10 Hz": 20.0,
|
||||
"62 dB @ 10 Hz": 21.25,
|
||||
"86 dB @ 9.1 Hz": 20.0,
|
||||
"92 dB @ 8.4 Hz": 16.67
|
||||
},
|
||||
"tip": "Trade off effective sampling rate and rejection of (50±1) Hz and (60±1) Hz",
|
||||
|
@ -2,31 +2,38 @@ from PyQt6.QtCore import QSignalBlocker
|
||||
from PyQt6.QtGui import QValidator
|
||||
|
||||
from pyqtgraph import SpinBox
|
||||
from pyqtgraph.parametertree import registerParameterItemType
|
||||
import pyqtgraph.parametertree.parameterTypes as pTypes
|
||||
import pyqtgraph.functions as fn
|
||||
from pyqtgraph.parametertree.parameterTypes import (
|
||||
SimpleParameter,
|
||||
NumericParameterItem,
|
||||
registerParameterItemType,
|
||||
)
|
||||
|
||||
|
||||
class PinSIPrefixSpinBox(SpinBox):
|
||||
class UnitfulSpinBox(SpinBox):
|
||||
"""
|
||||
Extension of PyQtGraph's SpinBox widget.
|
||||
Adds:
|
||||
|
||||
* "pinSiPrefix" option, where the siPrefix could be fixed to a particular scale
|
||||
* "noUnitEditing" option, where the unit portion of the SpinBox text, including
|
||||
the siPrefix, is fixed and uneditable.
|
||||
|
||||
* The "pinSiPrefix" option, where the siPrefix could be fixed to a
|
||||
particular scale instead of as determined by its value.
|
||||
* The "noUnitEditing" option, where the unit portion of the
|
||||
SpinBox text, including the siPrefix, is fixed and uneditable.
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None, value=0.0, **kwargs):
|
||||
super().__init__(parent, value, **kwargs)
|
||||
|
||||
self._current_si_prefix = ""
|
||||
self.lineEdit().cursorPositionChanged.connect(self.editor_cursor_position_changed)
|
||||
self.lineEdit().cursorPositionChanged.connect(
|
||||
self.editor_cursor_position_changed
|
||||
)
|
||||
|
||||
def validate(self, strn, pos):
|
||||
ret, strn, pos = super().validate(strn, pos)
|
||||
|
||||
if "noUnitEditing" in self.opts and self.opts["noUnitEditing"] is True:
|
||||
suffix = self.opts.get("suffix", "")
|
||||
if self.opts.get("noUnitEditing") is True:
|
||||
suffix = self.opts["suffix"]
|
||||
|
||||
# When the unit is edited / removed
|
||||
if not (
|
||||
@ -46,12 +53,12 @@ class PinSIPrefixSpinBox(SpinBox):
|
||||
Their suffix is different than our suffix; there's no obvious
|
||||
way to set that one here.
|
||||
"""
|
||||
if "noUnitEditing" in self.opts and self.opts["noUnitEditing"] is True:
|
||||
if self.opts.get("noUnitEditing") is True:
|
||||
edit = self.lineEdit()
|
||||
if edit.hasSelectedText():
|
||||
return # Allow for selecting units, for copy-and-paste
|
||||
|
||||
unit_len = len(self._current_si_prefix) + len(self.opts.get("suffix", ""))
|
||||
unit_len = len(self._current_si_prefix) + len(self.opts["suffix"])
|
||||
text_len = len(edit.text())
|
||||
|
||||
pos = -1
|
||||
@ -76,8 +83,8 @@ class PinSIPrefixSpinBox(SpinBox):
|
||||
|
||||
def formatText(self, prev=None):
|
||||
"""
|
||||
Implement 'pinSiPrefix' mechanism for pyqtgraph.SpinBox, where SI prefixes could
|
||||
be pinned down.
|
||||
Implement 'pinSiPrefix' mechanism for pyqtgraph.SpinBox, where
|
||||
SI prefixes could be pinned down.
|
||||
|
||||
Code modified from the PyQtGraph source
|
||||
"""
|
||||
@ -114,7 +121,12 @@ class PinSIPrefixSpinBox(SpinBox):
|
||||
return self.opts['format'].format(**parts)
|
||||
|
||||
|
||||
class PinSIPrefixNumericParameterItem(pTypes.NumericParameterItem):
|
||||
class UnitfulNumericParameterItem(NumericParameterItem):
|
||||
"""
|
||||
Subclasses PyQtGraph's `NumericParameterItem` and uses
|
||||
UnitfulSpinBox for editing.
|
||||
"""
|
||||
|
||||
def makeWidget(self):
|
||||
opts = self.param.opts
|
||||
t = opts['type']
|
||||
@ -122,7 +134,7 @@ class PinSIPrefixNumericParameterItem(pTypes.NumericParameterItem):
|
||||
'value': 0, 'min': None, 'max': None,
|
||||
'step': 1.0, 'dec': False,
|
||||
'siPrefix': False, 'suffix': '', 'decimals': 3,
|
||||
'pinSiPrefix': None, 'noUnitEditing': False
|
||||
'pinSiPrefix': None, 'noUnitEditing': False,
|
||||
}
|
||||
if t == 'int':
|
||||
defs['int'] = True
|
||||
@ -132,7 +144,7 @@ class PinSIPrefixNumericParameterItem(pTypes.NumericParameterItem):
|
||||
defs[k] = opts[k]
|
||||
if 'limits' in opts:
|
||||
defs['min'], defs['max'] = opts['limits']
|
||||
w = PinSIPrefixSpinBox()
|
||||
w = UnitfulSpinBox()
|
||||
w.setOpts(**defs)
|
||||
w.sigChanged = w.sigValueChanged
|
||||
w.sigChanging = w.sigValueChanging
|
||||
@ -140,8 +152,8 @@ class PinSIPrefixNumericParameterItem(pTypes.NumericParameterItem):
|
||||
|
||||
|
||||
registerParameterItemType(
|
||||
"float", PinSIPrefixNumericParameterItem, pTypes.SimpleParameter, override=True
|
||||
"float", UnitfulNumericParameterItem, SimpleParameter, override=True
|
||||
)
|
||||
registerParameterItemType(
|
||||
"int", PinSIPrefixNumericParameterItem, pTypes.SimpleParameter, override=True
|
||||
"int", UnitfulNumericParameterItem, SimpleParameter, override=True
|
||||
)
|
Loading…
Reference in New Issue
Block a user