.*?
![]()
'
- matches = findall(pattern, content, DOTALL)
- if matches:
- chosen_link = matches[0]
- if not chosen_link.startswith("http"):
- chosen_link = base_url + chosen_link
- try:
- img_response = requests.get(chosen_link, headers=HEADERS, timeout=10)
- img = Image.open(BytesIO(img_response.content))
- img = img.convert("RGB") # Rimuove ICC
- img.save(devicepath, "PNG")
- if DEBUG:
- FAlog("Image dimensions: {}x{}".format(img.width, img.height))
- self.session.openWithCallback(returnToChoiceBox, PicViewx, devicepath, 0, False, None)
- except requests.RequestException as e:
- if DEBUG:
- FAlog("Error downloading image: %s" % str(e))
- returnToChoiceBox()
- else:
- if DEBUG:
- FAlog("Image not found on the page.")
- returnToChoiceBox()
- except Exception as e:
- if DEBUG:
- FAlog("Error processing page: %s" % str(e))
- returnToChoiceBox()
-
- if len(menu) > 0:
- self.session.openWithCallback(boxAction, ChoiceBox, title=text, list=menu)
-
- def SatBild(self):
- try:
- current_selection = self['Mlist'].l.getCurrentSelection()
- if not current_selection or not current_selection[0] or len(current_selection[0]) < 2:
- if DEBUG:
- FAlog("SatBild Error: Invalid selection in CurrentSelection", str(current_selection))
- return
- menu = current_selection[0][1]
- if DEBUG:
- FAlog("SatBild menu= %s" % menu, "CurrentSelection= %s" % current_selection)
- self.deactivateCacheDialog()
- if menu == "eumetsat":
- self.doContext()
- else:
- try:
- url = "%s%s?map=%s" % (BASEURL, pathname2url(self.ort), menu)
- if DEBUG:
- FAlog("VIDEO URL map = %s" % url)
- req = Request(url, headers=HEADERS)
- resp = urlopen(req, timeout=10)
- content = (resp.read().decode('utf-8') if PY3 else resp.read())
- start_pattern = r"var urltemplate"
- end_pattern = r"var timehdrs"
- section_pattern = compile(r"%s(.*?)%s" % (start_pattern, end_pattern), DOTALL)
- section_match = section_pattern.search(content)
-
- if section_match:
- section_content = section_match.group(1)
- fulltext = compile(r'(\/\/cache.*?\.(jpg|png))', DOTALL)
- urls = fulltext.findall(section_content)
- for url, ext in urls:
- full_url = 'https:' + url
- if DEBUG:
- FAlog("Valid URL:", full_url)
- self.fetch_url(full_url)
- self.session.open(View_Slideshow, 0, True)
- else:
- if DEBUG:
- FAlog("SatBild Warning: No image URLs found in page content.")
- self.session.open(MessageBox, _("No satellite images found."), MessageBox.TYPE_INFO)
- return
- except Exception as e:
- self.session.open(MessageBox, _("Failed to process satellite data: %s" % str(e)), MessageBox.TYPE_ERROR)
- except Exception as e:
- if DEBUG:
- FAlog("SatBild Critical Error", str(e))
- self.session.open(MessageBox, _("A critical error occurred: %s" % str(e)), MessageBox.TYPE_ERROR)
-
-
-# ------------------------------------------------------------------------------------------
-# ------------------------------ Weather Maps ----------------------------------------------
-# ------------------------------------------------------------------------------------------
-
-
-class SatPanelListb(MenuList):
-
- if HD:
- ItemSkin = 143
- else:
- ItemSkin = 123
-
- def __init__(self, list, font0=24, font1=16, itemHeight=ItemSkin, enableWrapAround=True):
- MenuList.__init__(self, [], False, eListboxPythonMultiContent)
- self.font0 = gFont("Regular", font0)
- self.font1 = gFont("Regular", font1)
- self.itemHeight = itemHeight
-
-# ---------------------- get skin attribs ----------------------------
- def applySkin(self, desktop, parent):
- def font(value):
- self.font0 = parseFont(value, ((1, 1), (1, 1)))
-
- def font1(value):
- self.font1 = parseFont(value, ((1, 1), (1, 1)))
-
- def itemHeight(value):
- self.itemHeight = int(value)
-
- for (attrib, value) in list(self.skinAttributes):
- try:
- locals().get(attrib)(value)
- self.skinAttributes.remove((attrib, value))
- except Exception:
- pass
-
- self.l.setFont(0, self.font0)
- self.l.setFont(1, self.font1)
- self.l.setItemHeight(self.itemHeight)
- return GUIComponent.applySkin(self, desktop, parent)
-
-
-class SatPanelb(Screen, HelpableScreen):
-
- def __init__(self, session, ort, title, mlist):
- self.session = session
- self.ort = ort
-
- if size_w == 1920:
- self.skin = """
-
-
-
-
-
-
-
-
-
-
- """
- elif size_w == 2560:
- self.skin = """
-
-
-
-
-
-
-
-
-
-
- """
- else:
- self.skin = """
-
-
-
-
-
-
-
-
-
-
- """
-
- Screen.__init__(self, session)
- self.setup_title = title
- self.Mlist = mlist
- if DEBUG:
- FAlog("Mlist= %s" % self.Mlist, "\nSatPanelListb([])= %s" % SatPanelListb([]))
- self["Mlist"] = SatPanelListb([])
- self["Mlist"].l.setList(self.Mlist)
- self["Mlist"].selectionEnabled(1)
- self["key_blue"] = StaticText(_("Settings"))
- HelpableScreen.__init__(self)
- self["actions"] = HelpableActionMap(
- self, "ForecaActions",
- {
- "cancel": (self.Exit, _("Exit - End")),
- "left": (self.left, _("Left - Previous page")),
- "right": (self.right, _("Right - Next page")),
- "up": (self.up, _("Up - Previous")),
- "down": (self.down, _("Down - Next")),
- "showEventInfo": (self.info, _("Info - Legend")),
- "info": (self.info, _("Info - Legend")),
- "blue": (self.PicSetupMenu, _("Blue - Settings")),
- "ok": (self.ok, _("OK - Show")),
- },
- -2,
- )
- self.setTitle(title)
-
- def info(self):
- message = str("%s" % (_(
- "Server URL: %s\n"
- ) % BASEURL))
- entries = [
- ("VERSION", "%s" % VERSION), # No translation needed
- (_("Ok"), _("Show map")),
- (_("Blue"), _("Settings")),
- (_("Txt/Red"), _("Open Keyboard")),
- (_("Up/Down"), _("Previous/Next")),
- (_("< >"), _("Previous/Next page")),
- (_("Info"), _("This information"))
- ]
- message += format_message(entries)
- self.session.open(MessageBox, message, MessageBox.TYPE_INFO)
-
- def up(self):
- self["Mlist"].up()
- self["Mlist"].selectionEnabled(1)
-
- def down(self):
- self["Mlist"].down()
- self["Mlist"].selectionEnabled(1)
-
- def left(self):
- self["Mlist"].pageUp()
-
- def right(self):
- self["Mlist"].pageDown()
-
- def Exit(self):
- self.close()
-
- def ok(self):
- menu = self['Mlist'].l.getCurrentSelection()[0][1]
- if DEBUG:
- FAlog("SatPanelb menu= %s" % menu, "CurrentSelection= %s" % self['Mlist'].l.getCurrentSelection())
- self.SatBild()
-
- def PicSetupMenu(self):
- self.session.openWithCallback(self.OKCallback, PicSetup)
-
- def OKCallback(self, callback=None):
- global fav1, fav2, start
- # self.ort = city
- # fav1 = str(config.plugins.foreca.fav1.getValue())
- # fav2 = str(config.plugins.foreca.fav2.getValue())
- # start = str(config.plugins.foreca.home.getValue())
- fav1 = config.plugins.foreca.fav1.getValue()[config.plugins.foreca.fav1.getValue().rfind("/") + 1:]
- fav2 = config.plugins.foreca.fav2.getValue()[config.plugins.foreca.fav2.getValue().rfind("/") + 1:]
- start = config.plugins.foreca.home.getValue()[config.plugins.foreca.home.getValue().rfind("/") + 1:]
- self.ort = config.plugins.foreca.home.getValue()
- self.Exit()
-
- def SatBild(self):
- try:
- current_selection = self['Mlist'].l.getCurrentSelection()
- if not current_selection or not current_selection[0] or len(current_selection[0]) < 2:
- if DEBUG:
- FAlog("SatBild Error: Invalid selection in CurrentSelection", str(current_selection))
- self.session.open(MessageBox, _("Invalid selection. Please select a valid region."), MessageBox.TYPE_ERROR)
- return
-
- region = current_selection[0][1]
- if DEBUG:
- FAlog("SatBild: Selected region = %s" % region)
- devicepath = CACHE_PATH + "meteogram.png"
- url = "http://img.wetterkontor.de/karten/" + region + "0.jpg"
- if DEBUG:
- FAlog("SatBild: Downloading image from URL = %s" % url)
-
- try:
- download_image(url, devicepath)
- remove_icc_profile(devicepath)
- self.session.open(PicViewx, devicepath, 0, False, None)
- except Exception as e:
- if DEBUG:
- FAlog("SatBild Error: Failed to download or save the image", str(e))
- self.session.open(MessageBox, _("Failed to load the satellite image: %s" % str(e)), MessageBox.TYPE_ERROR)
-
- except Exception as e:
- if DEBUG:
- FAlog("SatBild Critical Error", str(e))
- self.session.open(MessageBox, _("A critical error occurred: %s" % str(e)), MessageBox.TYPE_ERROR)
-
-
-# ------------------------------------------------------------------------------------------
-# -------------------------- Picture viewer for large pictures -----------------------------
-# ------------------------------------------------------------------------------------------
-
-
-class PicViewx(Screen):
-
- def __init__(self, session, filelist, index, startslide, plaats=None):
- self.session = session
- self.bgcolor = config.plugins.foreca.bgcolor.value
- space = config.plugins.foreca.framesize.value
- space = space + 5
-
- self.skin = "
\
- \
- \
- \
- "
-
- Screen.__init__(self, session)
- self["actions"] = HelpableActionMap(
- self, "ForecaActions",
- {
- "cancel": (self.Exit, _("Exit - End")),
- "stop": (self.Exit, _("Exit - End")),
- },
- -1
- )
- self["pic"] = Pixmap()
- self["city"] = Label(plaats)
- self.filelist = filelist
- self.old_index = 0
- self.lastindex = index
- self.currPic = []
- self.setTitle(plaats)
- self.shownow = True
- self.dirlistcount = 0
- self.index = 0
- self.picload = ePicLoad()
- self.picload.PictureData.get().append(self.finish_decode)
- self.onLayoutFinish.append(self.setPicloadConf)
-
- self.startslide = startslide
+ Screen.__init__(self, session)
+ self["actions"] = HelpableActionMap(
+ self, "ForecaActions",
+ {
+ "cancel": (self.Exit, _("Exit - End")),
+ "stop": (self.Exit, _("Exit - End")),
+ },
+ -1
+ )
+ self["pic"] = Pixmap()
+ self["city"] = Label(plaats)
+ self.filelist = filelist
+ self.startslide = startslide
+ self.old_index = 0
+ self.lastindex = index
+ self.currPic = []
+ self.setTitle(plaats)
+ self.shownow = True
+ self.dirlistcount = 0
+ self.index = 0
+ self.picload = ePicLoad()
+ self.picload.PictureData.get().append(self.finish_decode)
+ self.onLayoutFinish.append(self.setPicloadConf)
def setPicloadConf(self):
sc = getScale()
@@ -2531,7 +2209,6 @@ def ShowPicture(self):
if self.shownow and len(self.currPic):
self.shownow = False
if self.currPic[0]:
- # remove_icc_profile(self.currPic[0])
print("[ShowPicture] Imposto l'immagine:", self.currPic[0])
self["pic"].instance.setPixmap(self.currPic[0].__deref__())
else:
@@ -2576,236 +2253,6 @@ def Exit(self):
self.clear_images()
self.close(self.lastindex + self.dirlistcount)
-# ------------------------------------------------------------------------------------------
-# ------------------------------ Slide Show ------------------------------------------------
-# ------------------------------------------------------------------------------------------
-
-
-class View_Slideshow(Screen):
-
- def __init__(self, session, pindex=0, startslide=False):
-
- if DEBUG:
- FAlog("SlideShow is running...")
- self.textcolor = config.plugins.foreca.textcolor.value
- self.bgcolor = config.plugins.foreca.bgcolor.value
- space = config.plugins.foreca.framesize.value
- fontsize = config.plugins.foreca.fontsize.value
-
- self.skin = "
\
- \
- \
- \
- \
- \
- "
- Screen.__init__(self, session)
- self["actions"] = HelpableActionMap(
- self, "ForecaActions",
- {
- "cancel": (self.Exit, _("Exit - End")),
- "red": (self.Exit, _("Exit - End")),
- "stop": (self.Exit, _("Exit - End")),
- "pause": (self.PlayPause, _("Pause")),
- "playpause": (self.PlayPause, _("Play/Pause")),
- "previous": (self.prevPic, _("Left - Previous")),
- "next": (self.nextPic, _("Right - Next")),
- "showEventInfo": (self.info, _("Info - Legend")),
- "info": (self.info, _("Info - Legend")),
- },
- -1,
- )
- self["point"] = Pixmap()
- self["pic"] = Pixmap()
- self["play_icon"] = Pixmap()
- self["file"] = Label(_("Please wait, photo is being loaded ..."))
- self.old_index = 0
- self.picfilelist = []
- self.lastindex = pindex
- self.currPic = []
- self.shownow = True
- self.dirlistcount = 0
-
- self.filelist = FileList(CACHE_PATH, showDirectories=False, matchingPattern=r"^.*\.(jpg|png)$", useServiceRef=False)
- for x in self.filelist.getFileList():
- if x[0][0]:
- if x[0][1] is False:
- self.picfilelist.append(x[0][0] if PY3 else CACHE_PATH + x[0][0])
- else:
- self.dirlistcount += 1
-
- self.maxentry = len(self.picfilelist) - 1
- self.pindex = pindex - self.dirlistcount
- if self.pindex < 0:
- self.pindex = 0
-
- self.picload = ePicLoad()
- self.picload.PictureData.get().append(self.finish_decode)
- self.slideTimer = eTimer()
- self.slideTimer.callback.append(self.slidePic)
-
- if self.maxentry >= 0:
- self.onLayoutFinish.append(self.setPicloadConf)
- if startslide is True:
- self.PlayPause()
-
- def info(self):
- message = str("%s" % (_(
- "Server URL: %s\n"
- ) % BASEURL))
- entries = [
- ("VERSION", "%s" % VERSION), # No translation needed
- (_("Prev/Next"), _("Prev./Next Pic")),
- (_("Pause"), _("Pause Pic")),
- (_("Play"), _("Play Pic")),
- (_("Stop"), _("Exit")),
- (_("Red"), _("Exit")),
- (_("Info"), _("This information"))
- ]
- message += format_message(entries)
- self.session.open(MessageBox, message, MessageBox.TYPE_INFO)
-
- def setPicloadConf(self):
- sc = getScale()
- if not sc or len(sc) < 2:
- sc = (1920, 1080)
- if not hasattr(self, 'bgcolor') or not self.bgcolor:
- self.bgcolor = "#000000"
- resize_value = int(config.plugins.foreca.resize.value) if str(config.plugins.foreca.resize.value).isdigit() else 1
- self.picload.setPara([
- self["pic"].instance.size().width(),
- self["pic"].instance.size().height(),
- sc[0],
- sc[1],
- 0,
- resize_value,
- self.bgcolor
- ])
- if "play_icon" in self and self["play_icon"]:
- self["play_icon"].hide()
- if "file" in self and self["file"] and config.plugins.foreca.infoline.value is False:
- self["file"].hide()
- self.start_decode()
-
- def ShowPicture(self):
- if self.shownow and len(self.currPic):
- self.shownow = False
- self["file"].setText(self.currPic[0].replace(".jpg", "").replace(".png", ""))
- self.lastindex = self.currPic[1]
- if self.currPic[2]:
- self["pic"].instance.setPixmap(self.currPic[2].__deref__())
- else:
- print("[ShowPicture] No image data present.")
- self.currPic = []
- self.nextDay()
- self.start_decode()
-
- def finish_decode(self, picInfo=""):
- self["point"].hide()
- ptr = self.picload.getData()
- if ptr is not None:
- text = ""
- try:
- if picInfo:
- parts = picInfo.split('\n', 1)
- if parts and '/' in parts[0]:
- filename = parts[0].split('/')[-1]
- text = "(" + str(self.pindex + 1) + "/" + str(self.maxentry + 1) + ") " + filename
- self.currPic = [text, self.pindex, ptr]
- self.ShowPicture()
- except Exception as e:
- print("[finish_decode] Errore:", str(e))
- else:
- print("[finish_decode] No image data obtained from picload.")
-
- def start_decode(self):
- if self.pindex < 0 or self.pindex >= len(self.picfilelist):
- print("[start_decode] Index out of bounds: %d" % self.pindex)
- return
-
- filepath = self.picfilelist[self.pindex]
- if CACHE_PATH not in filepath:
- filepath = CACHE_PATH + filepath
- if not exists(filepath):
- return
-
- try:
- self.picload.startDecode(filepath)
- except Exception as e:
- print("[start_decode] Error while decoding image: %s" % str(e))
- self["point"].show()
-
- def nextDay(self):
- self.pindex += 1
- if self.pindex > self.maxentry:
- self.pindex = 0
-
- def prev(self):
- self.pindex -= 1
- if self.pindex < 0:
- self.pindex = self.maxentry
-
- def slidePic(self):
- if DEBUG:
- FAlog("slide to next Picture index=" + str(self.lastindex))
- if config.plugins.foreca.loop.value is False and self.lastindex == self.maxentry:
- self.PlayPause()
- self.shownow = True
- self.ShowPicture()
-
- def PlayPause(self):
- if self.slideTimer.isActive():
- self.slideTimer.stop()
- self["play_icon"].hide()
- else:
- self.slideTimer.start(config.plugins.foreca.slidetime.value * 1000)
- self["play_icon"].show()
- self.nextPic()
-
- def prevPic(self):
- self.currPic = []
- self.pindex = self.lastindex
- self.prev()
- self.start_decode()
- self.shownow = True
-
- def nextPic(self):
- self.shownow = True
- self.ShowPicture()
-
- def clear_images(self):
- try:
- for filepath in self.picfilelist:
- full_path = join(CACHE_PATH, filepath)
- if exists(full_path):
- try:
- remove(full_path)
- except OSError as e:
- print("Error while removing file:", full_path, e)
-
- self.picfilelist = []
-
- if exists(CACHE_PATH):
- for filename in listdir(CACHE_PATH):
- if filename.endswith(".jpg") or filename.endswith(".png"):
- file_path = join(CACHE_PATH, filename)
- try:
- remove(file_path)
- # print("Image file removed:", file_path)
- except OSError as e:
- print("Error while removing file:", file_path, e)
- except Exception as e:
- print("Error no file:", e)
-
- def Exit(self):
- del self.picload
- self.clear_images()
- self.close(self.lastindex + self.dirlistcount)
-
-
-# ------------------------------------------------------------------------------------------
-# -------------------------------- Foreca Settings -----------------------------------------
-# ------------------------------------------------------------------------------------------
class PicSetup(Screen, ConfigListScreen):
@@ -2911,7 +2358,6 @@ def __layoutFinished(self):
def createSetup(self):
self.editListEntry = None
self.list = []
- # self.list.append(getConfigListEntry(_("Type Server"), config.plugins.foreca.languages))
self.list.append(getConfigListEntry(_("Select units"), config.plugins.foreca.units))
self.list.append(getConfigListEntry(_("Select time format"), config.plugins.foreca.time))
self.list.append(getConfigListEntry(_("City names as labels in the Main screen"), config.plugins.foreca.citylabels))
@@ -2935,13 +2381,6 @@ def OKcity(self):
current_item = str(self["Mlist"].getCurrent()[1].getText())
self.config_entry = None
- """
- print("current_item:", type(current_item), current_item)
- print("config.plugins.foreca.home:", type(config.plugins.foreca.home), config.plugins.foreca.home.value)
- print("config.plugins.foreca.fav1:", type(config.plugins.foreca.fav1), config.plugins.foreca.fav1.value)
- print("config.plugins.foreca.fav2:", type(config.plugins.foreca.fav2), config.plugins.foreca.fav2.value)
- """
-
if current_item == config.plugins.foreca.home.value:
self.config_entry = config.plugins.foreca.home
elif current_item == config.plugins.foreca.fav1.value:
@@ -2982,11 +2421,6 @@ def OKCallback(self, city=None):
if self.config_entry is None:
print("ERROR: self.config_entry is still None after restoring!")
return
- """
- print("Config entry actual:", self.config_entry, type(self.config_entry))
- print("Available methods:", dir(self.config_entry))
- print("Checking if setValue exists:", hasattr(self.config_entry, "setValue"))
- """
if not callable(getattr(self.config_entry, "setValue", None)):
print("ERROR: setValue is not callable! It is:", type(self.config_entry.setValue))
@@ -3048,7 +2482,7 @@ def keyUp(self):
self['Mlist'].instance.moveSelection(self['Mlist'].instance.moveUp)
self.createSetup()
- def keyNumber(self, number):
+ def keyNumberGlobal(self, number):
self["Mlist"].handleKey(KEY_0 + number)
self.createSetup()