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

Subscribers

People subscribed via source and target branches

to status/vote changes: