This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpreference.py
executable file
·80 lines (71 loc) · 4.6 KB
/
preference.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This file is part of indicator-weather.
# Indicator Weather is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3
# as published by the Free Software Foundation.
#
# Indicator Weather is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. <http://www.gnu.org/licenses/>
#
# Author(s):
# (C) 2015-2018 Kasra Madadipouya <[email protected]>
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from configuration import Configuration
class Dialog:
def __init__(self):
self.builder = Gtk.Builder()
self.builder.add_from_file('/usr/share/ubuntu-indicator-weather/ui.glade')
self.builder.connect_signals(self)
self.window = self.builder.get_object('dialog_preferences')
self.window.set_transient_for(None)
self.window.show_all()
self.configuration = Configuration()
self.load_user_preferences_to_ui()
def load_user_preferences_to_ui(self):
combo_temperature_scale, switch_automatic_location_detection, latitude, longitude, switch_hide_location, switch_round_temperature, switch_autostart, switch_notifications = self.get_ui_objects()
combo_temperature_scale.set_active(self.configuration.get_temperature_scale())
switch_automatic_location_detection.set_state(self.configuration.get_automatic_location_detection())
latitude.set_sensitive(not switch_automatic_location_detection.get_state())
longitude.set_sensitive(not switch_automatic_location_detection.get_state())
latitude.set_value(self.configuration.get_latitude())
longitude.set_value(self.configuration.get_longitude())
switch_hide_location.set_state(self.configuration.get_hide_location())
switch_round_temperature.set_state(self.configuration.get_round_temperature())
switch_autostart.set_state(self.configuration.get_auto_start())
switch_notifications.set_state(self.configuration.get_notifications())
def get_ui_objects(self):
combo_temperature_scale = self.builder.get_object('combo_temperature_scale')
switch_automatic_location_detection = self.builder.get_object('switch_automatic_location_detection')
latitude = self.builder.get_object('spin_latitude')
longitude = self.builder.get_object('spin_longitude')
switch_hide_location = self.builder.get_object('switch_hide_location')
switch_round_temperature = self.builder.get_object('switch_round_temperature')
switch_autostart = self.builder.get_object('switch_autostart')
switch_notifications = self.builder.get_object('switch_notifications')
return combo_temperature_scale, switch_automatic_location_detection, latitude, longitude, switch_hide_location, switch_round_temperature, switch_autostart, switch_notifications
def on_cancel_button_clicked(self, widget, data=None):
self.window.destroy()
Gtk.main_quit()
def on_ok_button_clicked(self, widget, data=None):
combo_temperature_scale, switch_automatic_location_detection, latitude, longitude, switch_hide_location, switch_round_temperature, switch_autostart, switch_notifications = self.get_ui_objects()
self.configuration.set_temperature_scale(combo_temperature_scale.get_active())
self.configuration.set_automatic_location_detection(str(switch_automatic_location_detection.get_active()).title())
self.configuration.set_latitude(latitude.get_value())
self.configuration.set_longitude(longitude.get_value())
self.configuration.set_hide_location(str(switch_hide_location.get_active()).title())
self.configuration.set_round_temperature(str(switch_round_temperature.get_active()).title())
self.configuration.set_auto_start(str(switch_autostart.get_active()).title())
self.configuration.set_notifications(str(switch_notifications.get_active()).title())
self.configuration.save_configuration()
self.configuration.save_ini_start_up_script()
self.on_cancel_button_clicked(widget)
def on_switch_automatic_location_detection_activated(self, switch_automatic_location_detection, data):
longitude = self.builder.get_object('spin_longitude')
latitude = self.builder.get_object('spin_latitude')
latitude.set_sensitive(not switch_automatic_location_detection.get_active())
longitude.set_sensitive(not switch_automatic_location_detection.get_active())
def main(self):
Gtk.main()