Author: duncan
Date: Sun Sep 23 13:46:41 2007
New Revision: 9889
Log:
Fixed caching and weather icons
Added moon icons
Added new background
Added:
branches/rel-1/testing/Duncan/weather/1click/images/oneclick_frame.png
(contents, props changed)
Modified:
branches/rel-1/testing/Duncan/weather/1click/oneclick.py
Added: branches/rel-1/testing/Duncan/weather/1click/images/oneclick_frame.png
==============================================================================
Binary file. No diff available.
Modified: branches/rel-1/testing/Duncan/weather/1click/oneclick.py
==============================================================================
--- branches/rel-1/testing/Duncan/weather/1click/oneclick.py (original)
+++ branches/rel-1/testing/Duncan/weather/1click/oneclick.py Sun Sep 23
13:46:41 2007
@@ -72,20 +72,63 @@
#check every 1 hour
WEATHER_AGE = 3600
+WEATHER_AGE = 3600 * 24
WEATHER_DIR = os.path.join(config.SHARE_DIR, 'images', 'weather')
-WEATHER_DIR = '/sources/svn/freevo-1.x/testing/Duncan/weather/1click/64x64'
+WEATHER_DIR = '/sources/svn/freevo-1.x/testing/Duncan/weather/1click/images'
#FIXME These mappings are incorrect
-WEATHER_DATA = {
-# icon tnc.com image fallback
- 0: ( '0.png', 'thunderstorm.png', 'thunshowers.png'),
- 1: ( '1.png', 'thunderstorm.png', 'thunshowers.png'),
- 2: ( '2.png', 'thunderstorm.png', 'thunshowers.png'),
- 3: ( '3.png', 'thunderstorm.png', 'thunshowers.png'),
- 4: ( '4.png', 'thunderstorm.png', 'thunshowers.png'),
- 5: ( '5.png', '', 'rainsnow.png'),
- 6: ( '6.png', '', 'rainsnow.png'),
- 7: ( '7.png', '', 'rainsnow.png'),
+WEATHER_ICONS = {
+# icon twc.com image fallback
+ '0': ( 'twc/0.png', 'thunderstorm.png', 'thunshowers.png'),
+ '1': ( 'twc/1.png', 'thunderstorm.png', 'thunshowers.png'),
+ '2': ( 'twc/2.png', 'thunderstorm.png', 'thunshowers.png'),
+ '3': ( 'twc/3.png', 'thunderstorm.png', 'thunshowers.png'),
+ '4': ( 'twc/4.png', 'thunderstorm.png', 'thunshowers.png'),
+ '5': ( 'twc/5.png', '', 'rainsnow.png'),
+ '6': ( 'twc/6.png', '', 'rainsnow.png'),
+ '7': ( 'twc/7.png', '', 'rainsnow.png'),
+ '8': ( 'twc/8.png', 'freezingfog.png', 'fog.png'),
+ '9': ( 'twc/9.png', 'drizzle.png', 'fog.png'),
+ '10': ('twc/10.png', 'freezingrain.png', 'rainsnow.png'),
+ '11': ('twc/11.png', 'lightrain.png', 'lshowers.png'),
+ '12': ('twc/12.png', 'rain.png', 'showers.png'),
+ '13': ('twc/13.png', '', 'flurries.png'),
+ '14': ('twc/14.png', '', 'pcloudy.png'),
+ '15': ('twc/15.png', '', 'thunshowers.png'),
+ '16': ('twc/16.png', '', 'thunshowers.png'),
+ '17': ('twc/17.png', '', 'showers.png'),
+ '18': ('twc/18.png', '', 'showers.png'),
+ '19': ('twc/19.png', '', 'rainsnow.png'),
+ '20': ('twc/20.png', 'mist.png', 'fog.png'),
+ '21': ('twc/21.png', '', 'cloudy.png'),
+ '22': ('twc/22.png', '', 'flurries.png'),
+ '23': ('twc/23.png', '', 'mcloudy.png'),
+ '24': ('twc/24.png', '', 'thunshowers.png'),
+ '25': ('twc/25.png', '', 'pcloudy.png'),
+ '26': ('twc/26.png', 'cloudy.png', 'rainsnow.png'),
+ '27': ('twc/27.png', 'mostlycloudy-n.png', 'lshowers.png'),
+ '28': ('twc/28.png', 'mostlycloudy.png', 'showers.png'),
+ '29': ('twc/29.png', 'partlycloudy-n.png', 'pcloudy.png'),
+ '30': ('twc/30.png', 'partlycloudy.png', 'pcloudy.png'),
+ '31': ('twc/31.png', 'clear-n.png', 'sunny.png'),
+ '32': ('twc/32.png', 'sunny.png', 'sunny.png'),
+ '33': ('twc/33.png', 'mostlyclear.png', 'sunny.png'),
+ '34': ('twc/34.png', 'mostlysunny.png', 'sunny.png'),
+ '35': ('twc/35.png', '', 'thunshowers.png'),
+ '36': ('twc/36.png', '', 'thunshowers.png'),
+ '37': ('twc/37.png', '', 'thunshowers.png'),
+ '38': ('twc/38.png', 'scatteredthunderstorms.png', 'thunshowers.png'),
+ '39': ('twc/39.png', '', 'thunshowers.png'),
+ '40': ('twc/40.png', 'heavyrain.png', 'showers.png'),
+ '41': ('twc/41.png', 'snowshowers.png', 'snowshow.png'),
+ '42': ('twc/42.png', '', 'rainsnow.png'),
+ '43': ('twc/43.png', '', 'showers.png'),
+ '44': ('twc/44.png', '', 'unknown.png'),
+ '45': ('twc/45.png', '', 'snowshow.png'),
+ '46': ('twc/46.png', '', 'snowshow.png'),
+ '47': ('twc/47.png', 'scatteredthunderstorms.png', 'thunshowers.png'),
+ 'na': ('twc/na.png', '', 'unknown.png'),
+}
#cloudy.png
#flurries.png
#fog.png
@@ -97,48 +140,6 @@
#snowshow.png
#sunny.png
#thunshowers.png
- 8: ( '8.png', 'freezingfog.png', 'fog.png'),
- 9: ( '9.png', 'drizzle.png', 'fog.png'),
- 10: ('10.png', 'freezingrain.png', 'rainsnow.png'),
- 11: ('11.png', 'lightrain.png', 'lshowers.png'),
- 12: ('12.png', 'rain.png', 'showers.png'),
- 13: ('13.png', '', 'flurries.png'),
- 14: ('14.png', '', 'pcloudy.png'),
- 15: ('15.png', '', 'thunshowers.png'),
- 16: ('16.png', '', 'thunshowers.png'),
- 17: ('17.png', '', 'showers.png'),
- 18: ('18.png', '', 'showers.png'),
- 19: ('19.png', '', 'rainsnow.png'),
- 20: ('20.png', 'mist.png', 'fog.png'),
- 21: ('21.png', '', 'cloudy.png'),
- 22: ('22.png', '', 'flurries.png'),
- 23: ('23.png', '', 'mcloudy.png'),
- 24: ('24.png', '', 'thunshowers.png'),
- 25: ('25.png', '', 'pcloudy.png'),
- 26: ('26.png', 'cloudy.png', 'rainsnow.png'),
- 27: ('27.png', 'mostlycloudy-n.png', 'lshowers.png'),
- 28: ('28.png', 'mostlycloudy.png', 'showers.png'),
- 29: ('29.png', 'partlycloudy-n.png', 'pcloudy.png'),
- 30: ('30.png', 'partlycloudy.png', 'pcloudy.png'),
- 31: ('31.png', 'clear-n.png', 'sunny.png'),
- 32: ('32.png', 'sunny.png', 'sunny.png'),
- 33: ('33.png', 'mostlyclear.png', 'sunny.png'),
- 34: ('34.png', 'mostlysunny.png', 'sunny.png'),
- 35: ('35.png', '', 'thunshowers.png'),
- 36: ('36.png', '', 'thunshowers.png'),
- 37: ('37.png', '', 'thunshowers.png'),
- 38: ('38.png', '', 'sunny.png'),
- 39: ('39.png', '', 'thunshowers.png'),
- 30: ('40.png', 'heavyrain.png', 'showers.png'),
- 41: ('41.png', 'snowshowers.png', 'snowshow.png'),
- 42: ('42.png', '', 'rainsnow.png'),
- 43: ('43.png', '', 'showers.png'),
- 44: ('44.png', '', 'showers.png'),
- 45: ('45.png', '', 'snowshow.png'),
- 46: ('46.png', '', 'snowshow.png'),
- 47: ('47.png', '', 'rainsnow.png'),
- 48: ('48.png', '', 'rainsnow.png'),
-}
def wget(url):
''' get a file from the url '''
@@ -220,7 +221,7 @@
def __init__(self):
'''
'''
- print '__init__()'
+ print 'PluginInterface.__init__()'
if not hasattr(config, 'PLUGIN_WEATHER_LOCATIONS'):
self.reason = 'PLUGIN_WEATHER_LOCATIONS not defined'
return
@@ -250,7 +251,7 @@
Item for the menu for one feed
'''
def __init__(self, parent, location):
- print '__init__(parent=%r, location=%r)' % (parent, location)
+ print 'WeatherItem.__init__(parent=%r, location=%r)' % (parent,
location)
Item.__init__(self, parent)
self.parent = parent
@@ -329,9 +330,9 @@
self.url_curc = config.ONECLICK_URL_CURC %
(urllib.quote(self.location), self.units)
self.url_dayf = config.ONECLICK_URL_DAYF %
(urllib.quote(self.location), self.units)
self.url_eloc = config.ONECLICK_URL_ELOC %
(urllib.quote(self.location))
- self.url_curc = 'SZXX0033-cc.xml'
- self.url_dayf = 'SZXX0033-dayf5.xml'
- self.url_eloc = 'SZXX0033-eloc.xml'
+ #self.url_curc = 'SZXX0033-cc.xml'
+ #self.url_dayf = 'SZXX0033-dayf5.xml'
+ #self.url_eloc = 'SZXX0033-eloc.xml'
self.mapurl = config.ONECLICK_URL_MAP % (self.location,)
self.mapurl2 = None
self.maplink = None
@@ -368,20 +369,22 @@
return not self.error
def getLastUpdated(self):
- '''
+ ''' parse the lsup time
+ @notes there seems to be a problem with AM/PM not parsing correctly
'''
print 'getLastUpdated() "%s"' % self.updated
- value = self.updated.replace(' Local Time', '')
- print 'getLastUpdated() "%r"' % value
- # looks to be a bit locale specific
- try:
- print 'getLastUpdated() "%r"' % time.strptime(value, "%m/%d/%y
%H:%M %p")
- updated = time.mktime(time.strptime(value, "%m/%d/%y %H:%M %p"))
- print time.strftime("%c %Z", time.localtime(updated))
- print time.strftime("%c %Z", time.gmtime(updated))
- return time.strftime("%c %Z", time.localtime(updated))
+ try:
+ value = time.strptime(self.updated.replace(' AM Local Time', ''),
'%m/%d/%y %H:%M')
+ return time.strftime("%c", time.localtime(time.mktime(value)))
except ValueError, e:
- return '%s' % value
+ try:
+ value = time.strptime(self.updated.replace(' PM Local Time',
''), '%m/%d/%y %H:%M')
+ (year, mon, day, hour, min, sec, weekday, yearday, saving) =
value
+ value = (year, mon, day, hour+12, min, sec, weekday, yearday,
saving)
+ return time.strftime("%c", time.localtime(time.mktime(value)))
+ except ValueError, e:
+ print e
+ return self.updated.replace(' Local Time', '')
#if self.ismetric:
# return time.strftime("%d/%m/%Y %H:%M:%S",
time.localtime(self.updated))
#else:
@@ -418,6 +421,14 @@
print 'getPressureChange(self)'
return "%s" % (self.pressure_change)
+ def getWind(self):
+ print 'getWind(self)'
+ if self.wind_direction == 'CALM':
+ return "%s" % (self.wind_speed)
+ elif self.wind_direction == 'VAR':
+ return "%s %s %s %s" % (_('Variable'), _('at'), self.wind_speed,
self.unit_s)
+ return "%s %s %s %s" % (self.wind_direction, _('at'), self.wind_speed,
self.unit_s)
+
def getWindDir(self):
print 'getWindDir(self)'
return "%s" % (self.wind_direction)
@@ -502,7 +513,7 @@
util.save_pickle(self.elocationData, self.cacheElocation)
util.save_pickle(self.currentData, self.cacheCurrent)
util.save_pickle(self.forecastData, self.cacheForecast)
- # attempt to save weathermap
+ # attempt to save weather map
try:
if self.weatherMapData is not None:
imgfd = os.open(self.mapFile, os.O_CREAT|os.W_OK)
@@ -536,7 +547,7 @@
popup = PopupBox(text=_('Fetching Weather for %s...') %
self.popupParam)
popup.show()
- if not os.path.exists(self.cacheElocation):
+ if not os.path.isfile(self.cacheElocation):
try:
elocationData = wget(self.url_eloc)
self.elocationData = elocationData
@@ -550,7 +561,7 @@
print 'currentData:', self.currentData
except Exception, error:
print 'Failed to get the current conditions data for %s: %s' %
(self.location, error)
- if os.path.exists(self.cacheCurrent):
+ if os.path.isfile(self.cacheCurrent):
self.currentData = util.read_pickle(self.cacheCurrent)
else:
self.currentData = None
@@ -559,7 +570,7 @@
print 'forecastData:', self.forecastData
except Exception, error:
print 'Failed to get the forecast data for %s: %s' %
(self.location, error)
- if os.path.exists(self.cacheForecast):
+ if os.path.isfile(self.cacheForecast):
self.forecastData = util.read_pickle(self.cacheForecast)
else:
self.forecastData = None
@@ -693,61 +704,75 @@
self.description = '%s %s %s' % (self.current_conditions, _("at"),
self.getTemperature())
print self.icon
- self.image = self.getWeatherIcon(self.icon)
+ self.image = self.getIconDay(self.icon)
- for day in forecast.dayf.days:
+ # skip today in the days
+ for day in forecast.dayf.days[1:]:
self.date.append(day.t)
self.highTemp.append(day.hi)
self.lowTemp.append(day.low)
for part in day.parts:
if part.p == 'd':
- self.weatherIcon.append(self.getWeatherIcon(part.icon))
+ self.weatherIcon.append(self.getIconDay(part.icon))
self.weatherType.append(part.t)
#for i in dir(self):
# print i, self[i]
- def getWeatherIcon(self, num):
+ def getIconDay(self, num):
'''obtain the weather icons for multiple day forecast'''
- print 'setWeatherTypeIcon(self)'
+ print 'getIconDay()'
- icon = os.path.join(WEATHER_DIR, '%s.png' % num)
- if not os.path.exists(icon):
+ icon = os.path.join(WEATHER_DIR, WEATHER_ICONS[num][1])
+ print '1: %s: %s' % (num, icon)
+ if not os.path.isfile(icon):
+ icon = os.path.join(WEATHER_DIR, WEATHER_ICONS[num][2])
+ print '2: %s: %s' % (num, icon)
+ if not os.path.isfile(icon):
+ icon = os.path.join(WEATHER_DIR, WEATHER_ICONS[num][0])
+ print '0: %s: %s' % (num, icon)
+ if not os.path.isfile(icon):
icon = os.path.join(WEATHER_DIR, 'na.png')
print '%s: %s' % (num, icon)
return icon
+ def getIconMoon(self, num):
+ '''obtain the weather icons for multiple day forecast'''
+ print 'getIconMoon()'
+
+ icon = os.path.join(WEATHER_DIR, 'moons', '%s.png' % (num))
+ print '%s: %s' % (num, icon)
+ return icon
+
+
class WeatherMainMenu(Item):
'''
this is the item for the main menu and creates the list
of Weather Locations in a submenu.
'''
def __init__(self, parent):
- print '__init__(self, parent)'
- Item.__init__(self, parent, skin_type='weather')
+ print 'WeatherMainMenu.__init__(self, parent)'
+ Item.__init__(self, parent, skin_type='oneclick')
self.parent = parent
self.name = _('Weather')
def actions(self):
- print 'actions(self)'
- '''
- return a list of actions for this item
- '''
+ ''' return a list of actions for this item '''
+ print 'actions()'
items = [ (self.create_locations_menu , _('Locations')) ]
return items
def __call__(self, arg=None, menuw=None):
- print '__call__(self, arg=None, menuw=None)'
- '''
- call first action in the actions() list
- '''
+ ''' call first action in the actions list '''
+ print '__call__(arg=%r, menuw=%r)' % (arg, menuw)
if self.actions():
return self.actions()[0][0](arg=arg, menuw=menuw)
def create_locations_menu(self, arg=None, menuw=None):
- print 'create_locations_menu(self, arg=None, menuw=None)'
+ ''' '''
+ print 'create_locations_menu(arg=%r, menuw=%r)' % (arg, menuw)
locations = []
autoselect = 0
# create menu items
@@ -780,47 +805,52 @@
'''
A handler class to display several detailed forecast screens and catch
events
'''
- def __init__(self, iArg=None, iMenuw=None, iWeather=None):
- print '__init__(self, iArg=None, iMenuw=None, iWeather=None)'
- self.arg = iArg
- self.menuw = iMenuw
- self.weather = iWeather
+ def __init__(self, arg=None, menu=None, weather=None):
+ ''' '''
+ print 'WeatherDetailHandler.__init__(arg=%r, menu=%r, weather=%r)' %
(arg, menu, weather)
+ self.arg = arg
+ self.menuw = menu
+ self.weather = weather
self.menuw.hide(clear=False)
rc.app(self)
self.skins = ('day', 'forecast', 'week', 'doplar')
+ self.skin_num = 0
self.subtitles = (_('Current Conditions'), _('Today\'s Forecast'),
_('Extended Forecast'), _('Radar Map'))
- self.curSkin = 0
-
- self.title = self.weather.name
- self.subtitle = self.subtitles[0]
+ self.title = ''
+ self.subtitle = self.getSubtitle(self.skin_num)
# Fire up splashscreen and load the plugins
- skin.draw('weather', self)
+ skin.draw('oneclick', self)
def prevSkin(self):
- print 'prevSkin()'
'''decrements the skin number round to the last skin'''
- self.curSkin -= 1
+ print 'prevSkin()'
+ self.skin_num -= 1
# out of bounds check, reset to size of skins array
- if self.curSkin < 0:
- self.curSkin = len(self.skins)-1
- self.subtitle = self.subtitles[self.curSkin]
+ if self.skin_num < 0:
+ self.skin_num = len(self.skins)-1
+ self.subtitle = self.getSubtitle(self.skin_num)
def nextSkin(self):
'''increment the skin number round to the first skin'''
print 'nextSkin()'
- self.curSkin += 1
+ self.skin_num += 1
print 'len(self.skins)=%s' % len(self.skins)
# out of bounds check, reset to 0
- if self.curSkin >= len(self.skins):
- self.curSkin = 0
- self.subtitle = self.subtitles[self.curSkin]
+ if self.skin_num >= len(self.skins):
+ self.skin_num = 0
+ self.subtitle = self.getSubtitle(self.skin_num)
+
+ def getSubtitle(self, num):
+ ''' returns the subtitle for a skin number '''
+ print 'getSubtitle(num=%s)' % (num)
+ return '%s %s %s' % (self.subtitles[num], _('for'), self.weather.name)
def eventhandler(self, event, menuw=None):
'''eventhandler'''
@@ -833,17 +863,17 @@
elif event == 'MENU_SELECT':
self.weather.getForecast(force=1)
skin.clear()
- skin.draw('weather', self)
+ skin.draw('oneclick', self)
return True
elif event in ('MENU_DOWN', 'MENU_RIGHT'):
self.nextSkin()
- skin.draw('weather', self)
+ skin.draw('oneclick', self)
return True
elif event in ('MENU_UP', 'MENU_LEFT'):
self.prevSkin()
- skin.draw('weather', self)
+ skin.draw('oneclick', self)
return True
return False
@@ -901,7 +931,7 @@
x=x_col2, y=y_start+y_inc, height=-1, align_h='left')
text = _('Wind')
- value = '%s %s %s' % (self.parent.weather.getWindDir(), _('at'),
self.parent.weather.getWindSpeed())
+ value = '%s' % (self.parent.weather.getWind())
y_start += y_inc
self.write_text(text, self.key_font, self.content,
x=x_col1, y=y_start+y_inc, height=-1, align_h='left')
@@ -959,20 +989,16 @@
def update_forecast(self):
- '''
- this screen is extremely useless, all it's doing is putting text
- around the day view. It would be nice if I could use the same source
- that the gnome-applet weather applet uses for detailed forecast data
- '''
+ ''' this screen is taken from the 1click weather forecast of the
firefox plug-in. '''
print 'update_forecast()'
- x_start = self.content.x + (20 * self.xmult)
- y_start = self.content.y + (30 * self.xmult)
+ x_start = self.content.x + (20 * self.xmult)
+ y_start = self.content.y + (30 * self.xmult)
weather = self.parent.weather
lines = []
try:
- lines.append('%s %s' % (_('As of:'), weather.getLastUpdated()))
- lines.append('%s %s' % (_('in'), weather.getObservationStation()))
+ lines.append('%s %s %s %s' %
+ (_('As of:'), weather.getLastUpdated(), _('in'),
weather.getObservationStation()))
lines.append(' %s' % (weather.getCurrentCondition()))
lines.append(' %s %s' % (_('Temperature:'),
weather.getTemperature()))
lines.append(' %s %s' % (_('Dew Point:'), weather.getDewPoint()))
@@ -980,8 +1006,7 @@
lines.append(' %s %s' % (_('Visibility:'),
weather.getVisibility()))
lines.append(' %s %s %s %s' %
(_('Pressure:'), weather.getPressure(), _('and'),
weather.getPressureChange()))
- lines.append(' %s %s %s %s' %
- (_('Winds:'), weather.getWindDir(), _('at'),
weather.getWindSpeed()))
+ lines.append(' %s %s' % (_('Winds:'), weather.getWind()))
lines.append('%s' % (_('Tonight:')))
lines.append(' %s %s' % (_('Sunset:'), weather.getSunset()))
lines.append(' %s %s' % (_('Moon Phase:'),
weather.getMoonPhase()))
@@ -992,7 +1017,6 @@
output = ''.join(output)
output = urllib.unquote(output)
print output
- print lines
y = y_start
for line in lines:
@@ -1000,9 +1024,21 @@
x=x_start, y=y, height=-1, align_h='left')
y += (30 * self.ymult)
+ try:
+ x_start = self.content.x + (500 * self.xmult)
+ y_start = self.content.y + (300 * self.ymult)
+ iconFile = weather.getIconMoon(weather.getMoonIcon())
+ self.draw_image(iconFile,
+ (x_start, y_start, 90, 90))
+ #(x_start, y_start, int(60 * self.xmult), int(60 *
self.ymult)))
+ print 'x_start=%s, y_start=%s, xmult=%s, ymult=%s' % (x_start,
y_start, self.xmult, self.ymult)
+ except Exception, e:
+ print e
+
def update_week(self):
- '''
+ ''' update the weeks forecast
+ @remarks this can be improved
'''
print 'update_week()'
@@ -1010,7 +1046,6 @@
y_start = self.content.y + (10 * self.xmult)
day = 0
- #for x in (40, 220, 400, 580):
for x in (0, 180, 360, 540):
x2_start = x_start + (x *self.xmult)
@@ -1047,8 +1082,7 @@
day += 1
def update_doplar(self):
- '''
- '''
+ ''' update the contents of the skin's radar map '''
print 'update_doplar()'
if self.parent.weather.weatherMapData is None:
x_start = self.content.x + (10 * self.xmult)
@@ -1065,8 +1099,8 @@
print 'update_content()'
self.parent = self.menu
self.content = self.calc_geometry(self.layout.content,
copy_object=True)
- self.update_functions[self.menu.curSkin]()
+ self.update_functions[self.menu.skin_num]()
# create one instance of the WeatherType class
-skin.register ('weather', ('screen', 'subtitle', 'title', 'plugin',
WeatherBaseScreen()))
+skin.register ('oneclick', ('screen', 'subtitle', 'title', 'plugin',
WeatherBaseScreen()))
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog