gui: Use a custom regex to handle the suffix with temperature characters

This commit is contained in:
linuswck 2024-07-31 11:35:04 +08:00
parent 3f9a4bf140
commit 1dcac25574

View File

@ -5,13 +5,14 @@ from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem, reg
import pyqtgraph as pg
pg.setConfigOptions(antialias=True)
from pyqtgraph import mkPen
from pyqtgraph.functions import siEval, siParse, SI_PREFIX_EXPONENTS, FLOAT_REGEX
from pyqtgraph.functions import siEval, siParse, SI_PREFIX_EXPONENTS, SI_PREFIXES
from pglive.sources.live_axis_range import LiveAxisRange
from pglive.sources.data_connector import DataConnector
from pglive.kwargs import Axis, LeadingLine
from pglive.sources.live_plot import LiveLinePlot
from pglive.sources.live_plot_widget import LivePlotWidget
from pglive.sources.live_axis import LiveAxis
import re
import sys
import os
import argparse
@ -33,6 +34,7 @@ from pid_autotune import PIDAutotune, PIDAutotuneState
import importlib.resources
COMMON_ERROR_MSG = "Connection Timeout. Disconnecting."
FLOAT_REGEX = re.compile(r'(?P<number>[+-]?((((\d+(\.\d*)?)|(\d*\.\d+))([eE][+-]?\d+)?)|((?i:nan)|(inf))))\s*((?P<siPrefix>[u' + SI_PREFIXES + r']?)(?P<suffix>[\w°℃].*))?$')
def get_argparser():
parser = argparse.ArgumentParser(description="ARTIQ master")
@ -958,10 +960,8 @@ class MainWindow(QtWidgets.QMainWindow):
if inner_param.opts.get("target", None) is not None:
if inner_param.opts.get("action", None) is not None:
if inner_param.opts.get("unit", None) is not None:
# siParse is buggy on ° character
if not inner_param.opts["unit"] == "°C":
_, _, suffix = siParse(str(data)+inner_param.opts["unit"])
data = siEval(str(data)+inner_param.opts["unit"], suffix=suffix)
_, _, suffix = siParse(str(data)+inner_param.opts["unit"], regex=FLOAT_REGEX)
data = siEval(str(data)+inner_param.opts["unit"], regex=FLOAT_REGEX, suffix=suffix)
cmd = getattr(getattr(self.kirdy, inner_param.opts["target"]), inner_param.opts["action"])
param.child(*param.childPath(inner_param)).setOpts(lock=True)
await cmd(data)