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
51 class) and you will always use one of its derivations: wx.Config
54 wx.ConfigBase organizes the items in a tree-like structure
55 (modeled after the Unix/Dos filesystem). There are groups
56 (directories) and keys (files). There is always one current
57 group given by the current path. As in the file system case, to
58 specify a key in the config class you must use a path to it.
59 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, integer
63 floating point or boolean, you can not store binary data without first
64 encoding it as a string. For performance reasons items should be kept small,
65 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\n"
91 "returns a 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\n"
102 "create the \"best\" implementation of wx.Config available for the\n"
103 "current platform.");
108 static void , DontCreateOnDemand(),
109 "Should Get() try to create a new log object if there isn't a current one?");
115 virtual void , SetPath(const wxString& path),
116 "Set current path: if the first character is '/', it's the absolute path,\n"
117 "otherwise it's a relative path. '..' is supported. If the strPath\n"
118 "doesn't exist it is created.");
122 virtual const wxString& , GetPath() const,
123 "Retrieve the current path (always as absolute path)");
128 DocAStr(GetFirstGroup,
129 "GetFirstGroup() -> (more, value, index)",
130 "Allows enumerating the subgroups in a config object. Returns\n"
131 "a tuple containing a flag indicating there are more items, the\n"
132 "name of the current item, and an index to pass to GetNextGroup to\n"
133 "fetch the next item.");
134 PyObject* GetFirstGroup() {
139 cont = self->GetFirstGroup(value, index);
140 return __EnumerationHelper(cont, value, index);
145 DocAStr(GetNextGroup,
146 "GetNextGroup(long index) -> (more, value, index)",
147 "Allows enumerating the subgroups in a config object. Returns\n"
148 "a tuple containing a flag indicating there are more items, the\n"
149 "name of the current item, and an index to pass to GetNextGroup to\n"
150 "fetch the next item.");
151 PyObject* GetNextGroup(long index) {
155 cont = self->GetNextGroup(value, index);
156 return __EnumerationHelper(cont, value, index);
160 DocAStr(GetFirstEntry,
161 "GetFirstEntry() -> (more, value, index)",
162 "Allows enumerating the entries in the current group in a config\n"
163 "object. Returns a tuple containing a flag indicating there are\n"
164 "more items, the name of the current item, and an index to pass to\n"
165 "GetNextGroup to fetch the next item.");
166 PyObject* GetFirstEntry() {
171 cont = self->GetFirstEntry(value, index);
172 return __EnumerationHelper(cont, value, index);
176 DocAStr(GetNextEntry,
177 "GetNextEntry(long index) -> (more, value, index)",
178 "Allows enumerating the entries in the current group in a config\n"
179 "object. Returns a tuple containing a flag indicating there are\n"
180 "more items, the name of the current item, and an index to pass to\n"
181 "GetNextGroup to fetch the next item.");
182 PyObject* GetNextEntry(long index) {
186 cont = self->GetNextEntry(value, index);
187 return __EnumerationHelper(cont, value, index);
194 virtual size_t , GetNumberOfEntries(bool recursive = False) const,
195 "Get the number of entries in the current group, with or\n"
196 "without its subgroups.");
199 virtual size_t , GetNumberOfGroups(bool recursive = False) const,
200 "Get the number of subgroups in the current group, with or\n"
201 "without its subgroups.");
206 virtual bool , HasGroup(const wxString& name) const,
207 "Returns True if the group by this name exists");
211 virtual bool , HasEntry(const wxString& name) const,
212 "Returns True if the entry by this name exists");
216 bool , Exists(const wxString& name) const,
217 "Returns True if either a group or an entry with a given name exists");
220 // get the entry type
222 virtual EntryType , GetEntryType(const wxString& name) const,
223 "Get the type of the entry. Returns one of the wx.Config.Type_XXX values.");
228 wxString , Read(const wxString& key, const wxString& defaultVal = wxPyEmptyString),
229 "Returns the value of key if it exists, defaultVal otherwise.");
234 "Returns the value of key if it exists, defaultVal otherwise.");
235 long ReadInt(const wxString& key, long defaultVal = 0) {
237 self->Read(key, &rv, defaultVal);
242 "Returns the value of key if it exists, defaultVal otherwise.");
243 double ReadFloat(const wxString& key, double defaultVal = 0.0) {
245 self->Read(key, &rv, defaultVal);
250 "Returns the value of key if it exists, defaultVal otherwise.");
251 bool ReadBool(const wxString& key, bool defaultVal = False) {
253 self->Read(key, &rv, defaultVal);
259 // write the value (return True on success)
261 bool , Write(const wxString& key, const wxString& value),
262 "write the value (return True on success)");
265 bool, Write(const wxString& key, long value),
266 "write the value (return True on success)",
270 bool, Write(const wxString& key, double value),
271 "write the value (return True on success)",
275 bool, Write(const wxString& key, bool value),
276 "write the value (return True on success)",
281 virtual bool , Flush(bool currentOnly = False),
282 "permanently writes all changes");
286 virtual bool , RenameEntry(const wxString& oldName,
287 const wxString& newName),
288 "Rename an entry. Returns False on failure (probably because the new\n"
289 "name is already taken by an existing entry)");
292 virtual bool , RenameGroup(const wxString& oldName,
293 const wxString& newName),
294 "Rename aa group. Returns False on failure (probably because the new\n"
295 "name is already taken by an existing entry)");
298 // deletes the specified entry and the group it belongs to if
299 // it was the last key in it and the second parameter is True
301 virtual bool , DeleteEntry(const wxString& key,
302 bool deleteGroupIfEmpty = True),
303 "Deletes the specified entry and the group it belongs to if\n"
304 "it was the last key in it and the second parameter is True");
308 virtual bool , DeleteGroup(const wxString& key),
309 "Delete the group (with all subgroups)");
313 virtual bool , DeleteAll(),
314 "Delete the whole underlying object (disk file, registry key, ...)\n"
315 "primarly intended for use by desinstallation routine.");
320 void , SetExpandEnvVars(bool doIt = True),
321 "We can automatically expand environment variables in the config entries\n"
322 "(this option is on by default, you can turn it on/off at any time)");
325 bool , IsExpandingEnvVars() const,
326 "Are we currently expanding environment variables?");
330 void , SetRecordDefaults(bool doIt = True),
331 "Set whether the config objec should record default values.");
334 bool , IsRecordingDefaults() const,
335 "Are we currently recording default values?");
339 wxString , ExpandEnvVars(const wxString& str) const,
340 "Expand any environment variables in str and return the result");
344 wxString , GetAppName() const,
348 wxString , GetVendorName() const,
353 void , SetAppName(const wxString& appName),
357 void , SetVendorName(const wxString& vendorName),
362 void , SetStyle(long style),
366 long , GetStyle() const,
372 //---------------------------------------------------------------------------
375 "This ConfigBase-derived class will use the registry on Windows,
376 and will be a wx.FileConfig on other platforms.");
378 class wxConfig : public wxConfigBase {
381 wxConfig(const wxString& appName = wxPyEmptyString,
382 const wxString& vendorName = wxPyEmptyString,
383 const wxString& localFilename = wxPyEmptyString,
384 const wxString& globalFilename = wxPyEmptyString,
395 "This config class will use a file for storage on all platforms.");
397 class wxFileConfig : public wxConfigBase {
400 wxFileConfig(const wxString& appName = wxPyEmptyString,
401 const wxString& vendorName = wxPyEmptyString,
402 const wxString& localFilename = wxPyEmptyString,
403 const wxString& globalFilename = wxPyEmptyString,
411 //---------------------------------------------------------------------------
413 DocStr(wxConfigPathChanger,
414 "A handy little class which changes current path to the path of
415 given entry and restores it in the destructoir: so if you declare
416 a local variable of this type, you work in the entry directory
417 and the path is automatically restored when the function returns.");
419 class wxConfigPathChanger
423 wxConfigPathChanger(const wxConfigBase *config, const wxString& entry),
426 ~wxConfigPathChanger();
429 const wxString& , Name() const,
434 //---------------------------------------------------------------------------
439 wxString , wxExpandEnvVars(const wxString &sz),
440 "Replace environment variables ($SOMETHING) with their values. The\n"
441 "format is $VARNAME or ${VARNAME} where VARNAME contains\n"
442 "alphanumeric characters and '_' only. '$' must be escaped ('\$')\n"
443 "in order to be taken literally.");
447 //---------------------------------------------------------------------------