convert to eSignal api
[enigma2-plugins.git] / weathercomponent / src / Components / Renderer / MSNWeatherPixmap.py
1 # -*- coding: utf-8 -*-
2 #
3 # WeatherPlugin E2
4 #
5 # Coded by Dr.Best (c) 2012-2013
6 # Support: www.dreambox-tools.info
7 # E-Mail: dr.best@dreambox-tools.info
8 #
9 # This plugin is open source but it is NOT free software.
10 #
11 # This plugin may only be distributed to and executed on hardware which
12 # is licensed by Dream Multimedia GmbH.
13 # In other words:
14 # It's NOT allowed to distribute any parts of this plugin or its source code in ANY way
15 # to hardware which is NOT licensed by Dream Multimedia GmbH.
16 # It's NOT allowed to execute this plugin and its source code or even parts of it in ANY way
17 # on hardware which is NOT licensed by Dream Multimedia GmbH.
18 #
19 # If you want to use or modify the code or parts of it,
20 # you have to keep MY license and inform me about the modifications by mail.
21 #
22
23 from Renderer import Renderer
24 from enigma import ePixmap
25 from Components.AVSwitch import AVSwitch
26 from enigma import eEnv, ePicLoad, eRect, eSize, gPixmapPtr
27
28 class MSNWeatherPixmap(Renderer):
29         def __init__(self):
30                 Renderer.__init__(self)
31                 self.picload = ePicLoad()
32                 self.picload_conn = self.picload.PictureData.connect(self.paintIconPixmapCB)
33                 self.iconFileName = ""
34
35         GUI_WIDGET = ePixmap
36
37         def postWidgetCreate(self, instance):
38                 for (attrib, value) in self.skinAttributes:
39                         if attrib == "size":
40                                 x, y = value.split(',')
41                                 self._scaleSize = eSize(int(x), int(y))
42                                 break
43                 sc = AVSwitch().getFramebufferScale()
44                 self._aspectRatio = eSize(sc[0], sc[1])
45                 self.picload.setPara((self._scaleSize.width(), self._scaleSize.height(), sc[0], sc[1], True, 2, '#ff000000'))
46                 
47         def disconnectAll(self):
48                 self.picload_conn = None
49                 self.picload = None
50                 Renderer.disconnectAll(self)
51                 
52         def paintIconPixmapCB(self, picInfo=None):
53                 ptr = self.picload.getData()
54                 if ptr is not None:
55                         pic_scale_size = eSize()
56                         # To be added in the future:
57                         if 'scale' in eSize.__dict__ and self._scaleSize.isValid() and self._aspectRatio.isValid():
58                                 pic_scale_size = ptr.size().scale(self._scaleSize, self._aspectRatio)
59                         # To be removed in the future:
60                         elif 'scaleSize' in gPixmapPtr.__dict__:
61                                 pic_scale_size = ptr.scaleSize()
62                         if pic_scale_size.isValid():
63                                 pic_scale_width = pic_scale_size.width()
64                                 pic_scale_height = pic_scale_size.height()
65                                 dest_rect = eRect(0, 0, pic_scale_width, pic_scale_height)
66                                 self.instance.setScale(1)
67                                 self.instance.setScaleDest(dest_rect)
68                         else:
69                                 self.instance.setScale(0)
70                         self.instance.setPixmap(ptr)
71                 else:
72                         self.instance.setPixmap(None)
73                 
74         def doSuspend(self, suspended):
75                 if suspended:
76                         self.changed((self.CHANGED_CLEAR,))
77                 else:
78                         self.changed((self.CHANGED_DEFAULT,))
79                         
80                         
81         def updateIcon(self, filename):
82                 new_IconFileName = filename
83                 if (self.iconFileName != new_IconFileName):
84                         self.iconFileName = new_IconFileName
85                         self.picload.startDecode(self.iconFileName)
86
87         def changed(self, what):
88                 if what[0] != self.CHANGED_CLEAR:
89                         if self.instance:
90                                 self.updateIcon(self.source.iconfilename)
91                 else:
92                         self.picload.startDecode("")