Merge lp:~jtatum/mago/gconf-docupd into lp:~mago-contributors/mago/mago-1.0

Proposed by James Tatum
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jtatum/mago/gconf-docupd
Merge into: lp:~mago-contributors/mago/mago-1.0
Diff against target: 255 lines
1 file modified
mago/gconfwrapper.py (+94/-42)
To merge this branch: bzr merge lp:~jtatum/mago/gconf-docupd
Reviewer Review Type Date Requested Status
Ara Pulido Approve
Nagappan Alagappan Approve
Javier Collado (community) Approve
Review via email: mp+12413@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Tatum (jtatum) wrote :

Adding/cleaning epydoc and indentation in gconfwrapper.

Revision history for this message
Javier Collado (javier.collado) wrote :

Looks good to me. Documentation improvements are always welcome.

review: Approve
Revision history for this message
Nagappan Alagappan (nagappan) :
review: Approve
Revision history for this message
Ara Pulido (ara) wrote :

Approved, merged and documentation updated at http://people.canonical.com/~ara/mago_doc/

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mago/gconfwrapper.py'
2--- mago/gconfwrapper.py 2009-09-03 13:06:36 +0000
3+++ mago/gconfwrapper.py 2009-09-25 13:40:25 +0000
4@@ -8,29 +8,44 @@
5 class GConf:
6 """
7 This class provides a handy interface for manipulating a gconf key.
8-
9+
10 >>> from gconfwrapper import GConf
11 >>> interface=GConf("/desktop/gnome/interface/")
12 >>> interface["accessibility"]
13- True
14+ False
15 >>> interface["gtk_theme"]="Human"
16+
17+ This class can also be used without being instantiated.
18+
19 >>> GConf.get_item('/desktop/gnome/interface/accessibility')
20- True
21-
22+ False
23+ >>> GConf.set_item('/desktop/gnome/interface/accessibility')
24+
25 The instance methods support the __getitem__ and __setitem__ special methods
26 automatically invoke get_item and set_item to handle properties. Generally,
27 instance methods should not be called directly.
28-
29+
30 The static methods are for convenience, avoiding instance instantiation when
31 getting or setting only a single gconf key.
32+
33+ @group Automatically invoked accessors: *value, *string, *bool, *int,
34+ *float, __getitem__, __setitem__, _get_type
35 """
36+
37+
38 class GConfError(Exception):
39 """
40- Exception class for GConf exceptions.
41+ Exception class for GConf exceptions
42 """
43 pass
44
45 def __init__ (self, domain):
46+ """
47+ Constructor for the GConf class
48+
49+ @param domain: The GConf domain, for instance: /desktop/gnome/interface/
50+ @type domain: string
51+ """
52 self._domain = domain
53 self._gconf_client = gconf.client_get_default ()
54
55@@ -52,23 +67,51 @@
56 return 'bool'
57 else:
58 raise self.GConfError, 'unsupported type: %s' % str (KeyType)
59-
60+
61 # Public functions
62
63 def set_domain (self, domain):
64+ """
65+ Change the domain of the current GConf instance
66+
67+ @param domain: New domain to use
68+ @type domain: string
69+ """
70 self._domain = domain
71-
72+
73 def get_domain (self):
74+ """
75+ Get the domain of the current GConf instance
76+
77+ @return: Domain of the current GConf instance
78+ @rtype: string
79+ """
80 return self._domain
81-
82+
83 def get_gconf_client (self):
84+ """
85+ Access the pygtk GConf client
86+
87+ @return: The pygtk GConf client
88+ @rtype: pygtk gconf object
89+ """
90 return self._gconf_client
91-
92+
93 def get_value (self, key):
94- '''returns the value of key `key' '''
95+ '''
96+ Returns the value of key 'key'
97+
98+ This is automatically invoked by the instance __getitem__ and
99+ __setitem__ so should not need to be called directly.
100+
101+ @param key: Target key to get
102+ @type key: string
103+ @return: Current value of target key
104+ @rtype: bool, int, string, float
105+ '''
106 if '/' in key:
107 raise self.GConfError, 'key must not contain /'
108-
109+
110 value = self._gconf_client.get (self._domain + key)
111 ValueType = value.type
112 if ValueType == VALUE_BOOL:
113@@ -79,84 +122,94 @@
114 return value.get_string ()
115 elif ValueType == VALUE_FLOAT:
116 return value.get_float ()
117-
118+
119 def set_value (self, key, value):
120- '''sets the value of key `key' to `value' '''
121+ '''
122+ Sets the value of key 'key' to 'value'
123+
124+ This is automatically invoked by the instance __getitem__ and
125+ __setitem__ so should not need to be called directly.
126+
127+ @param key: Target key to set
128+ @type key: string
129+ @param value: Value to set
130+ @type value: bool, int, string, float
131+ '''
132 value_type = self._get_type (value)
133-
134+
135 if '/' in key:
136 raise self.GConfError, 'key must not contain /'
137-
138+
139 func = getattr (self._gconf_client, 'set_' + value_type)
140 apply (func, (self._domain + key, value))
141-
142+
143 def get_string (self, key):
144 if '/' in key:
145 raise self.GConfError, 'key must not contain /'
146-
147+
148 return self._gconf_client.get_string (self._domain + key)
149-
150+
151 def set_string (self, key, value):
152 if type (value) != StringType:
153 raise self.GConfError, 'value must be a string'
154 if '/' in key:
155 raise self.GConfError, 'key must not contain /'
156-
157+
158 self._gconf_client.set_string (self._domain + key, value)
159-
160+
161 def get_bool (self, key):
162 if '/' in key:
163 raise self.GConfError, 'key must not contain /'
164-
165+
166 return self._gconf_client.get_bool (self._domain + key)
167-
168+
169 def set_bool (self, key, value):
170 if type (value) != IntType and \
171 (key != 0 or key != 1):
172 raise self.GConfError, 'value must be a boolean'
173 if '/' in key:
174 raise self.GConfError, 'key must not contain /'
175-
176+
177 self._gconf_client.set_bool (self._domain + key, value)
178-
179+
180 def get_int (self, key):
181 if '/' in key:
182 raise self.GConfError, 'key must not contain /'
183-
184+
185 return self._gconf_client.get_int (self._domain + key)
186-
187+
188 def set_int (self, key, value):
189 if type (value) != IntType:
190 raise self.GConfError, 'value must be an int'
191 if '/' in key:
192 raise self.GConfError, 'key must not contain /'
193-
194+
195 self._gconf_client.set_int (self._domain + key, value)
196-
197+
198 def get_float (self, key):
199 if '/' in key:
200 raise self.GConfError, 'key must not contain /'
201-
202+
203 return self._gconf_client.get_float (self._domain + key)
204-
205+
206 def set_float (self, key, value):
207 if type (value) != FloatType:
208 raise self.GConfError, 'value must be an float'
209-
210+
211 if '/' in key:
212 raise self.GConfError, 'key must not contain /'
213-
214+
215 self._gconf_client.set_float (self._domain + key, value)
216-
217+
218 # Some even simpler methods for the truly lazy
219 @staticmethod
220 def get_item(key):
221 """
222- Pass this a key and it will return the value.
223-
224+ Pass this a key and it will return the value
225+
226 >>> GConf.get_item("/desktop/gnome/interface/accessibility")
227 True
228-
229+
230 @type key: string
231 @param key: The gconf path to the target key
232 @rtype: string, int, bool, float
233@@ -170,10 +223,10 @@
234 @staticmethod
235 def set_item(key, value):
236 """
237- Set key to value provided:
238-
239+ Set key to value provided
240+
241 >>> GConf.set_item("/desktop/gnome/interface/accessibility", True)
242-
243+
244 @type key: string
245 @param key: The gconf path to the target key
246 @type value: string, int, bool, float
247@@ -194,7 +247,6 @@
248 print "Accessibility: %s" % GConf.get_item('/desktop/gnome/interface/accessibility')
249 GConf.set_item('/apps/test-gconf/foobar', True)
250 GConf.set_item('/apps/test-gconf/barfoo', False)
251-
252+
253 if __name__ == '__main__':
254 test()
255-

Subscribers

People subscribed via source and target branches

to status/vote changes: