Vadim Rutkovsky has proposed merging lp:~roignac/weather-indicator/Bug606729-connection-detect into lp:weather-indicator.
Requested reviews: Registry Administrators (registry) Related bugs: #606729 Startup problems - wifi connections https://bugs.launchpad.net/bugs/606729 For more details, see: https://code.launchpad.net/~roignac/weather-indicator/Bug606729-connection-detect/+merge/45561 Changes here are related to connection status handling. -- https://code.launchpad.net/~roignac/weather-indicator/Bug606729-connection-detect/+merge/45561 Your team Registry Administrators is requested to review the proposed merge of lp:~roignac/weather-indicator/Bug606729-connection-detect into lp:weather-indicator.
=== modified file 'bin/indicator-weather' --- bin/indicator-weather 2010-07-10 23:10:38 +0000 +++ bin/indicator-weather 2011-01-07 20:40:10 +0000 @@ -107,7 +107,7 @@ def menu_normal(self): self.menu = gtk.Menu() - + ##City self.city_show = gtk.MenuItem() self.city_show.set_sensitive(False) @@ -242,7 +242,6 @@ self.winder.set_menu(self.menu) - def on_city_changed(self,widget): if widget.get_active(): self.placechosen = self.places.index(widget.get_label()) @@ -251,14 +250,26 @@ def update_weather(self, notif=True,widget=None): current = self.get_weather(self.places[self.placechosen]) - sunrise,sunset,timezone = self.get_sun(self.places[self.placechosen]) - now = datetime.datetime.now().time() - sunrise_t = datetime.time(int(sunrise.split(':')[0]), int(sunrise.split(':')[1]), int(sunrise.split(':')[2])) - sunset_t = datetime.time(int(sunset.split(':')[0]), int(sunset.split(':')[1]), int(sunset.split(':')[2])) - if now<sunrise_t or now>sunset_t: - night = True + result = self.get_sun(self.places[self.placechosen]) + if result != None: + sunrise,sunset,timezone = result + now = datetime.datetime.now().time() + sunrise_t = datetime.time(int(sunrise.split(':')[0]), int(sunrise.split(':')[1]), int(sunrise.split(':')[2])) + sunset_t = datetime.time(int(sunset.split(':')[0]), int(sunset.split(':')[1]), int(sunset.split(':')[2])) + if now<sunrise_t or now>sunset_t: + night = True + else: + night = False else: - night = False + for item in self.menu.get_children()[0:len(self.menu.get_children())]: + item.destroy() + self.problem_show = gtk.MenuItem(_("Connection problem")) + self.problem_show.set_sensitive(False) + self.problem_show.show() + self.menu.append(self.problem_show) + self.winder.set_icon("ubuntuone-client-error") + return + self.condition = current print 'Update :',current,'(every',self.rate,'min. for',self.places[self.placechosen]+')' @@ -315,8 +326,9 @@ self.humid_show.set_label(self.humid) self.wind_show.set_label(self.wind) import time - self.sunrise_show.set_label(_('Sunrise: ')+time.strftime('%X',time.strptime(sunrise,'%H:%M:%S'))) - self.sunset_show.set_label(_('Sunset: ')+time.strftime('%X',time.strptime(sunset,'%H:%M:%S'))) + if result != None: + self.sunrise_show.set_label(_('Sunrise: ')+time.strftime('%X',time.strptime(sunrise,'%H:%M:%S'))) + self.sunset_show.set_label(_('Sunset: ')+time.strftime('%X',time.strptime(sunset,'%H:%M:%S'))) if self.notif != 'N' and a != False and notif: if self.condition != gconfClient.get_string("/apps/indicator-weather/current") and self.notif == 'U': @@ -349,7 +361,7 @@ dialog.run() if replace == False: if not (entry.get_text() in self.places): - self.places.append(entry.get_text()) + self.places.appednd(entry.get_text()) gconfClient.set_string("/apps/indicator-weather/places", str(self.places)) dialog.destroy() return True @@ -367,25 +379,20 @@ url = 'http://maps.google.com/maps/api/geocode/json?address='+urllib2.quote(city)+'&sensor=false' try: result = simplejson.load(urllib2.urlopen(url)) - except: - return error,error - lat,lon = result['results'][0]['geometry']['location']['lat'],result['results'][0]['geometry']['location']['lng'] - now = datetime.datetime.now() - url = 'http://www.earthtools.org/sun/%s/%s/%s/%s/99/1' % (lat,lon,now.day,now.month) - try: + lat,lon = result['results'][0]['geometry']['location']['lat'],result['results'][0]['geometry']['location']['lng'] + now = datetime.datetime.now() + url = 'http://www.earthtools.org/sun/%s/%s/%s/%s/99/1' % (lat,lon,now.day,now.month) f = urllib2.urlopen(url) - except: - return error,error - s=f.read() - parsed = parseString(s) - sunrise = parsed.getElementsByTagName("sunrise")[0].firstChild.nodeValue - sunset = parsed.getElementsByTagName("sunset")[0].firstChild.nodeValue - timezone = parsed.getElementsByTagName("timezone")[0].firstChild.nodeValue - return sunrise,sunset,timezone - + s=f.read() + parsed = parseString(s) + sunrise = parsed.getElementsByTagName("sunrise")[0].firstChild.nodeValue + sunset = parsed.getElementsByTagName("sunset")[0].firstChild.nodeValue + timezone = parsed.getElementsByTagName("timezone")[0].firstChild.nodeValue + return sunrise,sunset,timezone + except urllib2.URLError, error: + return None def get_weather(self, city, firstrun=False, extended=False, onlycity=False): - import locale localebad = locale.getlocale()[0] locale = localebad.split ('_') @@ -395,14 +402,14 @@ # open google weather api url f = urllib2.urlopen(url) - except: + except urllib2.URLError, error: # if there was an error opening the url, return - self.temp = "Connexion Problem" - self.city = "Connexion Problem" - self.humid = "Connexion Problem" - self.wind = "Connexion Problem" - self.icon = "Connexion Problem" - return "Error opening url" + self.temp = _("Connection problem") + self.city = _("Connection problem") + self.humid = _("Connection problem") + self.wind = _("Connection problem") + self.icon = _("Connection problem") + return _("Connection problem") s = f.read() encoding = f.headers['content-type'].split('charset=')[-1] @@ -524,7 +531,6 @@ def prefs(self, widget): self.prefswindow = PreferencesDialog() - self.prefswindow.show() def extforecast(self,widget):
_______________________________________________ Mailing list: https://launchpad.net/~registry Post to : registry@lists.launchpad.net Unsubscribe : https://launchpad.net/~registry More help : https://help.launchpad.net/ListHelp