1
0
Fork 0

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
1 changed files with 5 additions and 5 deletions

View File

@ -5,13 +5,14 @@ from pyqtgraph.parametertree import Parameter, ParameterTree, ParameterItem, reg
import pyqtgraph as pg import pyqtgraph as pg
pg.setConfigOptions(antialias=True) pg.setConfigOptions(antialias=True)
from pyqtgraph import mkPen 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.live_axis_range import LiveAxisRange
from pglive.sources.data_connector import DataConnector from pglive.sources.data_connector import DataConnector
from pglive.kwargs import Axis, LeadingLine from pglive.kwargs import Axis, LeadingLine
from pglive.sources.live_plot import LiveLinePlot from pglive.sources.live_plot import LiveLinePlot
from pglive.sources.live_plot_widget import LivePlotWidget from pglive.sources.live_plot_widget import LivePlotWidget
from pglive.sources.live_axis import LiveAxis from pglive.sources.live_axis import LiveAxis
import re
import sys import sys
import os import os
import argparse import argparse
@ -33,6 +34,7 @@ from pid_autotune import PIDAutotune, PIDAutotuneState
import importlib.resources import importlib.resources
COMMON_ERROR_MSG = "Connection Timeout. Disconnecting." 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(): def get_argparser():
parser = argparse.ArgumentParser(description="ARTIQ master") 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("target", None) is not None:
if inner_param.opts.get("action", None) is not None: if inner_param.opts.get("action", None) is not None:
if inner_param.opts.get("unit", None) is not None: if inner_param.opts.get("unit", None) is not None:
# siParse is buggy on ° character _, _, suffix = siParse(str(data)+inner_param.opts["unit"], regex=FLOAT_REGEX)
if not inner_param.opts["unit"] == "°C": data = siEval(str(data)+inner_param.opts["unit"], regex=FLOAT_REGEX, suffix=suffix)
_, _, suffix = siParse(str(data)+inner_param.opts["unit"])
data = siEval(str(data)+inner_param.opts["unit"], suffix=suffix)
cmd = getattr(getattr(self.kirdy, inner_param.opts["target"]), inner_param.opts["action"]) cmd = getattr(getattr(self.kirdy, inner_param.opts["target"]), inner_param.opts["action"])
param.child(*param.childPath(inner_param)).setOpts(lock=True) param.child(*param.childPath(inner_param)).setOpts(lock=True)
await cmd(data) await cmd(data)