def __init__(self, longitude=-0.418, latitude=39.360, units=weatherservice.Units()): WeatherService.__init__(self, longitude, latitude, units) self.search_string = geocodeapi.get_inv_direction(latitude, longitude)["search_string"] self.search_string = unicode2html(self.search_string) self.latlontrouble = False self.url1 = GOOGLE_WEATHER_URL % (self.search_string) self.url2 = GOOGLE_WEATHER_URL2 % (int(self.latitude * 1000000), int(self.longitude * 1000000))
def __init__(self): if dbus.SessionBus().request_name('es.atareao.MyWeatherIndicator') != dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER: print("application already running") exit(0) # self.last_notification = 0 self.actualization_time = 0 self.current_conditions = None self.current_conditions2 = None self.preferences_out = False self.forecast_out = False # self.notification = Notify.Notification.new('','', None) self.indicator = appindicator.Indicator.new('My-Weather-Indicator', 'My-Weather-Indicator', appindicator.IndicatorCategory.APPLICATION_STATUS) self.notification2 = Notify.Notification.new('','', None) self.indicator2 = appindicator.Indicator.new('My-Weather-Indicator2', 'My-Weather-Indicator', appindicator.IndicatorCategory.APPLICATION_STATUS) # self.create_menu() self.create_menu2() # while internet_on() == False: wait(1) print(comun.CONFIG_FILE,os.path.exists(comun.CONFIG_FILE)) if not os.path.exists(comun.CONFIG_FILE): configuration = Configuration() configuration.reset() latitude,longitude = ipaddress.get_current_location() city = geocodeapi.get_inv_direction(latitude,longitude) configuration.set('latitude',latitude) configuration.set('longitude',longitude) if city is not None: configuration.set('location',city['city']) configuration.save() cm=preferences.CM() if cm.run() == Gtk.ResponseType.ACCEPT: cm.save_preferences() else: exit(0) cm.hide() cm.destroy() self.WW1 = None self.WW2 = None self.load_preferences() self.actualization_time = 0 self.seclast = 60 self.work() ''' while(datetime.now().second !=0): wait(0.1) utcnow = datetime.utcnow() if self.WW1 is not None: self.WW1.set_datetime(utcnow) if self.WW2 is not None: self.WW2.set_datetime(utcnow) ''' GLib.timeout_add(500, self.update_widgets) GLib.timeout_add(60000, self.work)
def __init__(self, longitude=-0.418, latitude=39.360, units=weatherservice.Units()): WeatherService.__init__(self, longitude, latitude, units) self.search_string = geocodeapi.get_inv_direction( latitude, longitude)['search_string'] self.search_string = unicode2html(self.search_string) self.latlontrouble = False self.url1 = GOOGLE_WEATHER_URL % (self.search_string) self.url2 = GOOGLE_WEATHER_URL2 % ( int(self.latitude * 1000000), int(self.longitude * 1000000))
def search_location(self, latitude, longitude): self.set_wait_cursor() direction = geocodeapi.get_inv_direction(latitude, longitude) print(direction) if direction is not None: self.lat = direction['lat'] self.lng = direction['lng'] self.locality = direction['city'] self.entry1.set_text(direction['city']) self.web_send('center(%s, %s)' % (self.lat, self.lng)) self.set_normal_cursor()
def search_location(self, latitude, longitude): self.set_wait_cursor() direction = geocodeapi.get_inv_direction(latitude, longitude) print(direction) if direction is not None and\ 'city' in direction.keys() and\ direction['city'] is not None and\ len(direction['city']) > 0: self.lat = direction['lat'] self.lng = direction['lng'] self.locality = direction['city'] self.entry1.set_text(direction['city']) self.web_send('center(%s, %s)' % (self.lat, self.lng)) self.set_normal_cursor()
def __init__(self,parent,latitude='40',longitude='0'): gtk.Dialog.__init__(self,'my-weather-indicator | '+_('Search Location'),parent,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) self.direction = geocodeapi.get_inv_direction(latitude,longitude) if self.direction['locality']!= None and self.direction['country']!=None: self.location = self.direction['locality']+', '+self.direction['country'] elif self.direction['country']!=None: self.location = self.direction['country'] # gtk.Dialog.__init__(self) self.set_position(gtk.WIN_POS_CENTER_ALWAYS) self.set_default_size(600, 300) self.connect('destroy', self.close_application) # self.vbox1 = gtk.VBox(spacing = 5) self.vbox1.set_border_width(5) self.get_content_area().add(self.vbox1) #*************************************************************** self.hbox1 = gtk.HBox(spacing = 5) self.hbox1.set_border_width(5) self.vbox1.add(self.hbox1) # self.label1 = gtk.Label(_('Address')+':') self.hbox1.pack_start(self.label1,False,False) # self.entry1 = gtk.Entry() self.entry1.set_text(self.location) self.hbox1.pack_start(self.entry1,True,True) #*************************************************************** self.button0 = gtk.Button(_('Search location')) self.button0.connect('clicked',self.search_location) self.vbox1.pack_start(self.button0,False,False) #*************************************************************** self.scrolledwindow = gtk.ScrolledWindow() self.vbox1.pack_start(self.scrolledwindow,True,True) self.textview =gtk.TextView() self.scrolledwindow.add(self.textview) self.show_all()
def do_search_location_in_thread(latitude, longitude): print(5) return geocodeapi.get_inv_direction(latitude, longitude)
def save_preferences(self): configuration = Configuration() if self.checkbutton11.get_active() and\ (len(self.entry11.get_text()) == 0 or self.latitude is None or self.latitude == 0 or self.longitude is None or self.longitude == 0): self.latitude, self.longitude = ipaddress.get_current_location() ans = geocodeapi.get_inv_direction(self.latitude, self.longitude) if ans is not None and 'locality' in ans.keys(): self.location = ans['locality'] if self.checkbutton21.get_active() and\ (len(self.entry21.get_text()) == 0 or self.latitude2 is None or self.latitude2 == 0 or self.longitude2 is None or self.longitude2 == 0): self.latitude2, self.longitude2 = ipaddress.get_current_location() ans = geocodeapi.get_inv_direction(self.latitude2, self.longitude2) if ans is not None and 'locality' in ans.keys(): self.location2 = ans['locality'] if len(self.entry11.get_text()) > 0: self.location = self.entry11.get_text() if len(self.entry21.get_text()) > 0: self.location2 = self.entry21.get_text() configuration.set('first-time', False) configuration.set('version', comun.VERSION) configuration.set('main-location', self.checkbutton11.get_active()) configuration.set('autolocation', self.checkbutton10.get_active()) configuration.set('location', self.location) configuration.set('latitude', self.latitude) configuration.set('longitude', self.longitude) configuration.set('show-temperature', self.checkbutton12.get_active()) configuration.set('show-notifications', self.checkbutton13.get_active()) configuration.set('widget1', self.checkbutton14.get_active()) configuration.set('onwidget1hide', self.checkbutton15.get_active()) configuration.set('onwidget1top', self.checkbutton16.get_active()) configuration.set('showintaskbar1', self.checkbutton17.get_active()) configuration.set('onalldesktop1', self.checkbutton18.get_active()) configuration.set('skin1', get_selected_value_in_combo(self.comboboxskin1)) # configuration.set('second-location', self.checkbutton21.get_active()) configuration.set('location2', self.location2) configuration.set('latitude2', self.latitude2) configuration.set('longitude2', self.longitude2) configuration.set('show-temperature2', self.checkbutton22.get_active()) configuration.set('show-notifications2', self.checkbutton23.get_active()) configuration.set('widget2', self.checkbutton24.get_active()) configuration.set('onwidget2hide', self.checkbutton25.get_active()) configuration.set('onwidget2top', self.checkbutton26.get_active()) configuration.set('showintaskbar2', self.checkbutton27.get_active()) configuration.set('onalldesktop2', self.checkbutton28.get_active()) configuration.set('skin2', get_selected_value_in_combo(self.comboboxskin2)) # if self.radiobutton251.get_active(): configuration.set('weather-service', 'yahoo') elif self.radiobutton253.get_active(): configuration.set('weather-service', 'openweathermap') # wwokey = self.wwokey.get_text() if len(wwokey) > 0: wwo = WorldWeatherOnlineService(key=wwokey) if wwo.test_connection(): configuration.set('wwo-key', wwokey) if self.radiobutton252.get_active(): configuration.set('weather-service', 'worldweatheronline') else: if self.radiobutton252.get_active(): configuration.set('weather-service', 'openweathermap') wukey = self.wukey.get_text() if len(wukey) > 0: wu = UndergroundWeatherService(key=wukey) if wu.test_connection(): configuration.set('wu-key', wukey) if self.radiobutton254.get_active(): configuration.set('weather-service', 'wunderground') else: if self.radiobutton254.get_active(): configuration.set('weather-service', 'openweathermap') configuration.set( 'temperature', get_selected_value_in_combo(self.combobox3)) configuration.set( 'pressure', get_selected_value_in_combo(self.combobox32)) configuration.set( 'visibility', get_selected_value_in_combo(self.combobox33)) configuration.set( 'wind', get_selected_value_in_combo(self.combobox31)) configuration.set( 'rain', get_selected_value_in_combo(self.combobox34)) configuration.set( 'snow', get_selected_value_in_combo(self.combobox35)) configuration.set( '24h', get_selected_value_in_combo(self.combobox36)) configuration.set( 'refresh', get_selected_value_in_combo(self.combobox45)) configuration.set('icon-light', self.radiobutton31.get_active()) print('Saving...') configuration.save() # filestart = os.path.join( os.getenv("HOME"), ".config/autostart/my-weather-indicator-autostart.desktop") if self.checkbutton1.get_active(): if not os.path.exists(os.path.dirname(filestart)): os.makedirs(os.path.dirname(filestart)) shutil.copyfile(comun.AUTOSTART, filestart) else: if os.path.exists(filestart): os.remove(filestart)
def update_menu(self, index): if not internet_on(): print('--- Not internet connection ---') if self.icon_light: icon = os.path.join( comun.ICONDIR, weatherservice.CONDITIONS['not available']['icon-light']) else: icon = os.path.join( comun.ICONDIR, weatherservice.CONDITIONS['not available']['icon-dark']) self.indicators[index].set_icon(icon) self.indicators[index].set_label('', '') msg = weatherservice.CONDITIONS['not available']['text'] msg += '\n' + _('Not Internet connection') image = os.path.join( comun.IMAGESDIR, weatherservice.CONDITIONS['not available']['image']) self.notifications[index].update( 'My-Weather-Indicator', msg, image) self.notifications[index].show() return print('--- Updating data in location %s ---' % (index)) if self.preferences[index]['autolocation']: lat, lon = ipaddress.get_current_location() location = geocodeapi.get_inv_direction(lat, lon)['city'] if location is None: location = '' print(lat, lon, location) if self.preferences[index]['latitude'] != lat and\ self.preferences[index]['longitude'] != lon: self.preferences[index]['latitude'] = lat self.preferences[index]['longitude'] = lon self.preferences[index]['location'] = location if self.ws == 'worldweatheronline': self.weatherservices[index] =\ worldweatheronlineapi.WorldWeatherOnlineService( longitude=self.preferences[index]['longitude'], latitude=self.preferences[index]['latitude'], units=self.units, key=self.key) self.menus[index]['evolution'].hide() elif self.ws == 'openweathermap': self.weatherservices[index] =\ wopenweathermapapi.OWMWeatherService( longitude=self.preferences[index]['longitude'], latitude=self.preferences[index]['latitude'], units=self.units) self.menus[index]['evolution'].show() elif self.ws == 'wunderground': self.weatherservices[index] =\ wundergroundapi.UndergroundWeatherService( longitude=self.preferences[index]['longitude'], latitude=self.preferences[index]['latitude'], units=self.units, key=self.key) self.menus[index]['evolution'].hide() print('****** Updating weather') weather = self.weatherservices[index].get_weather() print('****** Updated weather') print(self.weathers[index]) if weather is None or (weather['ok'] is False and ( self.weathers[index] is not None and self.weathers[index]['ok'] is True)): return temporal_current_conditions = weather['current_conditions'] if len(temporal_current_conditions) != 0: self.current_conditions[index] = temporal_current_conditions self.weathers[index] = weather ######################################################## if self.preferences[index]['location']: self.menus[index]['location'].set_label( _('Location') + ': ' + self.preferences[index]['location']) self.menus[index]['temperature'].set_label(_('Temperature') + ': \ {0}{1:c}'.format(self.current_conditions[index]['temperature'], 176)) self.menus[index]['humidity'].set_label( _('Humidity') + ': ' + self.current_conditions[index]['humidity']) self.menus[index]['feels_like'].set_label(_('Feels like') + ': \ {0}{1:c}'.format(self.current_conditions[index]['feels_like'], 176)) self.menus[index]['dew_point'].set_label(_('Dew Point') + ': \ {0}{1:c}'.format(self.current_conditions[index]['dew_point'], 176)) self.menus[index]['wind'].set_label( _('Wind') + ': ' + self.current_conditions[index]['wind_condition']) if self.current_conditions[index]['wind_icon']: image = Gtk.Image.new_from_file( os.path.join(comun.IMAGESDIR, self.current_conditions[index]['wind_icon'])) self.menus[index]['wind'].set_image(image) self.menus[index]['condition'].set_label( self.current_conditions[index]['condition_text']) self.menus[index]['condition'].set_image( Gtk.Image.new_from_file(os.path.join( comun.IMAGESDIR, self.current_conditions[index]['condition_image']))) if self.widgets[index] is not None: self.widgets[index].set_location( self.preferences[index]['location']) self.widgets[index].set_weather(weather) self.menus[index]['dawn'].set_label( _('Dawn') + ': ' + self.current_conditions[index]['dawn']) self.menus[index]['sunrise'].set_label( _('Sunrise') + ': ' + self.current_conditions[index]['sunrise']) self.menus[index]['sunset'].set_label( _('Sunset') + ': ' + self.current_conditions[index]['sunset']) self.menus[index]['dusk'].set_label( _('Dusk') + ': ' + self.current_conditions[index]['dusk']) self.menus[index]['moon_phase'].set_label( self.current_conditions[index]['moon_phase']) self.menus[index]['moon_phase'].set_image( Gtk.Image.new_from_file( os.path.join(comun.IMAGESDIR, self.current_conditions[index]['moon_icon']))) # pressure = ( self.current_conditions[index]['pressure'] is not None) visibility = ( self.current_conditions[index]['visibility'] is not None) cloudiness = ( self.current_conditions[index]['cloudiness'] is not None) # solarradiation = ( # self.current_conditions[index]['solarradiation'] is not None) UV = ( self.current_conditions[index]['UV'] is not None) precip_today = ( self.current_conditions[index]['precip_today'] is not None) self.menus[index]['pressure'].set_visible(pressure) self.menus[index]['visibility'].set_visible(visibility) self.menus[index]['cloudiness'].set_visible(cloudiness) self.menus[index]['uv'].set_visible(UV) self.menus[index]['precipitation'].set_visible(precip_today) if pressure: self.menus[index]['pressure'].set_label( ('%s: %s') % (_('Pressure'), self.current_conditions[index]['pressure'])) if visibility: value = self.current_conditions[index]['visibility'] self.menus[index]['visibility'].set_label( ('%s: %s') % (_('Visibility'), value)) if cloudiness: value = self.current_conditions[index]['cloudiness'] self.menus[index]['cloudiness'].set_label( ('%s: %s') % (_('Cloudiness'), value)) if UV: value = self.current_conditions[index]['UV'] self.menus[index]['uv'].set_label( ('%s: %s') % (_('UV'), value)) if precip_today: value = self.current_conditions[index]['precip_today'] self.menus[index]['precipitation'].set_label( ('%s: %s') % (_('Precipitation'), value)) if self.preferences[index]['show-temperature'] is True: value = self.current_conditions[index]['temperature'] self.indicators[index].set_label( '{0}{1:c}'.format(value, 176), '') else: self.indicators[index].set_label('', '') if self.preferences[index]['show'] is True: self.indicators[index].set_status( appindicator.IndicatorStatus.ACTIVE) else: self.indicators[index].set_status( appindicator.IndicatorStatus.PASSIVE) if self.icon_light: icon = os.path.join( comun.ICONDIR, self.current_conditions[index]['condition_icon_light']) else: icon = os.path.join( comun.ICONDIR, self.current_conditions[index]['condition_icon_dark']) self.indicators[index].set_icon(icon) if self.preferences[index]['show-notifications'] is True: msg = _('Conditions in') + ' ' msg += self.preferences[index]['location'] + '\n' msg += _('Temperature') + ': ' +\ self.current_conditions[index]['temperature'] + '\n' msg += _('Humidity') + ': ' + \ self.current_conditions[index]['humidity'] + '\n' msg += _('Wind') + ': ' +\ self.current_conditions[index]['wind_condition'] + '\n' msg += self.current_conditions[index]['condition_text'] image = os.path.join( comun.IMAGESDIR, self.current_conditions[index]['condition_image']) self.notifications[index].update( 'My-Weather-Indicator', msg, image) self.notifications[index].show() while Gtk.events_pending(): Gtk.main_iteration() print('--- End of updating data in location %s ---' % (index)) self.last_update_time = time.time()
def load_preferences(self): if not os.path.exists(comun.CONFIG_FILE): if internet_on(): configuration = Configuration() configuration.reset() latitude, longitude = ipaddress.get_current_location() city = geocodeapi.get_inv_direction( latitude, longitude)['city'] if city is None: city = '' configuration.set('latitude', latitude) configuration.set('longitude', longitude) configuration.set('location', city) configuration.save() cm = preferences.CM() if cm.run() == Gtk.ResponseType.ACCEPT: cm.save_preferences() else: exit(0) cm.hide() cm.destroy() configuration = Configuration() self.first_time = configuration.get('first-time') self.refresh = configuration.get('refresh') self.version = configuration.get('version') # self.preferences[0] = {} self.preferences[0]['show'] = configuration.get('main-location') self.preferences[0]['autolocation'] = configuration.get('autolocation') self.preferences[0]['location'] = configuration.get('location') self.preferences[0]['latitude'] = configuration.get('latitude') self.preferences[0]['longitude'] = configuration.get('longitude') self.preferences[0]['show-temperature'] =\ configuration.get('show-temperature') self.preferences[0]['show-notifications'] =\ configuration.get('show-notifications') self.preferences[0]['widget'] = configuration.get('widget1') # self.preferences[1] = {} self.preferences[1]['show'] = configuration.get('second-location') self.preferences[1]['autolocation'] = False self.preferences[1]['location'] = configuration.get('location2') self.preferences[1]['latitude'] = configuration.get('latitude2') self.preferences[1]['longitude'] = configuration.get('longitude2') self.preferences[1]['show-temperature'] =\ configuration.get('show-temperature2') self.preferences[1]['show-notifications'] =\ configuration.get('show-notifications2') self.preferences[1]['widget'] = configuration.get('widget2') # temperature = configuration.get('temperature') pressure = configuration.get('pressure') visibility = configuration.get('visibility') wind = configuration.get('wind') snow = configuration.get('snow') rain = configuration.get('rain') ampm = not configuration.get('24h') self.units = weatherservice.Units(temperature=temperature, wind=wind, pressure=pressure, visibility=visibility, snow=snow, rain=rain, ampm=ampm) self.ws = configuration.get('weather-service') if self.ws == 'yahoo': self.key = '' for i in range(INDICATORS): if self.preferences[i]['show']: self.weatherservices[i] = wyahooapi.YahooWeatherService( longitude=self.preferences[i]['longitude'], latitude=self.preferences[i]['latitude'], units=self.units) self.menus[i]['evolution'].hide() elif self.ws == 'worldweatheronline': self.key = configuration.get('wwo-key') for i in range(INDICATORS): if self.preferences[i]['show']: self.weatherservices[i] =\ worldweatheronlineapi.WorldWeatherOnlineService( longitude=self.preferences[i]['longitude'], latitude=self.preferences[i]['latitude'], units=self.units, key=self.key) self.menus[i]['evolution'].hide() elif self.ws == 'openweathermap': self.key = '' for i in range(INDICATORS): if self.preferences[i]['show']: self.weatherservices[i] =\ wopenweathermapapi.OWMWeatherService( longitude=self.preferences[i]['longitude'], latitude=self.preferences[i]['latitude'], units=self.units) self.menus[i]['evolution'].show() elif self.ws == 'wunderground': self.key = configuration.get('wu-key') for i in range(INDICATORS): if self.preferences[i]['show']: self.weatherservices[i] =\ wundergroundapi.UndergroundWeatherService( longitude=self.preferences[i]['longitude'], latitude=self.preferences[i]['latitude'], units=self.units, key=self.key) self.menus[i]['evolution'].hide() # self.icon_light = configuration.get('icon-light') # utcnow = datetime.utcnow() for i in range(INDICATORS): if self.preferences[i]['show'] and\ self.preferences[i]['widget']: if self.widgets[i] is not None: self.widgets[i].hide() self.widgets[i].destroy() self.widgets[i] = None self.widgets[i] = WeatherWidget(self.indicators[i], i) self.widgets[i].set_datetime(utcnow) self.widgets[i].set_location(self.preferences[i]['location']) self.widgets[i].connect('pinit', self.on_pinit, i) elif self.widgets[i] is not None: self.widgets[i].hide() self.widgets[i].destroy() self.widgets[i] = None print(1) self.update_weather() self.start_looking_for_internet()
def get_location(latitude,longitude): direction = geocodeapi.get_inv_direction(latitude,longitude) if direction['locality'] != None: return direction['locality'] else: return direction['country']
def get_address_from_ip2(): lat,lon = get_current_location() return get_inv_direction(lat,lon)['search_string']
def get_address_from_ip(): lat, lon = get_current_location() ans = get_inv_direction(lat, lon) return ans
def load_at_startup(self): self.direction = geocodeapi.get_inv_direction(self.latitude,self.longitude) if self.direction['locality']!= None and self.direction['country']!=None: self.location = self.direction['locality']+', '+self.direction['country'] elif self.direction['country']!=None: self.location = self.direction['country']
def __init__(self): if dbus.SessionBus().request_name('es.atareao.MyWeatherIndicator') !=\ dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER: print("application already running") exit(0) # self.weather_updater = 0 self.widgets_updater = 0 self.menus = [] self.indicators = [] self.notifications = [] self.widgets = [] self.weatherservices = [] self.weathers = [] self.current_conditions = [] self.preferences = [] # Iniciate variables for i in range(INDICATORS): self.menus.append(None) self.indicators.append(None) self.notifications.append(None) self.widgets.append(None) self.weatherservices.append(None) self.weathers.append(None) self.current_conditions.append(None) self.preferences.append(None) # status = appindicator.IndicatorCategory.APPLICATION_STATUS self.notifications[0] = Notify.Notification.new('', '', None) self.indicators[0] = appindicator.Indicator.new( 'My-Weather-Indicator', 'My-Weather-Indicator', status) self.notifications[1] = Notify.Notification.new('', '', None) self.indicators[1] = appindicator.Indicator.new( 'My-Weather-Indicator2', 'My-Weather-Indicator', status) # for i in range(INDICATORS): self.create_menu(i) # ''' while internet_on() == False: print('Waiting for internet') time_start = time.time() time_end = (time_start + 1) while time_end > time.time(): while Gtk.events_pending(): Gtk.main_iteration() time.sleep(0.3) ''' if not os.path.exists(comun.CONFIG_FILE) and internet_on(): configuration = Configuration() configuration.reset() latitude, longitude = ipaddress.get_current_location() city = geocodeapi.get_inv_direction(latitude, longitude)['city'] if city is None: city = '' configuration.set('latitude', latitude) configuration.set('longitude', longitude) configuration.set('location', city) configuration.save() cm = preferences.CM() if cm.run() == Gtk.ResponseType.ACCEPT: cm.save_preferences() else: exit(0) cm.hide() cm.destroy() for i in range(INDICATORS): self.widgets[i] = None self.load_preferences()
def update_menu(self, index): if not internet_on(): if self.icon_light: icon = os.path.join( comun.ICONDIR, weatherservice.CONDITIONS['not available']['icon-light']) else: icon = os.path.join( comun.ICONDIR, weatherservice.CONDITIONS['not available']['icon-dark']) self.indicators[index].set_icon(icon) self.indicators[index].set_label('', '') msg = weatherservice.CONDITIONS['not available']['text'] msg += '\n'+_('Not Internet connection') image = os.path.join( comun.IMAGESDIR, weatherservice.CONDITIONS['not available']['image']) self.notifications[index].update( 'My-Weather-Indicator', msg, image) self.notifications[index].show() return print('--- Updating data in location %s ---' % (index)) if self.preferences[index]['autolocation']: lat, lon = ipaddress.get_current_location() location = geocodeapi.get_inv_direction(lat, lon)['city'] if location is None: location = '' print(lat, lon, location) if self.preferences[index]['latitude'] != lat and\ self.preferences[index]['longitude'] != lon: self.preferences[index]['latitude'] = lat self.preferences[index]['longitude'] = lon self.preferences[index]['location'] = location if self.ws == 'yahoo': self.weatherservices[index] =\ wyahooapi.YahooWeatherService( longitude=self.preferences[index]['longitude'], latitude=self.preferences[index]['latitude'], units=self.units) self.menus[index]['evolution'].hide() elif self.ws == 'worldweatheronline': self.weatherservices[index] =\ worldweatheronlineapi.WorldWeatherOnlineService( longitude=self.preferences[index]['longitude'], latitude=self.preferences[index]['latitude'], units=self.units, key=self.key) self.menus[index]['evolution'].hide() elif self.ws == 'openweathermap': self.weatherservices[index] =\ wopenweathermapapi.OWMWeatherService( longitude=self.preferences[index]['longitude'], latitude=self.preferences[index]['latitude'], units=self.units) self.menus[index]['evolution'].show() elif self.ws == 'wunderground': self.weatherservices[index] =\ wundergroundapi.UndergroundWeatherService( longitude=self.preferences[index]['longitude'], latitude=self.preferences[index]['latitude'], units=self.units, key=self.key) self.menus[index]['evolution'].hide() print('****** Updating weather') weather = self.weatherservices[index].get_weather() print('****** Updated weather') if weather is None: return temporal_current_conditions = weather['current_conditions'] conditions_changed = False if len(temporal_current_conditions) != 0: self.current_conditions[index] = temporal_current_conditions self.weathers[index] = weather ######################################################## if self.preferences[index]['location']: self.menus[index]['location'].set_label( _('Location') + ': ' + self.preferences[index]['location']) self.menus[index]['temperature'].set_label(_('Temperature') + ': \ {0}{1:c}'.format(self.current_conditions[index]['temperature'], 176)) self.menus[index]['humidity'].set_label( _('Humidity') + ': ' + self.current_conditions[index]['humidity']) self.menus[index]['feels_like'].set_label(_('Feels like')+': \ {0}{1:c}'.format(self.current_conditions[index]['feels_like'], 176)) self.menus[index]['dew_point'].set_label(_('Dew Point') + ': \ {0}{1:c}'.format(self.current_conditions[index]['dew_point'], 176)) self.menus[index]['wind'].set_label( _('Wind') + ':' + self.current_conditions[index]['wind_condition']) if self.current_conditions[index]['wind_icon']: image = Gtk.Image.new_from_file( os.path.join(comun.IMAGESDIR, self.current_conditions[index]['wind_icon'])) self.menus[index]['wind'].set_image(image) self.menus[index]['condition'].set_label( self.current_conditions[index]['condition_text']) afile = os.path.join( comun.IMAGESDIR, self.current_conditions[index]['condition_image']) self.menus[index]['condition'].set_image( Gtk.Image.new_from_file(os.path.join( comun.IMAGESDIR, self.current_conditions[index]['condition_image']))) filename = os.path.join( comun.WIMAGESDIR, self.current_conditions[index]['condition_image']) if self.widgets[index] is not None: self.widgets[index].set_location( self.preferences[index]['location']) self.widgets[index].set_weather(weather) self.menus[index]['dawn'].set_label( _('Dawn')+': '+self.current_conditions[index]['dawn']) self.menus[index]['sunrise'].set_label( _('Sunrise')+': '+self.current_conditions[index]['sunrise']) self.menus[index]['sunset'].set_label( _('Sunset')+': '+self.current_conditions[index]['sunset']) self.menus[index]['dusk'].set_label( _('Dusk')+': '+self.current_conditions[index]['dusk']) self.menus[index]['moon_phase'].set_label( self.current_conditions[index]['moon_phase']) self.menus[index]['moon_phase'].set_image( Gtk.Image.new_from_file( os.path.join(comun.IMAGESDIR, self.current_conditions[index]['moon_icon']))) # pressure = ( self.current_conditions[index]['pressure'] is not None) visibility = ( self.current_conditions[index]['visibility'] is not None) cloudiness = ( self.current_conditions[index]['cloudiness'] is not None) solarradiation = ( self.current_conditions[index]['solarradiation'] is not None) UV = ( self.current_conditions[index]['UV'] is not None) precip_today = ( self.current_conditions[index]['precip_today'] is not None) self.menus[index]['pressure'].set_visible(pressure) self.menus[index]['visibility'].set_visible(visibility) self.menus[index]['cloudiness'].set_visible(cloudiness) self.menus[index]['uv'].set_visible(UV) self.menus[index]['precipitation'].set_visible(precip_today) if pressure: self.menus[index]['pressure'].set_label( ('%s: %s') % (_('Pressure'), self.current_conditions[index]['pressure'])) if visibility: value = self.current_conditions[index]['visibility'] self.menus[index]['visibility'].set_label( ('%s: %s') % (_('Visibility'), value)) if cloudiness: value = self.current_conditions[index]['cloudiness'] self.menus[index]['cloudiness'].set_label( ('%s: %s') % (_('Cloudiness'), value)) if UV: value = self.current_conditions[index]['UV'] self.menus[index]['uv'].set_label( ('%s: %s') % (_('UV'), value)) if precip_today: value = self.current_conditions[index]['precip_today'] self.menus[index]['precipitation'].set_label( ('%s: %s') % (_('Precipitation'), value)) if self.preferences[index]['show-temperature'] is True: value = self.current_conditions[index]['temperature'] self.indicators[index].set_label( '{0}{1:c}'.format(value, 176), '') else: self.indicators[index].set_label('', '') if self.preferences[index]['show'] is True: self.indicators[index].set_status( appindicator.IndicatorStatus.ACTIVE) else: self.indicators[index].set_status( appindicator.IndicatorStatus.PASSIVE) if self.icon_light: icon = os.path.join( comun.ICONDIR, self.current_conditions[index]['condition_icon_light']) else: icon = os.path.join( comun.ICONDIR, self.current_conditions[index]['condition_icon_dark']) self.indicators[index].set_icon(icon) if self.preferences[index]['show-notifications'] is True: msg = _('Conditions in')+' ' msg += self.preferences[index]['location'] + '\n' msg += _('Temperature')+': ' +\ self.current_conditions[index]['temperature'] + '\n' msg += _('Humidity') + ': ' + \ self.current_conditions[index]['humidity'] + '\n' msg += _('Wind') + ': ' +\ self.current_conditions[index]['wind_condition']+'\n' msg += self.current_conditions[index]['condition_text'] image = os.path.join( comun.IMAGESDIR, self.current_conditions[index]['condition_image']) self.notifications[index].update( 'My-Weather-Indicator', msg, image) self.notifications[index].show() while Gtk.events_pending(): Gtk.main_iteration() print('--- End of updating data in location %s ---' % (index))
def __init__(self): if dbus.SessionBus().request_name('es.atareao.MyWeatherIndicator') !=\ dbus.bus.REQUEST_NAME_REPLY_PRIMARY_OWNER: print("application already running") exit(0) # self.weather_updater = 0 self.widgets_updater = 0 self.menus = [] self.indicators = [] self.notifications = [] self.widgets = [] self.weatherservices = [] self.weathers = [] self.current_conditions = [] self.preferences = [] self.last_update_time = 0 # Iniciate variables for i in range(INDICATORS): self.menus.append(None) self.indicators.append(None) self.notifications.append(None) self.widgets.append(None) self.weatherservices.append(None) self.weathers.append(None) self.current_conditions.append(None) self.preferences.append(None) # status = appindicator.IndicatorCategory.APPLICATION_STATUS self.notifications[0] = Notify.Notification.new('', '', None) self.indicators[0] = appindicator.Indicator.new( 'My-Weather-Indicator', 'My-Weather-Indicator', status) self.notifications[1] = Notify.Notification.new('', '', None) self.indicators[1] = appindicator.Indicator.new( 'My-Weather-Indicator2', 'My-Weather-Indicator', status) # for i in range(INDICATORS): self.create_menu(i) # if not os.path.exists(comun.CONFIG_FILE): if internet_on(): configuration = Configuration() configuration.reset() latitude, longitude = ipaddress.get_current_location() city = geocodeapi.get_inv_direction( latitude, longitude)['city'] if city is None: city = '' configuration.set('latitude', latitude) configuration.set('longitude', longitude) configuration.set('location', city) configuration.save() cm = preferences.CM() if cm.run() == Gtk.ResponseType.ACCEPT: cm.save_preferences() else: exit(0) cm.hide() cm.destroy() for i in range(INDICATORS): self.widgets[i] = None self.load_preferences()
def load_preferences(self): if not os.path.exists(comun.CONFIG_FILE): if internet_on(): configuration = Configuration() configuration.reset() latitude, longitude = ipaddress.get_current_location() city = geocodeapi.get_inv_direction( latitude, longitude)['city'] if city is None: city = '' configuration.set('latitude', latitude) configuration.set('longitude', longitude) configuration.set('location', city) configuration.save() cm = preferences.CM() if cm.run() == Gtk.ResponseType.ACCEPT: cm.save_preferences() else: exit(0) cm.hide() cm.destroy() configuration = Configuration() self.first_time = configuration.get('first-time') self.refresh = configuration.get('refresh') self.version = configuration.get('version') # self.preferences[0] = {} self.preferences[0]['show'] = configuration.get('main-location') self.preferences[0]['autolocation'] = configuration.get('autolocation') self.preferences[0]['location'] = configuration.get('location') self.preferences[0]['latitude'] = configuration.get('latitude') self.preferences[0]['longitude'] = configuration.get('longitude') self.preferences[0]['show-temperature'] =\ configuration.get('show-temperature') self.preferences[0]['show-notifications'] =\ configuration.get('show-notifications') self.preferences[0]['widget'] = configuration.get('widget1') # self.preferences[1] = {} self.preferences[1]['show'] = configuration.get('second-location') self.preferences[1]['autolocation'] = False self.preferences[1]['location'] = configuration.get('location2') self.preferences[1]['latitude'] = configuration.get('latitude2') self.preferences[1]['longitude'] = configuration.get('longitude2') self.preferences[1]['show-temperature'] =\ configuration.get('show-temperature2') self.preferences[1]['show-notifications'] =\ configuration.get('show-notifications2') self.preferences[1]['widget'] = configuration.get('widget2') # temperature = configuration.get('temperature') pressure = configuration.get('pressure') visibility = configuration.get('visibility') wind = configuration.get('wind') snow = configuration.get('snow') rain = configuration.get('rain') ampm = not configuration.get('24h') self.units = weatherservice.Units(temperature=temperature, wind=wind, pressure=pressure, visibility=visibility, snow=snow, rain=rain, ampm=ampm) self.ws = configuration.get('weather-service') if self.ws == 'yahoo': self.key = '' for i in range(INDICATORS): if self.preferences[i]['show']: self.weatherservices[i] = wyahooapi.YahooWeatherService( longitude=self.preferences[i]['longitude'], latitude=self.preferences[i]['latitude'], units=self.units) self.menus[i]['evolution'].hide() elif self.ws == 'worldweatheronline': self.key = configuration.get('wwo-key') for i in range(INDICATORS): if self.preferences[i]['show']: self.weatherservices[i] =\ worldweatheronlineapi.WorldWeatherOnlineService( longitude=self.preferences[i]['longitude'], latitude=self.preferences[i]['latitude'], units=self.units, key=self.key) self.menus[i]['evolution'].hide() elif self.ws == 'openweathermap': self.key = '' for i in range(INDICATORS): if self.preferences[i]['show']: self.weatherservices[i] =\ wopenweathermapapi.OWMWeatherService( longitude=self.preferences[i]['longitude'], latitude=self.preferences[i]['latitude'], units=self.units) self.menus[i]['evolution'].show() elif self.ws == 'wunderground': self.key = configuration.get('wu-key') for i in range(INDICATORS): if self.preferences[i]['show']: self.weatherservices[i] =\ wundergroundapi.UndergroundWeatherService( longitude=self.preferences[i]['longitude'], latitude=self.preferences[i]['latitude'], units=self.units, key=self.key) self.menus[i]['evolution'].hide() # self.icon_light = configuration.get('icon-light') # utcnow = datetime.utcnow() for i in range(INDICATORS): if self.preferences[i]['show'] and\ self.preferences[i]['widget']: if self.widgets[i] is not None: self.widgets[i].hide() self.widgets[i].destroy() self.widgets[i] = None self.widgets[i] = WeatherWidget( self.indicators[i], i) self.widgets[i].set_datetime(utcnow) self.widgets[i].set_location(self.preferences[i]['location']) self.widgets[i].connect('pinit', self.on_pinit, i) elif self.widgets[i] is not None: self.widgets[i].hide() self.widgets[i].destroy() self.widgets[i] = None print(1) self.update_weather() self.start_looking_for_internet()