From 058463a9b3876497823af576db7f6b4ff033a004 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 20 Feb 2021 00:36:18 +0100 Subject: [PATCH] fix display and parsing issues --- owrx/form/device.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/owrx/form/device.py b/owrx/form/device.py index d9f7653..d9e0b25 100644 --- a/owrx/form/device.py +++ b/owrx/form/device.py @@ -8,23 +8,29 @@ class GainInput(Input): self.gain_stages = gain_stages def render_input(self, value): + try: + display_value = float(value) + except (ValueError, TypeError): + display_value = "0.0" + return """
{stageoption}
""".format( id=self.id, classes=self.input_classes(), - value="0.0" if value is None else value, + value=display_value, label=self.label, options=self.render_options(value), - stageoption=self.render_stage_option(value), + stageoption="" if self.gain_stages is None else self.render_stage_option(value), ) def render_options(self, value): @@ -41,9 +47,7 @@ class GainInput(Input): """ """.format( - value=v[0], - text=v[1], - selected="selected" if mode == v[0] else "" + value=v[0], text=v[1], selected="selected" if mode == v[0] else "" ) for v in options ) @@ -55,7 +59,7 @@ class GainInput(Input): try: float(value) return "manual" - except ValueError: + except (ValueError, TypeError): pass return "stages" @@ -75,7 +79,8 @@ class GainInput(Input): """
{stage}
- +
""".format( id=self.id, @@ -93,7 +98,7 @@ class GainInput(Input): if input_id in data: return data[input_id][0] else: - return 0.0 + return None select_id = "{id}-select".format(id=self.id) if select_id in data: @@ -102,12 +107,14 @@ class GainInput(Input): value = 0.0 if input_id in data: try: - value = float(float(data[input_id][0])) + value = float(data[input_id][0]) except ValueError: pass return {self.id: value} - if data[select_id][0] == "stages": + if self.gain_stages is not None and data[select_id][0] == "stages": settings_dict = [{s: getStageValue(s)} for s in self.gain_stages] + # filter out empty ones + settings_dict = [s for s in settings_dict if next(iter(s.values()))] return {self.id: SoapySettings.encode(settings_dict)} return {self.id: None}