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
81
82
83
84
85
86
87
88
89
90
91
92
|
#!/usr/bin/env python
# First run tutorial.glade through gtk-builder-convert with this command:
# gtk-builder-convert tutorial.glade tutorial.xml
# Then save this file as tutorial.py and make it executable using this command:
# chmod a+x tutorial.py
# And execute it:
# ./tutorial.py
import pygtk
pygtk.require("2.0")
import gtk
import gconf
DefaultTimePeriod = 30
DefaultTheme='Blue'
theme_id = {"Blue" : "0","Black" : "1"}
class Preference(object):
def __init__(self):
builder = gtk.Builder()
builder.add_from_file("preference.glade")
builder.connect_signals(
{ "on_preference_destroy" : gtk.main_quit,
"gtk_main_quit" : gtk.main_quit,
"on_Ok_clicked" : self.save_config}
)
self.window = builder.get_object("preference")
self.ThemeSelect = builder.get_object("ThemeSelect")
self.RefreshSpinButton = builder.get_object("RefreshSpinButton")
self.ThemeList = builder.get_object("ThemeList")
self.Adj = gtk.SpinButton.get_adjustment(self.RefreshSpinButton)
#read config file
self.conf=Config()
(self.TimePeriod, self.Theme) = self.conf.get_settings()
self.Adj.set_value(self.TimePeriod)
Iter = self.ThemeList.get_iter_from_string(theme_id[self.Theme])
self.ThemeSelect.set_active_iter(Iter)
#show preference windows
self.window.show()
def get_config(self):
self.conf.get_settings()
def save_config(self,*arg):
#print arg
#print gtk.ComboBox.get_active(self.ThemeSelect), gtk.ComboBox.get_active_text(self.ThemeSelect)
#print gtk.Adjustment.get_value(gtk.SpinButton.get_adjustment(self.RefreshSpinButton))
#save config
self.NewTheme = gtk.ComboBox.get_active_text(self.ThemeSelect)
self.NewTimePeriod = int(gtk.Adjustment.get_value
(gtk.SpinButton.get_adjustment(self.RefreshSpinButton)))
self.conf.set_settings(self.NewTimePeriod,self.NewTheme)
class Config():
def __init__(self):
self.client = gconf.client_get_default()
#self.prefs_key = self.client.get_preferences_key("/app/panel/applets/forismatic") #for applet
self.client.add_dir(
"/app/panel/applets/forismatic",gconf.CLIENT_PRELOAD_NONE) #delete for applet
self.prefs_key="/apps/panel/applets/forismatic" #delete for applet
#print self.prefs_key
#self.set_settings(15,'Black')
self.get_settings()
def get_settings(self):
self.TimePeriod = self.client.get_int(
self.prefs_key+"/TimePeriod")
if self.TimePeriod == None:
self.client.set_int(
self.prefs_key+"/TimePeriod", DefaultTimePeriod)
self.TimePeriod = self.client.get_int(
self.prefs_key+"/TimePeriod")
#print self.TimePeriod
self.Theme = self.client.get_string(self.prefs_key+"/Theme")
if self.Theme == None:
self.client.set_string(self.prefs_key+"/Theme",DefaultTheme)
self.Theme = DefaultTheme
#print self.Theme
return self.TimePeriod,self.Theme
def set_settings(self,TimePeriod,Theme):
self.client.set_int(self.prefs_key+"/TimePeriod",TimePeriod)
self.client.set_string(self.prefs_key+"/Theme",Theme)
if __name__ == "__main__":
app = Preference()
gtk.main()
|