3
# Copyright (C) 2009 Martin Owens
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU 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 General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
Gnome application for controlling a random wallpaper via crontab.
23
# Generate python libs
27
import gettext, locale
29
sys.path.append('lib')
31
from crontab import CronTab
32
from gwc.config import config
35
RAND_APP = '/usr/bin/random-wallpaper'
36
GLADE_DIR = os.path.abspath('glade')
37
LOCALE_DIR = os.path.abspath('po')
39
print "Looking for translations in %s" % LOCALE_DIR
41
locale.setlocale(locale.LC_ALL)
42
for module in gtk.glade, gettext:
43
module.bindtextdomain(APP, LOCALE_DIR)
44
module.textdomain(APP)
49
# 'folder' : [ 'localdir', 'folder_label', 'recursive', 'recursive_label' ],
50
# 'rssfeed' : [ 'rssurl', 'rss_label' ],
51
# 'deviant' : [ 'deviant_search', 'deviant_label' ],
55
class SettingsManager(object):
57
Manage the settings of this feature,
58
will save to crontab and to xml files.
64
def glade_xml(self, file, inital):
65
"""Load a glade XML File"""
66
return gtk.glade.XML(os.path.join(GLADE_DIR, file), inital, APP)
69
"""Initalise the gnome signals"""
71
'destroyWindow' : gtk.main_quit,
72
'changeChange' : self.change_change,
73
'everyChanged' : self.every_changed,
74
'timeChanged' : self.time_changed,
75
# 'localdirChanged' : self.ldir_changed,
76
# 'recursiveChanged' : self.recur_changed,
77
'refreshWall' : self.refresh_wall,
78
# 'storedirChanged' : self.sdir_changed,
79
# 'searchChanged' : self.search_changed,
80
# 'rssChanged' : self.rss_changed,
81
# 'oldremoval' : self.old_removal,
84
self.wtree = self.glade_xml('wallchanger.glade', 'window')
85
self.widget = self.wtree.get_widget
86
self.window = self.widget('window')
89
# type = str(config['type'])
90
# for key in type_widgets.keys():
91
# widget = self.widget('type_'+key)
93
# raise ValueError, 'Missing Type Widget %s' % key
94
# widget.connect( 'toggled', self.change_type, key, type_widgets[key] )
96
# widget.set_active(True)
97
# self.change_type( widget, key, type_widgets[key] )
99
change = str(config['change'])
100
if self.widget('change_'+change):
101
self.widget('change_'+change).set_active(True)
102
self.change_change(self.widget('change_'+change))
104
# folder = config['localfolder']
106
# folder = os.path.expanduser(str(folder))
107
# if os.path.exists(folder):
108
# self.widget('localdir').set_current_folder(folder)
110
# recur = str(config['recursive']) == 'True'
111
# self.widget('recursive').set_active(recur)
113
# folder = config['folder']
115
# folder = os.path.expanduser(str(folder))
116
# if os.path.exists(folder):
117
# self.widget('storedir').set_current_folder(folder)
119
# rssurl = config['rssurl']
121
# self.widget('rssurl').set_text(str(rssurl))
123
# search = config['search']
125
# self.widget('deviant_search').set_text(str(search))
127
# rmold = str(config['removeold']) == 'True'
128
# self.widget('removeold').set_active(rmold)
130
every = config['everyunit']
133
self.widget('crontype').set_active(int(every))
135
time = config['everystep']
138
self.widget('num').set_value(int(time))
140
def change_type(self, widget, text, deps):
141
"""Signal indicating a change in source image type"""
142
if widget.get_active():
143
config['type'] = str(text)
145
if widget.get_active():
146
self.widget(key).show()
148
self.widget(key).hide()
150
def change_change(self, widget):
151
"""Signal indicating a change in time type"""
152
l = widget.get_label()
153
if widget.get_active():
155
config['change'] = 'never'
157
config['change'] = 'onboot'
159
config['change'] = 'every'
160
self.widget('num').set_sensitive(True)
161
self.widget('crontype').set_sensitive(True)
164
self.widget('num').set_sensitive(False)
165
self.widget('crontype').set_sensitive(False)
168
def every_changed(self, widget):
169
"""Signal for the every numberal box"""
170
config['everyunit'] = widget.get_active()
173
def time_changed(self, widget):
174
"""Signal for the step widget"""
175
config['everystep'] = int(widget.get_value())
178
def ldir_changed(self, widget):
179
"""When the local directory is updated"""
180
config['localfolder'] = str(widget.get_current_folder())
182
def recur_changed(self, widget):
183
"""When the recursive checkbox is changed"""
184
config['recursive'] = str(widget.get_active())
186
def sdir_changed(self, widget):
187
"""When the source directory is updated"""
188
config['folder'] = str(widget.get_current_folder())
190
def search_changed(self, widget, text):
191
"""When the search field has updated"""
192
config['search'] = str(widget.get_text())
194
def rss_changed(self, widget, text):
195
"""When the RSS field has changed"""
196
config['rssurl'] = str(widget.get_text())
198
def old_removal(self, widget):
199
"""Whent he remove old images checkbox is changed"""
200
config['removeold'] = str(widget.get_active())
202
def update_cron(self):
203
"""Update the saved crontab"""
204
unit = config['everyunit']
207
step = config['everystep']
212
l = tab.find_command(RAND_APP.split('/')[-1])
216
e = tab.new(RAND_APP)
218
e.command._command = RAND_APP
220
type = str(config['change'])
232
elif type == 'onboot':
238
def finish_gui(self):
239
"""Finalisation of the gnome GUI"""
240
self.wtree.signal_autoconnect(self.signals)
242
def refresh_wall(self, widget):
243
"""Signal for loading a new random image for the background"""
245
for line in os.popen(RAND_APP):
249
if __name__ == "__main__":
250
manager = SettingsManager()