Skip to content

Commit

Permalink
[Updated] Simplify and fix weather plugin icons rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitarCC authored and Huevos committed Aug 5, 2024
1 parent 01ad2ec commit d26c88e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 89 deletions.
53 changes: 9 additions & 44 deletions weathercomponent/src/Components/Renderer/MSNWeatherPixmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,24 @@

from Components.Renderer.Renderer import Renderer
from enigma import ePixmap
from Components.AVSwitch import AVSwitch
from enigma import eEnv, ePicLoad, eRect, eSize, gPixmapPtr
from skin import parseColor
from enigma import BT_SCALE, BT_KEEP_ASPECT_RATIO
from Tools.LoadPixmap import LoadPixmap


class MSNWeatherPixmap(Renderer):
def __init__(self):
Renderer.__init__(self)
self.picload = ePicLoad()
self.picload.PictureData.get().append(self.paintIconPixmapCB)
self.iconFileName = ""
self.backgroundColor = 0x000000
self.pix = None

GUI_WIDGET = ePixmap

def postWidgetCreate(self, instance):
for (attrib, value) in self.skinAttributes:
if attrib == "size":
x, y = value.split(',')
self._scaleSize = eSize(int(x), int(y))
break
for (attrib, value) in self.skinAttributes:
if attrib == "backgroundColor":
self.backgroundColor = parseColor(value).argb()
break
sc = AVSwitch().getFramebufferScale()
self._aspectRatio = eSize(sc[0], sc[1])
self.picload.setPara((self._scaleSize.width(), self._scaleSize.height(), sc[0], sc[1], True, 2, "#%08x" % self.backgroundColor))
pass

def disconnectAll(self):
self.picload.PictureData.get().remove(self.paintIconPixmapCB)
self.picload = None
Renderer.disconnectAll(self)

def paintIconPixmapCB(self, picInfo=None):
ptr = self.picload.getData()
if ptr is not None:
pic_scale_size = eSize()
# To be added in the future:
if 'scale' in eSize.__dict__ and self._scaleSize.isValid() and self._aspectRatio.isValid():
pic_scale_size = ptr.size().scale(self._scaleSize, self._aspectRatio)
# To be removed in the future:
elif 'scaleSize' in gPixmapPtr.__dict__:
pic_scale_size = ptr.scaleSize()
if pic_scale_size.isValid():
pic_scale_width = pic_scale_size.width()
pic_scale_height = pic_scale_size.height()
dest_rect = eRect(0, 0, pic_scale_width, pic_scale_height)
self.instance.setScale(1)
self.instance.setScaleDest(dest_rect)
else:
self.instance.setScale(0)
self.instance.setPixmap(ptr)
else:
self.instance.setPixmap(None)

def doSuspend(self, suspended):
if suspended:
self.changed((self.CHANGED_CLEAR,))
Expand All @@ -88,11 +50,14 @@ def updateIcon(self, filename):
new_IconFileName = filename
if (self.iconFileName != new_IconFileName):
self.iconFileName = new_IconFileName
self.picload.startDecode(self.iconFileName)
self.pix = LoadPixmap(self.iconFileName)
self.instance.setPixmapScale(BT_SCALE | BT_KEEP_ASPECT_RATIO)
self.instance.setPixmap(self.pix)

def changed(self, what):
if what[0] != self.CHANGED_CLEAR:
if self.instance:
self.updateIcon(self.source.iconfilename)
else:
self.picload.startDecode("")
if self.instance:
self.updateIcon(None)
51 changes: 6 additions & 45 deletions weatherplugin/src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
from Components.ActionMap import ActionMap
from Components.Sources.StaticText import StaticText
from Components.Pixmap import Pixmap
from enigma import ePicLoad, eRect, eSize, gPixmapPtr
from Components.AVSwitch import AVSwitch
from enigma import BT_SCALE, BT_KEEP_ASPECT_RATIO
from Components.config import ConfigSubsection, ConfigSubList, ConfigInteger, config
from Tools.LoadPixmap import LoadPixmap
from .setup import initConfig, MSNWeatherPluginEntriesListConfigScreen
from .MSNWeather import MSNWeather
from skin import parseColor
import time

try:
Expand Down Expand Up @@ -261,53 +260,15 @@ class WeatherIcon(Pixmap):
def __init__(self):
Pixmap.__init__(self)
self.IconFileName = ""
self.picload = ePicLoad()
self.picload.PictureData.get().append(self.paintIconPixmapCB)
self.backgroundColor = 0x000000
self.pix = None

def onShow(self):
Pixmap.onShow(self)
sc = AVSwitch().getFramebufferScale()
self._aspectRatio = eSize(sc[0], sc[1])
self._scaleSize = self.instance.size()
self.picload.setPara((self._scaleSize.width(), self._scaleSize.height(), sc[0], sc[1], True, 2, "#%08x" % self.backgroundColor))

def paintIconPixmapCB(self, picInfo=None):
ptr = self.picload.getData()
if ptr is not None:
pic_scale_size = eSize()
# To be added in the future:
if 'scale' in eSize.__dict__ and self._scaleSize.isValid() and self._aspectRatio.isValid():
pic_scale_size = ptr.size().scale(self._scaleSize, self._aspectRatio)
# To be removed in the future:
elif 'scaleSize' in gPixmapPtr.__dict__:
pic_scale_size = ptr.scaleSize()

if pic_scale_size.isValid():
pic_scale_width = pic_scale_size.width()
pic_scale_height = pic_scale_size.height()
dest_rect = eRect(0, 0, pic_scale_width, pic_scale_height)
self.instance.setScale(1)
self.instance.setScaleDest(dest_rect)
else:
self.instance.setScale(0)
self.instance.setPixmap(ptr)
else:
self.instance.setPixmap(None)

def updateIcon(self, filename):
new_IconFileName = filename
if (self.IconFileName != new_IconFileName):
self.IconFileName = new_IconFileName
self.picload.startDecode(self.IconFileName)

def applySkin(self, desktop, screen):
self.desktop = desktop
attribs = []
for (attrib, value) in self.skinAttributes[:]:
if attrib == "backgroundColor":
self.backgroundColor = parseColor(value).argb()
else:
attribs.append((attrib, value))
self.skinAttributes = attribs
return Pixmap.applySkin(self, desktop, screen)
self.pix = LoadPixmap(self.IconFileName)
self.instance.setPixmapScale(BT_SCALE | BT_KEEP_ASPECT_RATIO)
self.instance.setPixmap(self.pix)

0 comments on commit d26c88e

Please sign in to comment.