1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 __maintainer__ = 'Benjamin Kampmann <benjamin@fluendo.com>'
19
20 from elisa.base_components.view import View
21
22 from pgm.graph.text import Text
23 from pgm.graph.image import Image
24 from pgm.graph.group import Group
25
26 import os, pgm
27
29
30 """
31 This class implements weather view for pgm
32 """
33
34 supported_controllers = ('weather:weather_controller',)
35
40
41
42
44 pass
45 canvas = self.frontend.context.viewport_handle.get_canvas()
46
47
48
49
50 pos_text_y = canvas.height * 0.87
51
52 self._group = Group(canvas)
53 self._group.visible = True
54 self._location = Text()
55 self._location.bg_color=(0,0,0,0)
56 title = self.controller.model.location
57 if title == '':
58 self._location.label = 'Unknown location'
59 else:
60 self._location.label = title
61 self._location.x = canvas.width * 0.1
62 self._location.y = canvas.height * 0.01
63 self._location.width = canvas.width * 0.7
64 self._location.alignment = pgm.TEXT_ALIGN_CENTER
65 self._location.visible = True
66 self._group.add(self._location)
67
68
69
70 self._icon = Image()
71 icon_path = self.frontend.theme.get_media(self.controller.model.icon,
72 ('weather:data/%s.png'
73 % self.controller.model.icon)
74 )
75 self._icon.set_from_file(icon_path)
76 self._icon.bg_color = (0,0,0,0)
77 self._icon.size = (canvas.width * 0.5, canvas.width * 0.5)
78 self._icon.x = canvas.width * 0.2
79
80 self._icon.visible = True
81 self._group.add(self._icon)
82
83
84 self._windsock = Image()
85 icon_path = self.frontend.theme.get_media('windsock.png' ,
86 'weather:data/windsock.png')
87 self._windsock.set_from_file(icon_path)
88 self._windsock.bg_color = (0,0,0,0)
89 self._windsock.width = canvas.width * 0.15
90 self._windsock.x = canvas.width * 0.1
91 self._windsock.y = canvas.height * 0.6
92 self._windsock.visible = True
93 self._group.add(self._windsock)
94
95 self._windspeed = Text()
96 self._windspeed.label = ("%d km/h" % self.controller.model.wind_speed)
97 self._windspeed.bg_color = 0,0,0,0
98 self._windspeed.x = canvas.width * 0.13
99 self._windspeed.y = pos_text_y
100 self._windspeed.width = canvas.width * 0.15
101 self._windspeed.visible = True
102 self._group.add(self._windspeed)
103
104
105
106
107 self._hydro = Image()
108 icon_path = self.frontend.theme.get_media('hydrometer.png' ,
109 'weather:data/hydrometer.png')
110 self._hydro.set_from_file(icon_path)
111 self._hydro.bg_color = (0,0,0,0)
112 self._hydro.width = canvas.width * 0.15
113 self._hydro.x = canvas.width * 0.3
114 self._hydro.y = canvas.height * 0.6
115 self._hydro.visible = True
116 self._group.add(self._hydro)
117
118 self._humi = Text()
119 self._humi.label = ("%d %%" % self.controller.model.relHumidity)
120 self._humi.bg_color = 0,0,0,0
121 self._humi.x = canvas.width * 0.35
122 self._humi.y = pos_text_y
123 self._humi.width = canvas.width * 0.15
124 self._humi.visible = True
125 self._group.add(self._humi)
126
127 self._view = Image()
128 icon_path = self.frontend.theme.get_media('view.png' ,
129 'weather:data/view.png')
130 self._view.set_from_file(icon_path)
131 self._view.bg_color = (0,0,0,0)
132 self._view.width = canvas.width * 0.15
133 self._view.x = canvas.width * 0.5
134 self._view.y = canvas.height * 0.6
135 self._view.visible = True
136 self._group.add(self._view)
137
138 self._sky = Text()
139 self._sky.label = ("%d km" % self.controller.model.view)
140 self._sky.bg_color = 0,0,0,0
141 self._sky.x = canvas.width * 0.53
142 self._sky.y = pos_text_y
143 self._sky.width = canvas.width * 0.15
144 self._sky.visible = True
145 self._group.add(self._sky)
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185