Package elisa :: Package plugins :: Package bad :: Package weather :: Module weather_pgm_view
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.bad.weather.weather_pgm_view

  1  # -*- coding: utf-8 -*- 
  2  # Elisa - Home multimedia server 
  3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  4  # All rights reserved. 
  5  # 
  6  # This file is available under one of two license agreements. 
  7  # 
  8  # This file is licensed under the GPL version 3. 
  9  # See "LICENSE.GPL" in the root of this distribution including a special 
 10  # exception to use Elisa with Fluendo's plugins. 
 11  # 
 12  # The GPL part of Elisa is also available under a commercial licensing 
 13  # agreement from Fluendo. 
 14  # See "LICENSE.Elisa" in the root directory of this distribution package 
 15  # for details on that license. 
 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   
28 -class WeatherPgmView(View):
29 30 """ 31 This class implements weather view for pgm 32 """ 33 34 supported_controllers = ('weather:weather_controller',) 35
36 - def __init__(self):
37 View.__init__(self) 38 self.context_path = 'pigment:pigment_context' 39 self.context_handle = None
40 41 42
43 - def controller_changed(self, old_controller, new_controller):
44 pass 45 canvas = self.frontend.context.viewport_handle.get_canvas() 46 # print "doing it" 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 ### Set the Icon 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 ### Set windsock and windspeed 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 ### Set humidity and it's image 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 ## delete this line, if you want to use it inside elisa 148 #self.context_handle = self.table 149 150 # self.icon = gtk.Image() 151 # pixbuf = gtk.gdk.pixbuf_new_from_file_at_size( 152 # self.frontend.theme.get_media( 153 # self.controller.model.icon, 154 # ('weather:data/%s.png' 155 # % self.controller.model.icon) 156 # ), 157 # 250, 158 # 250) 159 # self.icon.set_from_pixbuf(pixbuf) 160 # self.icon.show() 161 # self.table.attach(self.icon,0,2,1,3) 162 # self.debug("The icon is: %s and the path is: %s" % 163 # (self.controller.model.icon, 164 # self.frontend.theme.get_media( 165 # self.controller.model.icon, 166 # ('weather:data/%s.png' % 167 # self.controller.model.icon 168 # )) 169 # ) 170 # ) 171 # self.lbl_local_val.set_text(self.controller.model.location) 172 # self.lbl_temp_val.set_text("%d °C" % 173 # self.controller.model.temp) 174 # self.lbl_wspeed_val.set_text("%d km/h" % 175 # self.controller.model.wind_speed) 176 # self.lbl_windD_val.set_text("%d °" % 177 # self.controller.model.wind_dir) 178 # self.lbl_hum_val.set_text("%d %%" % 179 # self.controller.model.relHumidity) 180 # self.lbl_dew_val.set_text("%d °C" % 181 # self.controller.model.dew) 182 # self.lbl_sky_val.set_text(self.controller.model.sky) 183 # self.lbl_press_val.set_text("%d hPa" % 184 # self.controller.model.press) 185