3
# Pybik -- A 3 dimensional magic cube game.
4
# Copyright © 2009, 2011-2012 B. Clausius <barcc@gmx.de>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
31
SELECTIONMODE_QUAD = 0
35
gconf_root = '/apps/pybik'
40
'selection_mode': SELECTIONMODE_EXT,
42
'dynamic_script_selection' : False,
43
'saved_state' : 'Cube 3 identity:',
46
'colors/0/color': '#a81407',
47
'colors/1/color': '#d94b1c',
48
'colors/2/color': '#f0c829',
49
'colors/3/color': '#e3e3e3',
50
'colors/4/color': '#1d6311',
51
'colors/5/color': '#00275e',
52
'colors/0/facetype': COLORED,
53
'colors/1/facetype': COLORED,
54
'colors/2/facetype': COLORED,
55
'colors/3/facetype': COLORED,
56
'colors/4/facetype': COLORED,
57
'colors/5/facetype': COLORED,
58
'colors/0/pattern': -1,
59
'colors/1/pattern': -1,
60
'colors/2/pattern': -1,
61
'colors/3/pattern': -1,
62
'colors/4/pattern': -1,
63
'colors/5/pattern': -1,
64
'colors/0/imagefile': '',
65
'colors/1/imagefile': '',
66
'colors/2/imagefile': '',
67
'colors/3/imagefile': '',
68
'colors/4/imagefile': '',
69
'colors/5/imagefile': '',
70
'colors/0/imagemode': TILED,
71
'colors/1/imagemode': TILED,
72
'colors/2/imagemode': TILED,
73
'colors/3/imagemode': TILED,
74
'colors/4/imagemode': TILED,
75
'colors/5/imagemode': TILED,
76
'background_color': '#2B0011',
80
class ConfstoreDefault (object):
84
def __init__(self, parent, defaults_):
86
self.finalize(parent, defaults_)
88
def init_notify(self):
91
def finalize(self, parent, defaults_):
93
assert ConfstoreDefault.root == None, ConfstoreDefault.root
94
ConfstoreDefault.root = self
99
#debug('%s: self.defaults[%s] = %s' % (self.root_key, key, defaults_[key]))
100
self.defaults[key] = defaults_[key]
102
key1, key2 = key.split('/', 1)
103
if key1 in self.defaults:
104
self.defaults[key1].finalize(self, {key2:defaults_[key]})
106
self.defaults[key1] = self.__class__(self, {key2:defaults_[key]}, key1)
108
def __getitem__(self, key):
109
return self.__getattr__(str(key))
111
def __getattr__(self, keyname):
112
#debug('Default getattr', self.root_key, keyname)
113
return self.defaults[keyname]
115
def set_color(self, i, color):
116
self.colors[i].color = str(color)
117
self.colors[i].facetype = COLORED
119
def set_image_filename(self, i, image_filename):
120
self.colors[i].imagefile = image_filename
121
self.colors[i].facetype = IMAGED
124
class ConfstoreGConf (ConfstoreDefault):
127
def __init__(self, parent, defaults_, key):
132
assert ConfstoreGConf.client is None
133
ConfstoreGConf.client = gconf.client_get_default()
135
self.root_key = '/'.join((parent.root_key, key))
137
ConfstoreDefault.__init__(self, parent, defaults_)
139
def init_notify(self):
141
self.client.add_dir(self.root_key, gconf.CLIENT_PRELOAD_RECURSIVE)
142
self.client.notify_add(self.root_key, self.on_gconf_notify)
143
except glib.GError as e:
144
warnings.warn(str(e))
146
def clear_cache(self):
149
def on_gconf_notify(self, unused_client, unused_cnxn_id, entry, unused_args):
150
keys = entry.key[len(self.root_key)+1:].split('/')
151
#debug('on_gconf_notify', cnxn_id, entry.key, keys)
153
for key in keys[:-1]:
156
del c.values[keys[-1]]
159
for callback in self.callbacks:
163
def _gconf_typename(value):
164
typename = value.__class__.__name__
165
if typename == "str":
169
def __getattr__(self, key):
171
if key in self.values:
172
return self.values[key]
176
value = self.client.get('/'.join((self.root_key, key)))
177
except glib.GError as e:
178
warnings.warn(str(e))
181
ret = getattr(value, "get_" + self._gconf_typename(self.defaults[key]))()
182
self.values[key] = ret
186
return ConfstoreDefault.__getattr__(self, key)
188
def __setattr__(self, key, value):
189
if key in self.defaults:
190
typename = self._gconf_typename(self.defaults[key])
191
gconf_value = gconf.Value(typename)
192
getattr(gconf_value, 'set_'+typename)(value)
194
#debug('Cache setattr', self.root_key, key, value)
195
self.values[key] = value
196
#debug('GConf setattr', self.root_key, key, gconf_value)
197
self.client.set('/'.join((self.root_key, key)), gconf_value)
199
object.__setattr__(self, key, value)
201
def __delattr__(self, key):
202
if key in self.defaults:
203
#self.__setattr__(key, self.defaults[key])
204
if key in self.values:
205
#debug('Cache delattr', self.root_key, key)
207
#debug('GConf delattr', self.root_key, key)
208
self.client.unset('/'.join((self.root_key, key)))
211
object.__delattr__(self, key)
214
def mouse_left_handed(self):
216
value = self.client.get('/desktop/gnome/peripherals/mouse/left_handed')
217
except glib.GError as e:
218
warnings.warn(str(e))
221
ret = value.get_bool()
227
confstore = ConfstoreGConf(None, defaults, gconf_root)