From 691d88f841a42da927b96806ebe84fab3dcfbacd Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Tue, 16 Feb 2021 18:35:18 +0100 Subject: [PATCH] waterfall config fine-adjustments * hide the waterfall colors input when pre-defined color scheme is selected * skip unparseable lines on custom color input * fallback to black and white if custom color config is unusable * always use the waterfall classes when sending changes to the client --- htdocs/lib/settings/WaterfallDropdown.js | 11 +++++++++++ htdocs/settings.js | 1 + owrx/connection.py | 4 ++-- owrx/controllers/assets.py | 1 + owrx/form/converter.py | 14 +++++++++----- owrx/waterfall.py | 7 ++++++- 6 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 htdocs/lib/settings/WaterfallDropdown.js diff --git a/htdocs/lib/settings/WaterfallDropdown.js b/htdocs/lib/settings/WaterfallDropdown.js new file mode 100644 index 0000000..ea05992 --- /dev/null +++ b/htdocs/lib/settings/WaterfallDropdown.js @@ -0,0 +1,11 @@ +$.fn.waterfallDropdown = function(){ + this.each(function(){ + var $select = $(this); + var setVisibility = function() { + var show = $select.val() === 'CUSTOM'; + $('#waterfall_colors').parents('.form-group')[show ? 'show' : 'hide'](); + } + $select.on('change', setVisibility); + setVisibility(); + }) +} \ No newline at end of file diff --git a/htdocs/settings.js b/htdocs/settings.js index 072ae79..1a76dbe 100644 --- a/htdocs/settings.js +++ b/htdocs/settings.js @@ -4,4 +4,5 @@ $(function(){ $('.imageupload').imageUpload(); $('.bookmarks').bookmarktable(); $('.wsjt-decoding-depths').wsjtDecodingDepthsInput(); + $('#waterfall_scheme').waterfallDropdown(); }); \ No newline at end of file diff --git a/owrx/connection.py b/owrx/connection.py index 7a74073..bf0e38d 100644 --- a/owrx/connection.py +++ b/owrx/connection.py @@ -207,8 +207,8 @@ class OpenWebRxReceiverClient(OpenWebRxClient, SdrSourceEventClient): def writeConfig(changes): # TODO it would be nicer to have all options available and switchable in the client # this restores the existing functionality for now, but there is lots of potential - if "waterfall_scheme" in changes: - scheme = WaterfallOptions(changes["waterfall_scheme"]).instantiate() + if "waterfall_scheme" in changes or "waterfall_colors" in changes: + scheme = WaterfallOptions(globalConfig["waterfall_scheme"]).instantiate() changes["waterfall_colors"] = scheme.getColors() self.write_config(changes) diff --git a/owrx/controllers/assets.py b/owrx/controllers/assets.py index 61483b7..6565bb5 100644 --- a/owrx/controllers/assets.py +++ b/owrx/controllers/assets.py @@ -151,6 +151,7 @@ class CompiledAssetsController(GzipMixin, ModificationAwareController): "lib/settings/ImageUpload.js", "lib/settings/BookmarkTable.js", "lib/settings/WsjtDecodingDepthsInput.js", + "lib/settings/WaterfallDropdown.js", "settings.js", ], } diff --git a/owrx/form/converter.py b/owrx/form/converter.py index 6c8dbff..580b368 100644 --- a/owrx/form/converter.py +++ b/owrx/form/converter.py @@ -76,10 +76,14 @@ class WaterfallColorsConverter(Converter): def convert_from_form(self, value): def parseString(s): - if s.startswith("#"): - return int(s[1:], 16) - # int() with base 0 can accept "0x" prefixed hex strings, or int numbers - return int(s, 0) + try: + if s.startswith("#"): + return int(s[1:], 16) + # int() with base 0 can accept "0x" prefixed hex strings, or int numbers + return int(s, 0) + except ValueError: + return None # \r\n or \n? this should work with both. - return [parseString(v.strip("\r ")) for v in value.split("\n")] + values = [parseString(v.strip("\r ")) for v in value.split("\n")] + return [v for v in values if v is not None] diff --git a/owrx/waterfall.py b/owrx/waterfall.py index 68d5fdf..ad1a31e 100644 --- a/owrx/waterfall.py +++ b/owrx/waterfall.py @@ -287,7 +287,12 @@ class Ha7ilmWaterfall(Waterfall): class CustomWaterfall(Waterfall): def __init__(self): config = Config.get() - super().__init__(config["waterfall_colors"]) + if "waterfall_colors" in config and config["waterfall_colors"]: + colors = config["waterfall_colors"] + else: + # fallback: black and white + colors = [0x000000, 0xffffff] + super().__init__(colors) class WaterfallOptions(DropdownEnum):