start building device forms

This commit is contained in:
Jakob Ketterl
2021-02-19 15:29:17 +01:00
parent 4316832b95
commit 3aa238727e
7 changed files with 65 additions and 39 deletions

View File

@ -10,6 +10,9 @@ from abc import ABC, abstractmethod
from owrx.command import CommandMapper
from owrx.socket import getAvailablePort
from owrx.property import PropertyStack, PropertyLayer
from owrx.form import Input, TextInput, NumberInput
from owrx.controllers.settings import Section
from typing import List
import logging
@ -352,3 +355,33 @@ class SdrSource(ABC):
self.busyState = state
for c in self.clients:
c.onBusyStateChange(state)
class SdrDeviceDescriptionMissing(Exception):
pass
class SdrDeviceDescription(object):
@staticmethod
def getByType(sdr_type: str) -> "SdrDeviceDescription":
try:
className = "".join(x for x in sdr_type.title() if x.isalnum()) + "DeviceDescription"
module = __import__("owrx.source.{0}".format(sdr_type), fromlist=[className])
cls = getattr(module, className)
return cls()
except (ModuleNotFoundError, AttributeError):
raise SdrDeviceDescriptionMissing("Device description for type {} not available".format(sdr_type))
def getInputs(self) -> List[Input]:
return [
TextInput("name", "Device name"),
NumberInput("ppm", "Frequency correction", append="ppm"),
]
def mergeInputs(self, *args):
# build a dictionary indexed by the input id to make sure every id only exists once
inputs = {input.id: input for input_list in args for input in input_list}
return inputs.values()
def getSection(self):
return Section("Device settings", *self.getInputs())