Skip to content

Commit

Permalink
[PEP8] cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TwolDE2 committed Aug 6, 2024
1 parent 8eaf1e0 commit 95eb6c1
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
1 change: 0 additions & 1 deletion lib/python/Components/Timeshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def __infoBarTimeshiftOnClose(self):
if self.ptsTimerEntryStateChange in self.session.nav.RecordTimer.on_state_change:
self.session.nav.RecordTimer.on_state_change.remove(self.ptsTimerEntryStateChange)


def __seekableStatusChanged(self):
# print("[Timeshift]__seekableStatusChanged")
self["TimeshiftActivateActions"].setEnabled(not self.isSeekable() and self.timeshiftEnabled() and int(config.timeshift.startdelay.value))
Expand Down
1 change: 1 addition & 0 deletions lib/python/Components/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ def isChanged(self):
strv = self.tostring(self.value)
return strv.lower() != sv.lower()


class ConfigEnableDisable(ConfigBoolean):
def __init__(self, default=False, graphic=True):
ConfigBoolean.__init__(self, default=default, descriptions={False: _("Disable"), True: _("Enable")}, graphic=graphic)
Expand Down
26 changes: 15 additions & 11 deletions lib/python/Plugins/SystemPlugins/TerrestrialBouquet/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
config.plugins.terrestrialbouquet.makeradiobouquet = ConfigYesNo()
config.plugins.terrestrialbouquet.skipduplicates = ConfigYesNo(True)


class TerrestrialBouquet:
def __init__(self):
self.config = config.plugins.terrestrialbouquet
Expand All @@ -35,14 +36,14 @@ def getTerrestrials(self, mode):
if (servicelist := ServiceReference.list(ServiceReference(query))) is not None:
while (service := servicelist.getNext()) and service.valid():
if service.getUnsignedData(4) >> 16 == 0xeeee: # filter (only terrestrial)
stype, sid, tsid, onid, ns = [int(x, 16) for x in service.toString().split(":",7)[2:7]]
stype, sid, tsid, onid, ns = [int(x, 16) for x in service.toString().split(":", 7)[2:7]]
name = ServiceReference.getServiceName(service)
terrestrials["%04x:%04x:%04x" % (onid, tsid, sid)] = {"name": name, "namespace": ns, "onid": onid, "tsid": tsid, "sid": sid, "type": stype}
return terrestrials

def getAllowedTypes(self, mode):
return self.VIDEO_ALLOWED_TYPES if mode == MODE_TV else self.AUDIO_ALLOWED_TYPES # tv (live and NVOD) and radio allowed service types

def readLcnDb(self):
try: # may not exist
f = open(self.lcndb)
Expand All @@ -55,22 +56,22 @@ def readLcnDb(self):
lcn, signal = tuple([int(x) for x in line[24:].split(":", 1)])
key = line[9:23]
LCNs[key] = {"lcn": lcn, "signal": signal}
return {k:v for k,v in sorted(list(LCNs.items()), key=lambda x: (x[1]["lcn"], abs(x[1]["signal"] - 65535)))}
return {k: v for k, v in sorted(list(LCNs.items()), key=lambda x: (x[1]["lcn"], abs(x[1]["signal"] - 65535)))}

def rebuild(self):
if not self.config.enabled.value:
return _("Terrestrial Bouquet plugin is not enabled.")
msg = _("Try running a manual scan of terrestrial frequencies. If this fails maybe there is no lcn data available in your area.")
msg = _("Try running a manual scan of terrestrial frequencies. If this fails maybe there is no lcn data available in your area.")
self.services.clear()
if not (LCNs := self.readLcnDb()):
return self.lcndb + _("empty or missing.") + " " + msg
return self.lcndb + _("empty or missing.") + " " + msg
for mode in (MODE_TV, MODE_RADIO):
terrestrials = self.getTerrestrials(mode)
for k in terrestrials:
if k in LCNs:
terrestrials[k] |= LCNs[k]
self.services |= terrestrials
self.services = {k:v for k,v in sorted(list(self.services.items()),key=lambda x: ("lcn" in x[1] and x[1]["lcn"] or 65535, "signal" in x[1] and abs(x[1]["signal"]-65536) or 65535))}
self.services = {k: v for k, v in sorted(list(self.services.items()), key=lambda x: ("lcn" in x[1] and x[1]["lcn"] or 65535, "signal" in x[1] and abs(x[1]["signal"] - 65536) or 65535))}
LCNsUsed = [] # duplicates (we are already ordered by highest signal strength)
for k in list(self.services.keys()): # use list to avoid RuntimeError: dictionary changed size during iteration
if not "lcn" in self.services[k] or self.services[k]["lcn"] in LCNsUsed:
Expand All @@ -81,7 +82,7 @@ def rebuild(self):
else:
LCNsUsed.append(self.services[k]["lcn"])
if not self.services:
return _("No corresponding terrestrial services found.") + " " + msg
return _("No corresponding terrestrial services found.") + " " + msg
self.createBouquet()

