input merging mechanism
This commit is contained in:
parent
bec61465c9
commit
4316832b95
@ -1,6 +1,5 @@
|
|||||||
from owrx.form import Input
|
from owrx.form import Input
|
||||||
from owrx.controllers.settings import Section
|
from owrx.controllers.settings import Section
|
||||||
from abc import ABC, abstractmethod
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
@ -8,7 +7,7 @@ class SdrDeviceDescriptionMissing(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SdrDeviceDescription(ABC):
|
class SdrDeviceDescription(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getByType(sdr_type: str) -> "SdrDeviceDescription":
|
def getByType(sdr_type: str) -> "SdrDeviceDescription":
|
||||||
try:
|
try:
|
||||||
@ -19,9 +18,13 @@ class SdrDeviceDescription(ABC):
|
|||||||
except (ModuleNotFoundError, AttributeError):
|
except (ModuleNotFoundError, AttributeError):
|
||||||
raise SdrDeviceDescriptionMissing("Device description for type {} not available".format(sdr_type))
|
raise SdrDeviceDescriptionMissing("Device description for type {} not available".format(sdr_type))
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def getInputs(self) -> List[Input]:
|
def getInputs(self) -> List[Input]:
|
||||||
pass
|
return []
|
||||||
|
|
||||||
|
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):
|
def getSection(self):
|
||||||
return Section("Device settings", *self.getInputs())
|
return Section("Device settings", *self.getInputs())
|
||||||
|
@ -17,9 +17,9 @@ class RtlSdrSource(ConnectorSource):
|
|||||||
|
|
||||||
class RtlSdrDeviceDescription(SdrDeviceDescription):
|
class RtlSdrDeviceDescription(SdrDeviceDescription):
|
||||||
def getInputs(self) -> List[Input]:
|
def getInputs(self) -> List[Input]:
|
||||||
return [
|
return self.mergeInputs(
|
||||||
TextInput(
|
super().getInputs(),
|
||||||
"test",
|
[
|
||||||
"This is a drill"
|
TextInput("test", "This is a drill"),
|
||||||
),
|
],
|
||||||
]
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user