1 #!/usr/bin/env python2.5
4 # Copyright (c) 2007-2008 INdT.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # ============================================================================
21 # Author : Yves Marcoz
23 # Description : Simple RSS Reader
24 # ============================================================================
32 ranges = { "updateInterval":[0.5, 1, 2, 4, 12, 24], "expiry":[24, 48, 72], "fontSize":range(12,24), "orientation":["Automatic", "Landscape", "Portrait"]}
33 titles = {"updateInterval":"Auto-update Interval", "expiry":"Expiry For Articles", "fontSize":"Font Size For Article Listing", "orientation":"Display Orientation"}
34 subtitles = {"updateInterval":"Update every %s hours", "expiry":"Delete articles after %s hours", "fontSize":"%s pixels", "orientation":"%s"}
37 def __init__(self, parent, configFilename):
38 self.configFilename = configFilename
43 def createDialog(self):
45 self.window = gtk.Dialog("Preferences", self.parent)
46 #self.vbox = gtk.VBox(False, 10)
48 for setting in ["fontSize", "expiry", "orientation", "updateInterval",]:
49 picker = hildon.PickerButton(gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
50 selector = self.create_selector(ranges[setting], setting)
51 picker.set_selector(selector)
52 picker.set_title(titles[setting])
53 picker.set_text(titles[setting], subtitles[setting] % self.config[setting])
54 picker.set_name('HildonButton-finger')
55 picker.set_alignment(0,0,1,1)
56 self.buttons[setting] = picker
57 self.window.vbox.pack_start(picker)
59 button = hildon.CheckButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
60 button.set_label("Auto-update Enabled")
61 button.set_active(self.config["autoupdate"])
62 button.connect("toggled", self.button_toggled)
64 self.window.vbox.pack_start(button)
66 self.window.connect("destroy", self.onExit)
67 #self.window.add(self.vbox)
68 self.window.show_all()
71 def onExit(self, *widget):
75 def button_toggled(self, widget):
76 #print "widget", widget.get_active()
77 if (widget.get_active()):
78 self.config["autoupdate"] = True
80 self.config["autoupdate"] = False
81 #print "autoup", self.autoupdate
84 def selection_changed(self, selector, button, setting):
85 current_selection = selector.get_current_text()
87 self.config[setting] = current_selection
88 gobject.idle_add(self.updateButton, setting)
91 def updateButton(self, setting):
92 self.buttons[setting].set_text(titles[setting], subtitles[setting] % self.config[setting])
97 configParser = ConfigParser.RawConfigParser()
98 configParser.read(self.configFilename)
99 self.config["fontSize"] = configParser.getint(section, "fontSize")
100 self.config["expiry"] = configParser.getint(section, "expiry")
101 self.config["autoupdate"] = configParser.getboolean(section, "autoupdate")
102 self.config["updateInterval"] = configParser.getfloat(section, "updateInterval")
103 self.config["orientation"] = configParser.get(section, "orientation")
105 self.config["fontSize"] = 16
106 self.config["expiry"] = 24
107 self.config["autoupdate"] = False
108 self.config["updateInterval"] = 4
109 self.config["orientation"] = "Automatic"
111 def saveConfig(self):
112 configParser = ConfigParser.RawConfigParser()
113 configParser.add_section(section)
114 configParser.set(section, 'fontSize', str(self.config["fontSize"]))
115 configParser.set(section, 'expiry', str(self.config["expiry"]))
116 configParser.set(section, 'autoupdate', str(self.config["autoupdate"]))
117 configParser.set(section, 'updateInterval', str(self.config["updateInterval"]))
118 configParser.set(section, 'orientation', str(self.config["orientation"]))
120 # Writing our configuration file
121 file = open(self.configFilename, 'wb')
122 configParser.write(file)
125 def create_selector(self, choices, setting):
126 #self.pickerDialog = hildon.PickerDialog(self.parent)
127 selector = hildon.TouchSelector(text=True)
130 iter = selector.append_text(str(item))
131 if str(self.config[setting]) == str(item):
132 selector.set_active(0, index)
134 selector.connect("changed", self.selection_changed, setting)
135 #self.pickerDialog.set_selector(selector)
137 #self.pickerDialog.show_all()
139 def getFontSize(self):
140 return self.config["fontSize"]
142 return self.config["expiry"]
143 def isAutoUpdateEnabled(self):
144 return self.config["autoupdate"]
145 def getUpdateInterval(self):
146 return float(self.config["updateInterval"])
147 def getReadFont(self):
148 return "sans %s" % self.config["fontSize"]
149 def getUnreadFont(self):
150 return "sans bold %s" % self.config["fontSize"]
151 def getOrientation(self):
152 return ranges["orientation"].index(self.config["orientation"])