def menu_set_preferences_response(self, widget): self.menu_offon(False) cm = preferences.CM() if cm.run() == Gtk.ResponseType.ACCEPT: cm.hide() cm.save_preferences() cm.hide() cm.destroy() self.load_preferences() cm.destroy() self.menu_offon(True)
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 __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()