Compare commits

..

14 Commits

Author SHA1 Message Date
38099d6d7b ctrl_panel: Fix editing fields with unit "°C"
A faulty regular expression within PyQtGraph causes any Parameter with
a suffix that doesn't begin with an alphanumeric character (as matched
with \w) to act abnormally. For instance, entering "100 °C" into the
input boxes gets interpreted as 10 °C.

Use a custom regular expression for Parameters with this unit, which
simply matches for any character in the suffix group.
2024-07-31 16:24:29 +08:00
9a00c2b8f2 ctrl_panel: More appropriate steps and fixes 2024-07-31 16:18:09 +08:00
99d095ebb9 ctrl_panel: Put plotted values into readings group
For more intuitiveness to first-time users
2024-07-31 16:18:09 +08:00
54db579825 ctrl_panel: Fix max_v to only have unit "V"
As most users do not need to limit TEC voltage with accuracy of less
than 1mV.
2024-07-31 16:18:09 +08:00
3144ea2c9d ctrl_panel: Keep i_set visible when PID engaged
Since i_set is also plotted, we would want to see its precise value too.
2024-07-31 16:18:09 +08:00
8b68ff7652 ctrl_panel: Remove MutexParameter
Use the standard ListParamenter instead, and hook up UI changes and
sent commands elsewhere.
2024-07-31 16:18:09 +08:00
fb977982f8 ctrl_panel: Limits fixes
* PID Autotune test current should be positive

* Maximum absolute voltage should be 4 V not 5 V
2024-07-31 16:18:09 +08:00
e54e161e4e ctrl_panel: Code cleanup
* Remove unnecessary duplication of `THERMOSTAT_PARAMETERS`

* i -> ch

* Separate ParameterTree and Parameter initiation

* Remove extra "channel" option to root parameters, as the "value"
option is already the channel number
2024-07-31 16:18:09 +08:00
39bc3179cd ctrl_panel: PID Auto Tune -> PID Autotune 2024-07-31 16:18:09 +08:00
ada95ec243 ctrl_panel: Stop crushing spinboxes
It might not be the case on some themes, but on the default Qt theme the
spinbox are a bit too short for the containing numbers. See
https://github.com/pyqtgraph/pyqtgraph/issues/701.
2024-07-31 16:18:09 +08:00
7b899eca2a ctrl_panel: Pin down units for editable fields
User input always has the same order of magnitude, so allowing multiple
siPrefixes would be unwanted complexity. Don't allow them to be changed.

The Parameter option "noUnitEditing" is added to do so by the following
measures:

1. Don't validate for changed siPrefix and suffix, which avoids their
removal.

2. Avoid getting the cursor embedded within the unit.
2024-07-31 16:17:03 +08:00
c4ced31d18 ctrl_panel: Remove need for "mA" hack
Remove all instances of mA scaling scattered all around the code and
specify it in the parameter tree with a single source of truth.

Done by adding the option "pinSiPrefix" for all Parameters of type `int`
or `float`, and using it for current Parameters with unit "mA".
2024-07-31 16:12:55 +08:00
0d9e8a3bf2 ctrl_panel: Appropriate units for measured current
Allow the readonly display of current to vary its SI prefix in the unit,
since as a display entry it won't have the unit adjustment problem.
2024-07-31 14:45:12 +08:00
05c1a8547d ctrl_panel: Improve postfilter description 2024-07-31 14:44:51 +08:00
3 changed files with 34 additions and 22 deletions

View File

@ -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):

View File

@ -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",

View File

@ -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
)