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 *)
88 %apply SWIGTYPE *DISOWN { wxConfigBase *config };
90 static wxConfigBase *, Set(wxConfigBase *config),
91 "Sets the global config object (the one returned by Get) and returns a
92 reference to the previous global config object.", "");
93 %clear wxConfigBase *config;
96 static wxConfigBase *, Get(bool createOnDemand = true),
97 "Returns the current global config object, creating one if neccessary.", "");
101 static wxConfigBase *, Create(),
102 "Create and return a new global config object. This function will
103 create the \"best\" implementation of wx.Config available for the
104 current platform.", "");
109 static void , DontCreateOnDemand(),
110 "Should Get() try to create a new log object if there isn't a current
117 virtual void , SetPath(const wxString& path),
118 "Set current path: if the first character is '/', it's the absolute
119 path, otherwise it's a relative path. '..' is supported. If the
120 strPath doesn't exist it is created.", "");
124 virtual const wxString& , GetPath() const,
125 "Retrieve the current path (always as absolute path)", "");
130 DocAStr(GetFirstGroup,
131 "GetFirstGroup() -> (more, value, index)",
132 "Allows enumerating the subgroups in a config object. Returns a tuple
133 containing a flag indicating there are more items, the name of the
134 current item, and an index to pass to GetNextGroup to fetch the next
136 PyObject* GetFirstGroup() {
141 cont = self->GetFirstGroup(value, index);
142 return __EnumerationHelper(cont, value, index);
147 DocAStr(GetNextGroup,
148 "GetNextGroup(long index) -> (more, value, index)",
149 "Allows enumerating the subgroups in a config object. Returns a tuple
150 containing a flag indicating there are more items, the name of the
151 current item, and an index to pass to GetNextGroup to fetch the next
153 PyObject* GetNextGroup(long index) {
157 cont = self->GetNextGroup(value, index);
158 return __EnumerationHelper(cont, value, index);
162 DocAStr(GetFirstEntry,
163 "GetFirstEntry() -> (more, value, index)",
164 "Allows enumerating the entries in the current group in a config
165 object. Returns a tuple containing a flag indicating there are more
166 items, the name of the current item, and an index to pass to
167 GetNextGroup to fetch the next item.", "");
168 PyObject* GetFirstEntry() {
173 cont = self->GetFirstEntry(value, index);
174 return __EnumerationHelper(cont, value, index);
178 DocAStr(GetNextEntry,
179 "GetNextEntry(long index) -> (more, value, index)",
180 "Allows enumerating the entries in the current group in a config
181 object. Returns a tuple containing a flag indicating there are more
182 items, the name of the current item, and an index to pass to
183 GetNextGroup to fetch the next item.", "");
184 PyObject* GetNextEntry(long index) {
188 cont = self->GetNextEntry(value, index);
189 return __EnumerationHelper(cont, value, index);
196 virtual size_t , GetNumberOfEntries(bool recursive = false) const,
197 "Get the number of entries in the current group, with or without its
201 virtual size_t , GetNumberOfGroups(bool recursive = false) const,
202 "Get the number of subgroups in the current group, with or without its
208 virtual bool , HasGroup(const wxString& name) const,
209 "Returns True if the group by this name exists", "");
213 virtual bool , HasEntry(const wxString& name) const,
214 "Returns True if the entry by this name exists", "");
218 bool , Exists(const wxString& name) const,
219 "Returns True if either a group or an entry with a given name exists", "");
222 // get the entry type
224 virtual EntryType , GetEntryType(const wxString& name) const,
225 "Get the type of the entry. Returns one of the wx.Config.Type_XXX values.", "");
230 wxString , Read(const wxString& key, const wxString& defaultVal = wxPyEmptyString),
231 "Returns the value of key if it exists, defaultVal otherwise.", "");
236 "Returns the value of key if it exists, defaultVal otherwise.", "");
237 long ReadInt(const wxString& key, long defaultVal = 0) {
239 self->Read(key, &rv, defaultVal);
244 "Returns the value of key if it exists, defaultVal otherwise.", "");
245 double ReadFloat(const wxString& key, double defaultVal = 0.0) {
247 self->Read(key, &rv, defaultVal);
252 "Returns the value of key if it exists, defaultVal otherwise.", "");
253 bool ReadBool(const wxString& key, bool defaultVal = false) {
255 self->Read(key, &rv, defaultVal);
261 // write the value (return True on success)
263 bool , Write(const wxString& key, const wxString& value),
264 "write the value (return True on success)", "");
267 bool, Write(const wxString& key, long value),
268 "write the value (return True on success)", "",
272 bool, Write(const wxString& key, double value),
273 "write the value (return True on success)", "",
277 bool, Write(const wxString& key, bool value),
278 "write the value (return True on success)", "",
283 virtual bool , Flush(bool currentOnly = false),
284 "permanently writes all changes", "");
288 virtual bool , RenameEntry(const wxString& oldName,
289 const wxString& newName),
290 "Rename an entry. Returns False on failure (probably because the new
291 name is already taken by an existing entry)", "");
294 virtual bool , RenameGroup(const wxString& oldName,
295 const wxString& newName),
296 "Rename a group. Returns False on failure (probably because the new
297 name is already taken by an existing entry)", "");
300 // deletes the specified entry and the group it belongs to if
301 // it was the last key in it and the second parameter is True
303 virtual bool , DeleteEntry(const wxString& key,
304 bool deleteGroupIfEmpty = true),
305 "Deletes the specified entry and the group it belongs to if it was the
306 last key in it and the second parameter is True", "");
310 virtual bool , DeleteGroup(const wxString& key),
311 "Delete the group (with all subgroups)", "");
315 virtual bool , DeleteAll(),
316 "Delete the whole underlying object (disk file, registry key, ...)
317 primarly intended for use by deinstallation routine.", "");
322 void , SetExpandEnvVars(bool doIt = true),
323 "We can automatically expand environment variables in the config
324 entries this option is on by default, you can turn it on/off at any
328 bool , IsExpandingEnvVars() const,
329 "Are we currently expanding environment variables?", "");
333 void , SetRecordDefaults(bool doIt = true),
334 "Set whether the config objec should record default values.", "");
337 bool , IsRecordingDefaults() const,
338 "Are we currently recording default values?", "");
342 wxString , ExpandEnvVars(const wxString& str) const,
343 "Expand any environment variables in str and return the result", "");
347 wxString , GetAppName() const,
351 wxString , GetVendorName() const,
356 void , SetAppName(const wxString& appName),
360 void , SetVendorName(const wxString& vendorName),
365 void , SetStyle(long style),
369 long , GetStyle() const,
375 //---------------------------------------------------------------------------
378 "This ConfigBase-derived class will use the registry on Windows,
379 and will be a wx.FileConfig on other platforms.", "");
381 class wxConfig : public wxConfigBase {
384 wxConfig(const wxString& appName = wxPyEmptyString,
385 const wxString& vendorName = wxPyEmptyString,
386 const wxString& localFilename = wxPyEmptyString,
387 const wxString& globalFilename = wxPyEmptyString,
388 long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE),
398 "This config class will use a file for storage on all platforms.", "");
400 class wxFileConfig : public wxConfigBase {
403 wxFileConfig(const wxString& appName = wxPyEmptyString,
404 const wxString& vendorName = wxPyEmptyString,
405 const wxString& localFilename = wxPyEmptyString,
406 const wxString& globalFilename = wxPyEmptyString,
407 long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE),
414 //---------------------------------------------------------------------------
416 DocStr(wxConfigPathChanger,
417 "A handy little class which changes current path to the path of given
418 entry and restores it in the destructoir: so if you declare a local
419 variable of this type, you work in the entry directory and the path is
420 automatically restored when the function returns.", "");
422 class wxConfigPathChanger
426 wxConfigPathChanger(const wxConfigBase *config, const wxString& entry),
429 ~wxConfigPathChanger();
432 const wxString& , Name() const,
433 "Get the key name", "");
437 //---------------------------------------------------------------------------
442 wxString , wxExpandEnvVars(const wxString &sz),
443 "Replace environment variables ($SOMETHING) with their values. The
444 format is $VARNAME or ${VARNAME} where VARNAME contains alphanumeric
445 characters and '_' only. '$' must be escaped ('\$') in order to be
446 taken literally.", "");
450 //---------------------------------------------------------------------------