1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for wxConfig, wxFileConfig, etc.
7 // Created: 25-Nov-1998
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
22 //---------------------------------------------------------------------------
26 static PyObject* __EnumerationHelper(bool flag, wxString& str, long index) {
27 PyObject* ret = PyTuple_New(3);
29 PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(flag));
30 PyTuple_SET_ITEM(ret, 1, wx2PyString(str));
31 PyTuple_SET_ITEM(ret, 2, PyInt_FromLong(index));
40 wxCONFIG_USE_LOCAL_FILE,
41 wxCONFIG_USE_GLOBAL_FILE,
42 wxCONFIG_USE_RELATIVE_PATH,
43 wxCONFIG_USE_NO_ESCAPE_CHARACTERS
49 "wx.ConfigBase class defines the basic interface of all config
50 classes. It can not be used by itself (it is an abstract base class)
51 and you will always use one of its derivations: wx.Config or
54 wx.ConfigBase organizes the items in a tree-like structure, modeled
55 after the Unix/Dos filesystem. There are groups that act like
56 directories and entries, key/value pairs that act like files. There
57 is always one current group given by the current path. As in the file
58 system case, to specify a key in the config class you must use a path
59 to it. Config classes also support the notion of the current group,
60 which makes it possible to use relative paths.
62 Keys are pairs \"key_name = value\" where value may be of string,
63 integer floating point or boolean, you can not store binary data
64 without first encoding it as a string. For performance reasons items
65 should be kept small, no more than a couple kilobytes.
71 // wxConfigBase(const wxString& appName = wxPyEmptyString, **** An ABC
72 // const wxString& vendorName = wxPyEmptyString,
73 // const wxString& localFilename = wxPyEmptyString,
74 // const wxString& globalFilename = wxPyEmptyString,
83 Type_Integer, // use Read(long *)
84 Type_Float // use Read(double *)
89 static wxConfigBase *, Set(wxConfigBase *config),
90 "Sets the global config object (the one returned by Get) and returns a
91 reference to the previous global config object.", "");
95 static wxConfigBase *, Get(bool createOnDemand = True),
96 "Returns the current global config object, creating one if neccessary.", "");
100 static wxConfigBase *, Create(),
101 "Create and return a new global config object. This function will
102 create the \"best\" implementation of wx.Config available for the
103 current platform.", "");
108 static void , DontCreateOnDemand(),
109 "Should Get() try to create a new log object if there isn't a current
116 virtual void , SetPath(const wxString& path),
117 "Set current path: if the first character is '/', it's the absolute
118 path, otherwise it's a relative path. '..' is supported. If the
119 strPath doesn't exist it is created.", "");
123 virtual const wxString& , GetPath() const,
124 "Retrieve the current path (always as absolute path)", "");
129 DocAStr(GetFirstGroup,
130 "GetFirstGroup() -> (more, value, index)",
131 "Allows enumerating the subgroups in a config object. Returns a tuple
132 containing a flag indicating there are more items, the name of the
133 current item, and an index to pass to GetNextGroup to fetch the next
135 PyObject* GetFirstGroup() {
140 cont = self->GetFirstGroup(value, index);
141 return __EnumerationHelper(cont, value, index);
146 DocAStr(GetNextGroup,
147 "GetNextGroup(long index) -> (more, value, index)",
148 "Allows enumerating the subgroups in a config object. Returns a tuple
149 containing a flag indicating there are more items, the name of the
150 current item, and an index to pass to GetNextGroup to fetch the next
152 PyObject* GetNextGroup(long index) {
156 cont = self->GetNextGroup(value, index);
157 return __EnumerationHelper(cont, value, index);
161 DocAStr(GetFirstEntry,
162 "GetFirstEntry() -> (more, value, index)",
163 "Allows enumerating the entries in the current group in a config
164 object. Returns a tuple containing a flag indicating there are more
165 items, the name of the current item, and an index to pass to
166 GetNextGroup to fetch the next item.", "");
167 PyObject* GetFirstEntry() {
172 cont = self->GetFirstEntry(value, index);
173 return __EnumerationHelper(cont, value, index);
177 DocAStr(GetNextEntry,
178 "GetNextEntry(long index) -> (more, value, index)",
179 "Allows enumerating the entries in the current group in a config
180 object. Returns a tuple containing a flag indicating there are more
181 items, the name of the current item, and an index to pass to
182 GetNextGroup to fetch the next item.", "");
183 PyObject* GetNextEntry(long index) {
187 cont = self->GetNextEntry(value, index);
188 return __EnumerationHelper(cont, value, index);
195 virtual size_t , GetNumberOfEntries(bool recursive = False) const,
196 "Get the number of entries in the current group, with or without its
200 virtual size_t , GetNumberOfGroups(bool recursive = False) const,
201 "Get the number of subgroups in the current group, with or without its
207 virtual bool , HasGroup(const wxString& name) const,
208 "Returns True if the group by this name exists", "");
212 virtual bool , HasEntry(const wxString& name) const,
213 "Returns True if the entry by this name exists", "");
217 bool , Exists(const wxString& name) const,
218 "Returns True if either a group or an entry with a given name exists", "");
221 // get the entry type
223 virtual EntryType , GetEntryType(const wxString& name) const,
224 "Get the type of the entry. Returns one of the wx.Config.Type_XXX values.", "");
229 wxString , Read(const wxString& key, const wxString& defaultVal = wxPyEmptyString),
230 "Returns the value of key if it exists, defaultVal otherwise.", "");
235 "Returns the value of key if it exists, defaultVal otherwise.", "");
236 long ReadInt(const wxString& key, long defaultVal = 0) {
238 self->Read(key, &rv, defaultVal);
243 "Returns the value of key if it exists, defaultVal otherwise.", "");
244 double ReadFloat(const wxString& key, double defaultVal = 0.0) {
246 self->Read(key, &rv, defaultVal);
251 "Returns the value of key if it exists, defaultVal otherwise.", "");
252 bool ReadBool(const wxString& key, bool defaultVal = False) {
254 self->Read(key, &rv, defaultVal);
260 // write the value (return True on success)
262 bool , Write(const wxString& key, const wxString& value),
263 "write the value (return True on success)", "");
266 bool, Write(const wxString& key, long value),
267 "write the value (return True on success)", "",
271 bool, Write(const wxString& key, double value),
272 "write the value (return True on success)", "",
276 bool, Write(const wxString& key, bool value),
277 "write the value (return True on success)", "",
282 virtual bool , Flush(bool currentOnly = False),
283 "permanently writes all changes", "");
287 virtual bool , RenameEntry(const wxString& oldName,
288 const wxString& newName),
289 "Rename an entry. Returns False on failure (probably because the new
290 name is already taken by an existing entry)", "");
293 virtual bool , RenameGroup(const wxString& oldName,
294 const wxString& newName),
295 "Rename a group. Returns False on failure (probably because the new
296 name is already taken by an existing entry)", "");
299 // deletes the specified entry and the group it belongs to if
300 // it was the last key in it and the second parameter is True
302 virtual bool , DeleteEntry(const wxString& key,
303 bool deleteGroupIfEmpty = True),
304 "Deletes the specified entry and the group it belongs to if it was the
305 last key in it and the second parameter is True", "");
309 virtual bool , DeleteGroup(const wxString& key),
310 "Delete the group (with all subgroups)", "");
314 virtual bool , DeleteAll(),
315 "Delete the whole underlying object (disk file, registry key, ...)
316 primarly intended for use by deinstallation routine.", "");
321 void , SetExpandEnvVars(bool doIt = True),
322 "We can automatically expand environment variables in the config
323 entries this option is on by default, you can turn it on/off at any
327 bool , IsExpandingEnvVars() const,
328 "Are we currently expanding environment variables?", "");
332 void , SetRecordDefaults(bool doIt = True),
333 "Set whether the config objec should record default values.", "");
336 bool , IsRecordingDefaults() const,
337 "Are we currently recording default values?", "");
341 wxString , ExpandEnvVars(const wxString& str) const,
342 "Expand any environment variables in str and return the result", "");
346 wxString , GetAppName() const,
350 wxString , GetVendorName() const,
355 void , SetAppName(const wxString& appName),
359 void , SetVendorName(const wxString& vendorName),
364 void , SetStyle(long style),
368 long , GetStyle() const,
374 //---------------------------------------------------------------------------
377 "This ConfigBase-derived class will use the registry on Windows,
378 and will be a wx.FileConfig on other platforms.", "");
380 class wxConfig : public wxConfigBase {
383 wxConfig(const wxString& appName = wxPyEmptyString,
384 const wxString& vendorName = wxPyEmptyString,
385 const wxString& localFilename = wxPyEmptyString,
386 const wxString& globalFilename = wxPyEmptyString,
387 long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE),
397 "This config class will use a file for storage on all platforms.", "");
399 class wxFileConfig : public wxConfigBase {
402 wxFileConfig(const wxString& appName = wxPyEmptyString,
403 const wxString& vendorName = wxPyEmptyString,
404 const wxString& localFilename = wxPyEmptyString,
405 const wxString& globalFilename = wxPyEmptyString,
406 long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE),
413 //---------------------------------------------------------------------------
415 DocStr(wxConfigPathChanger,
416 "A handy little class which changes current path to the path of given
417 entry and restores it in the destructoir: so if you declare a local
418 variable of this type, you work in the entry directory and the path is
419 automatically restored when the function returns.", "");
421 class wxConfigPathChanger
425 wxConfigPathChanger(const wxConfigBase *config, const wxString& entry),
428 ~wxConfigPathChanger();
431 const wxString& , Name() const,
432 "Get the key name", "");
436 //---------------------------------------------------------------------------
441 wxString , wxExpandEnvVars(const wxString &sz),
442 "Replace environment variables ($SOMETHING) with their values. The
443 format is $VARNAME or ${VARNAME} where VARNAME contains alphanumeric
444 characters and '_' only. '$' must be escaped ('\$') in order to be
445 taken literally.", "");
449 //---------------------------------------------------------------------------