def readBouquetIndex(self, mode):
Expand All @@ -106,7 +107,7 @@ def writeBouquetIndex(self, bouquetIndexContent, mode):

def writeBouquet(self, mode):
allowed_service_types = not self.config.makeradiobouquet.value and self.VIDEO_ALLOWED_TYPES + self.AUDIO_ALLOWED_TYPES or self.getAllowedTypes(mode)
lcnindex = {v["lcn"]:k for k,v in self.services.items() if not v.get("duplicate") and v.get("lcn") and v.get("type") in allowed_service_types}
lcnindex = {v["lcn"]: k for k, v in self.services.items() if not v.get("duplicate") and v.get("lcn") and v.get("type") in allowed_service_types}
highestLCN = max(list(lcnindex.keys()))
duplicates = {} if self.config.skipduplicates.value else {i + 1 + highestLCN: v for i, v in enumerate(sorted([v for v in self.services.values() if v.get("duplicate") and v.get("type") in allowed_service_types], key=lambda x: x["name"].lower()))}
sections = providers[self.config.providers.value].get("sections", {})
Expand All @@ -130,7 +131,7 @@ def writeBouquet(self, mode):

def bouquetServiceLine(self, service):
return "#SERVICE 1:0:%x:%x:%x:%x:%x:0:0:0:\n" % (service["type"], service["sid"], service["tsid"], service["onid"], service["namespace"])

def bouquetMarker(self, text):
return "#SERVICE 1:64:0:0:0:0:0:0:0:0:\n#DESCRIPTION %s\n" % text

Expand All @@ -140,7 +141,7 @@ def createBouquet(self):
if mode == MODE_RADIO and (not radio_services or not self.config.makeradiobouquet.value):
break
bouquetIndexContent = self.readBouquetIndex(mode)
if '"' + self.bouquetFilename[:-2] + ("tv" if mode == MODE_TV else "radio") + '"' not in bouquetIndexContent: # only edit the index if bouquet file is not present
if '"' + self.bouquetFilename[:-2] + ("tv" if mode == MODE_TV else "radio") + '"' not in bouquetIndexContent: # only edit the index if bouquet file is not present
self.writeBouquetIndex(bouquetIndexContent, mode)
self.writeBouquet(mode)
eDVBDB.getInstance().reloadBouquets()
Expand Down Expand Up @@ -169,7 +170,7 @@ def changedEntry(self):

def updatebluetext(self):
self["key_blue"].text = _("Rebuild bouquet") if self.config.enabled.value else ""

def startrebuild(self):
if self.config.enabled.value:
self.saveAll()
Expand All @@ -186,12 +187,15 @@ def PluginCallback(close, answer=None):
if close and answer:
close(True)


def PluginMain(session, close=None, **kwargs):
session.openWithCallback(boundFunction(PluginCallback, close), PluginSetup)


def PluginStart(menuid, **kwargs):
return menuid == "scan" and [(_("Terrestrial Bouquet"), PluginMain, "PluginMain", 1)] or []


def Plugins(**kwargs):
from Components.NimManager import nimmanager
return [PluginDescriptor(name=_("Terrestrial Bouquet"), description=_("Create an ordered bouquet of terrestrial services based on LCN data from your local transmitter."), where=PluginDescriptor.WHERE_MENU, needsRestart=False, fnc=PluginStart),] if nimmanager.hasNimType("DVB-T") else []
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
providers = {
"other":{},
"other": {},
"uk": {
"name": _("UK"),
"bouquetname": "FreeView",
Expand All @@ -10,4 +10,4 @@
230: _("News"),
260: _("BBC Interactive"),
670: _("Adult"),
700: _("Radio"),}}}
700: _("Radio"), }}}
2 changes: 1 addition & 1 deletion lib/python/Screens/AudioSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def keyNumberGlobal(self, number):
def keyOk(self):
if self.focus == FOCUS_STREAMS and self["streams"].list:
cur = self["streams"].getCurrent()
service = self.session.nav.getCurrentService()
service = self.session.nav.getCurrentService() # noqa: F841
ref = self.session.nav.getCurrentServiceRef()
ref = ref and eServiceReference(ref)
if self.settings.menupage.value == PAGE_AUDIO and cur[0] is not None:
Expand Down
2 changes: 1 addition & 1 deletion lib/python/Screens/InputDeviceSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from Components.Sources.List import List
from Components.config import config, ConfigYesNo, getConfigListEntry, ConfigSelection
from Components.ConfigList import ConfigListScreen
from Components.ActionMap import ActionMap, HelpableActionMap
from Components.ActionMap import HelpableActionMap
from Components.SystemInfo import SystemInfo
from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
from Tools.LoadPixmap import LoadPixmap
Expand Down

0 comments on commit 95eb6c1

Please sign in to comment.