Skip to content

Commit

Permalink
Added API Key (APPID) support
Browse files Browse the repository at this point in the history
  • Loading branch information
RingOV committed Oct 25, 2015
1 parent 17fd7e4 commit 4dc30ee
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 45 deletions.
26 changes: 25 additions & 1 deletion dialogs/city_id_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@
weather_lang_list = None
gw_config = None
loading = False
grid_appid = None
entrybox_appid = None


def Save_Config():
json.dump(gw_config, open(CONFIG_PATH_FILE, "w"), sort_keys=True, indent=4, separators=(', ', ': '))


def Load_Config():
global gw_config
try:
gw_config = json.load(open(CONFIG_PATH_FILE))
except:
print ('[!] '+_('Error loading config file'))


def set_service(widget, label, liststore2, combobox_weather_lang, weather_lang, store):
global gw_config
Load_Config()
Expand All @@ -42,8 +47,14 @@ def set_service(widget, label, liststore2, combobox_weather_lang, weather_lang,
gw_config['max_days'] = data.get_max_days(i)
if gw_config['n'] > gw_config['max_days']:
gw_config['n'] = gw_config['max_days']
if data.get_need_appid(i):
grid_appid.show()
else:
grid_appid.hide()

Save_Config()


def set_weather_lang(widget):
if not loading:
global gw_config
Expand All @@ -52,6 +63,7 @@ def set_weather_lang(widget):
gw_config[gw_config['service']+'_weather_lang'] = weather_lang_list[i]
Save_Config()


def load_data(service, label, liststore2, combobox_weather_lang, weather_lang, store):
global url, example, code, dict_weather_lang, weather_lang_list, gw_config, loading
loading = True
Expand Down Expand Up @@ -81,9 +93,17 @@ def load_data(service, label, liststore2, combobox_weather_lang, weather_lang, s
store.clear()
for item in city_list:
store.append([item.split(';')[0], item.split(';')[1]])
if data.get_need_appid(service):
grid_appid.show()
try: entrybox_appid.set_text(gw_config[data.get_appid(service)])
except: entrybox_appid.set_text('')
else:
grid_appid.hide()
loading = False


def create(window, APP_PATH, service):
global grid_appid, entrybox_appid
Load_Config()
ui = Gtk.Builder()
ui.add_from_file(os.path.join(APP_PATH, "dialogs","city_id_dialog.ui"))
Expand All @@ -106,6 +126,8 @@ def create(window, APP_PATH, service):
liststore3.append([services_list[i]])
combobox_service.set_active(data.get_index(service))
store = ui.get_object('liststore1')
grid_appid = ui.get_object('grid_appid')
entrybox_appid = ui.get_object('entrybox_appid')

load_data(service, label, liststore2, combobox_weather_lang, gw_config['weather_lang'], store)

Expand All @@ -115,11 +137,13 @@ def create(window, APP_PATH, service):
bar_ok = ui.get_object('bar_ok')
bar_err = ui.get_object('bar_err')
bar_label = ui.get_object('bar_label')


treeView = ui.get_object('treeView')
create_columns(treeView)

return dialog, entrybox, treeView, bar_err, bar_ok, bar_label, combobox_weather_lang, weather_lang_list, combobox_service
return dialog, entrybox, treeView, bar_err, bar_ok, bar_label, combobox_weather_lang, weather_lang_list, combobox_service, grid_appid, entrybox_appid


def create_columns(treeView):
rendererText = Gtk.CellRendererText()
Expand Down
131 changes: 112 additions & 19 deletions dialogs/city_id_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,6 @@ selected</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entrybox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid2">
<property name="visible">True</property>
Expand Down Expand Up @@ -228,7 +213,7 @@ selected</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
Expand Down Expand Up @@ -258,7 +243,7 @@ selected</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
Expand Down Expand Up @@ -327,7 +312,7 @@ selected</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="top_attach">5</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
Expand Down Expand Up @@ -395,11 +380,119 @@ selected</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="top_attach">6</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_spacing">2</property>
<child>
<object class="GtkEntry" id="entrybox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">City code</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid_appid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<child>
<object class="GtkEntry" id="entrybox_appid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="xalign">1</property>
<property name="label">APPID</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLinkButton" id="linkbutton1">
<property name="label">?</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="relief">none</property>
<property name="uri">http://openweathermap.org/appid</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">2</property>
<property name="height">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
Expand Down
24 changes: 19 additions & 5 deletions gis-weather.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python3
#
# gis_weather.py
v = '0.7.8.22'
v = '0.7.8.24'
# Copyright (C) 2013-2015 Alexander Koltsov <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -101,6 +101,7 @@ def make_dirs(path):
gw_config_default = {
'angel': 0, # angle of clockwise rotation in degrees
'city_id': 0, # location code
'appid': '', # api key
'upd_time': 30, # Update by (in minutes)
'n': 7, # Display days
'x_pos': 60, # left position
Expand Down Expand Up @@ -1484,12 +1485,14 @@ def menu_response(self, widget, event, value=None):
if not widget.get_active():
return

global city_id, weather_lang
global city_id, weather_lang, appid
Load_Config()
try:
if value[1] != 0:
service = value[0]
city_id = value[1].split(';')[0]
if data.get_need_appid(service):
appid = gw_config[data.get_appid(service)]
if service+'_weather_lang' in gw_config.keys():
weather_lang = gw_config[service+'_weather_lang']
else:
Expand All @@ -1511,10 +1514,10 @@ def menu_response(self, widget, event, value=None):


def show_edit_dialog(self):
global city_id, gw_config
global city_id, gw_config, appid
Load_Config()
dialog, entrybox, treeview, bar_err, bar_ok, bar_label, combobox_weather_lang, weather_lang_list, combobox_service = city_id_dialog.create(self.window_main, APP_PATH, service);
dialog.show_all()
dialog, entrybox, treeview, bar_err, bar_ok, bar_label, combobox_weather_lang, weather_lang_list, combobox_service, grid_appid, entrybox_appid = city_id_dialog.create(self.window_main, APP_PATH, service);
# dialog.show_all()
response = dialog.run()

while response == Gtk.ResponseType.ACCEPT or response == Gtk.ResponseType.OK:
Expand All @@ -1524,6 +1527,10 @@ def show_edit_dialog(self):
city_list = gw_config[data.get_city_list(service)]
except:
city_list = []
try:
appid = gw_config[data.get_appid(service)]
except:
appid = ''
if response == Gtk.ResponseType.ACCEPT:
try:
selection = treeview.get_selection()
Expand All @@ -1547,6 +1554,10 @@ def show_edit_dialog(self):
pass
if response == Gtk.ResponseType.OK:
try:
if data.get_need_appid(service) and entrybox_appid.get_text() != '':
appid = entrybox_appid.get_text()
gw_config[data.get_appid(service)] = appid
Save_Config()
city_id = entrybox.get_text()
c_name = data.get_city_name(service, city_id)
if c_name == 'None':
Expand Down Expand Up @@ -1586,6 +1597,9 @@ def show_edit_dialog(self):
city_id = city_list[0].split(';')[0]
else:
city_id = 0
if data.get_need_appid(service) and entrybox_appid.get_text() != '':
appid = entrybox_appid.get_text()
gw_config[data.get_appid(service)] = appid
Save_Config()
dialog.hide()
return True
Expand Down
Binary file modified i18n/el/LC_MESSAGES/gis-weather.mo
Binary file not shown.
Loading

0 comments on commit 4dc30ee

Please sign in to comment.