mirror of
https://github.com/jketterl/openwebrx.git
synced 2026-02-24 00:26:07 +01:00
improve profile handling
This commit is contained in:
parent
84bd6772a5
commit
9c4e21316b
11
owrx/sdr.py
11
owrx/sdr.py
|
|
@ -1,7 +1,7 @@
|
|||
from owrx.config import Config
|
||||
from owrx.source import SdrSourceEventClient, ProfileIsActiveFilter
|
||||
from owrx.source import SdrSourceEventClient, ProfileIsEnabledFilter
|
||||
from owrx.feature import FeatureDetector, UnknownFeatureException
|
||||
from owrx.active.list import ActiveListTransformation, ActiveListFilter, ActiveListListener, ActiveList, ActiveListChange
|
||||
from owrx.active.list import ActiveListTransformation, ActiveListFilter, ActiveListListener, ActiveList, ActiveListChange, ActiveListIndexAdded, ActiveListIndexDeleted
|
||||
|
||||
import logging
|
||||
|
||||
|
|
@ -45,7 +45,8 @@ class ProfileChangeListener(ActiveListListener):
|
|||
self.callback = callback
|
||||
|
||||
def onListChange(self, source: ActiveList, changes: list[ActiveListChange]):
|
||||
self.callback()
|
||||
if any(isinstance(c, ActiveListIndexAdded) or isinstance(c, ActiveListIndexDeleted) for c in changes):
|
||||
self.callback()
|
||||
|
||||
|
||||
class HasProfilesFilter(ActiveListFilter):
|
||||
|
|
@ -57,13 +58,13 @@ class HasProfilesFilter(ActiveListFilter):
|
|||
if "profiles" not in device:
|
||||
return False
|
||||
if id(device) not in self.profiles:
|
||||
self.profiles[id(device)] = device["profiles"].filter(ProfileIsActiveFilter())
|
||||
self.profiles[id(device)] = device["profiles"].filter(ProfileIsEnabledFilter())
|
||||
return len(self.profiles[id(device)]) > 0
|
||||
|
||||
def monitor(self, device, callback: callable):
|
||||
self.monitors[id(device)] = monitor = ProfileChangeListener(callback)
|
||||
if id(device) not in self.profiles:
|
||||
self.profiles[id(device)] = device["profiles"].filter(ProfileIsActiveFilter())
|
||||
self.profiles[id(device)] = device["profiles"].filter(ProfileIsEnabledFilter())
|
||||
self.profiles[id(device)].addListener(monitor)
|
||||
|
||||
def unmonitor(self, device):
|
||||
|
|
|
|||
|
|
@ -94,12 +94,8 @@ class SdrProfileCarouselListener(ActiveListListener):
|
|||
|
||||
|
||||
class SdrProfileCarousel(PropertyCarousel):
|
||||
def __init__(self, props):
|
||||
def __init__(self, profiles):
|
||||
super().__init__()
|
||||
if "profiles" not in props:
|
||||
return
|
||||
|
||||
profiles = props["profiles"].filter(ProfileIsActiveFilter())
|
||||
|
||||
for profile in profiles:
|
||||
self.addProfile(profile)
|
||||
|
|
@ -126,7 +122,7 @@ class SdrProfileCarousel(PropertyCarousel):
|
|||
return super()._getDefaultLayer()
|
||||
|
||||
|
||||
class ProfileIsActiveFilter(ActiveListFilter):
|
||||
class ProfileIsEnabledFilter(ActiveListFilter):
|
||||
def __init__(self):
|
||||
self.subscriptions = {}
|
||||
|
||||
|
|
@ -154,9 +150,12 @@ class SdrSource(ABC):
|
|||
self.stderrPipe = None
|
||||
|
||||
self.props = PropertyStack()
|
||||
if "profiles" not in props:
|
||||
props["profiles"] = ActiveList()
|
||||
self.profiles = props["profiles"].filter(ProfileIsEnabledFilter())
|
||||
|
||||
# layer 0 reserved for profile properties
|
||||
self.profileCarousel = SdrProfileCarousel(props)
|
||||
self.profileCarousel = SdrProfileCarousel(self.profiles)
|
||||
# prevent profile names from overriding the device name
|
||||
self.props.addLayer(0, PropertyFilter(self.profileCarousel, ByLambda(lambda x: x != "name")))
|
||||
|
||||
|
|
@ -278,7 +277,7 @@ class SdrSource(ABC):
|
|||
return self.getProfile(self.props["profile_id"])
|
||||
|
||||
def getProfiles(self):
|
||||
return self.props["profiles"].filter(ProfileIsActiveFilter())
|
||||
return self.profiles
|
||||
|
||||
def getProfile(self, profile_id):
|
||||
try:
|
||||
|
|
|
|||
Loading…
Reference in a new issue