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 wxPyBlock_t blocked = wxPyBeginBlockThreads();
28 PyObject* ret = PyTuple_New(3);
30 PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(flag));
31 PyTuple_SET_ITEM(ret, 1, wx2PyString(str));
32 PyTuple_SET_ITEM(ret, 2, PyInt_FromLong(index));
34 wxPyEndBlockThreads(blocked);
42 wxCONFIG_USE_LOCAL_FILE,
43 wxCONFIG_USE_GLOBAL_FILE,
44 wxCONFIG_USE_RELATIVE_PATH,
45 wxCONFIG_USE_NO_ESCAPE_CHARACTERS
51 "wx.ConfigBase class defines the basic interface of all config
52 classes. It can not be used by itself (it is an abstract base class)
53 and you will always use one of its derivations: wx.Config or
56 wx.ConfigBase organizes the items in a tree-like structure, modeled
57 after the Unix/Dos filesystem. There are groups that act like
58 directories and entries, key/value pairs that act like files. There
59 is always one current group given by the current path. As in the file
60 system case, to specify a key in the config class you must use a path
61 to it. Config classes also support the notion of the current group,
62 which makes it possible to use relative paths.
64 Keys are pairs \"key_name = value\" where value may be of string,
65 integer floating point or boolean, you can not store binary data
66 without first encoding it as a string. For performance reasons items
67 should be kept small, no more than a couple kilobytes.
73 // wxConfigBase(const wxString& appName = wxPyEmptyString, **** An ABC
74 // const wxString& vendorName = wxPyEmptyString,
75 // const wxString& localFilename = wxPyEmptyString,
76 // const wxString& globalFilename = wxPyEmptyString,
85 Type_Integer, // use Read(long *)
86 Type_Float // use Read(double *)
90 %disownarg( wxConfigBase *config );
92 static wxConfigBase *, Set(wxConfigBase *config),
93 "Sets the global config object (the one returned by Get) and returns a
94 reference to the previous global config object.", "");
95 %cleardisown( wxConfigBase *config );
98 static wxConfigBase *, Get(bool createOnDemand = true),
99 "Returns the current global config object, creating one if neccessary.", "");
103 static wxConfigBase *, Create(),
104 "Create and return a new global config object. This function will
105 create the \"best\" implementation of wx.Config available for the
106 current platform.", "");
111 static void , DontCreateOnDemand(),
112 "Should Get() try to create a new log object if there isn't a current
119 virtual void , SetPath(const wxString& path),
120 "Set current path: if the first character is '/', it's the absolute
121 path, otherwise it's a relative path. '..' is supported. If the
122 strPath doesn't exist it is created.", "");
126 virtual const wxString& , GetPath() const,
127 "Retrieve the current path (always as absolute path)", "");
132 DocAStr(GetFirstGroup,
133 "GetFirstGroup() -> (more, value, index)",
134 "Allows enumerating the subgroups in a config object. Returns a tuple
135 containing a flag indicating there are more items, the name of the
136 current item, and an index to pass to GetNextGroup to fetch the next
138 PyObject* GetFirstGroup() {
143 cont = self->GetFirstGroup(value, index);
144 return __EnumerationHelper(cont, value, index);
149 DocAStr(GetNextGroup,
150 "GetNextGroup(long index) -> (more, value, index)",
151 "Allows enumerating the subgroups in a config object. Returns a tuple
152 containing a flag indicating there are more items, the name of the
153 current item, and an index to pass to GetNextGroup to fetch the next
155 PyObject* GetNextGroup(long index) {
159 cont = self->GetNextGroup(value, index);
160 return __EnumerationHelper(cont, value, index);
164 DocAStr(GetFirstEntry,
165 "GetFirstEntry() -> (more, value, index)",
166 "Allows enumerating the entries in the current group in a config
167 object. Returns a tuple containing a flag indicating there are more
168 items, the name of the current item, and an index to pass to
169 GetNextGroup to fetch the next item.", "");
170 PyObject* GetFirstEntry() {
175 cont = self->GetFirstEntry(value, index);
176 return __EnumerationHelper(cont, value, index);
180 DocAStr(GetNextEntry,
181 "GetNextEntry(long index) -> (more, value, index)",
182 "Allows enumerating the entries in the current group in a config
183 object. Returns a tuple containing a flag indicating there are more
184 items, the name of the current item, and an index to pass to
185 GetNextGroup to fetch the next item.", "");
186 PyObject* GetNextEntry(long index) {
190 cont = self->GetNextEntry(value, index);
191 return __EnumerationHelper(cont, value, index);
198 virtual size_t , GetNumberOfEntries(bool recursive = false) const,
199 "Get the number of entries in the current group, with or without its
203 virtual size_t , GetNumberOfGroups(bool recursive = false) const,
204 "Get the number of subgroups in the current group, with or without its
210 virtual bool , HasGroup(const wxString& name) const,
211 "Returns True if the group by this name exists", "");
215 virtual bool , HasEntry(const wxString& name) const,
216 "Returns True if the entry by this name exists", "");
220 bool , Exists(const wxString& name) const,
221 "Returns True if either a group or an entry with a given name exists", "");
224 // get the entry type
226 virtual EntryType , GetEntryType(const wxString& name) const,
227 "Get the type of the entry. Returns one of the wx.Config.Type_XXX values.", "");
232 wxString , Read(const wxString& key, const wxString& defaultVal = wxPyEmptyString),
233 "Returns the value of key if it exists, defaultVal otherwise.", "");
238 "Returns the value of key if it exists, defaultVal otherwise.", "");
239 long ReadInt(const wxString& key, long defaultVal = 0) {
241 self->Read(key, &rv, defaultVal);
246 "Returns the value of key if it exists, defaultVal otherwise.", "");
247 double ReadFloat(const wxString& key, double defaultVal = 0.0) {
249 self->Read(key, &rv, defaultVal);
254 "Returns the value of key if it exists, defaultVal otherwise.", "");
255 bool ReadBool(const wxString& key, bool defaultVal = false) {
257 self->Read(key, &rv, defaultVal);
263 // write the value (return True on success)
265 bool , Write(const wxString& key, const wxString& value),
266 "write the value (return True on success)", "");
269 bool, Write(const wxString& key, long value),
270 "write the value (return True on success)", "",
274 bool, Write(const wxString& key, double value),
275 "write the value (return True on success)", "",
279 bool, Write(const wxString& key, bool value),
280 "write the value (return True on success)", "",
285 virtual bool , Flush(bool currentOnly = false),
286 "permanently writes all changes", "");
290 virtual bool , RenameEntry(const wxString& oldName,
291 const wxString& newName),
292 "Rename an entry. Returns False on failure (probably because the new
293 name is already taken by an existing entry)", "");
296 virtual bool , RenameGroup(const wxString& oldName,
297 const wxString& newName),
298 "Rename a group. Returns False on failure (probably because the new
299 name is already taken by an existing entry)", "");
302 // deletes the specified entry and the group it belongs to if
303 // it was the last key in it and the second parameter is True
305 virtual bool , DeleteEntry(const wxString& key,
306 bool deleteGroupIfEmpty = true),
307 "Deletes the specified entry and the group it belongs to if it was the
308 last key in it and the second parameter is True", "");
312 virtual bool , DeleteGroup(const wxString& key),
313 "Delete the group (with all subgroups)", "");
317 virtual bool , DeleteAll(),
318 "Delete the whole underlying object (disk file, registry key, ...)
319 primarly intended for use by deinstallation routine.", "");
324 void , SetExpandEnvVars(bool doIt = true),
325 "We can automatically expand environment variables in the config
326 entries this option is on by default, you can turn it on/off at any
330 bool , IsExpandingEnvVars() const,
331 "Are we currently expanding environment variables?", "");
335 void , SetRecordDefaults(bool doIt = true),
336 "Set whether the config objec should record default values.", "");
339 bool , IsRecordingDefaults() const,
340 "Are we currently recording default values?", "");
344 wxString , ExpandEnvVars(const wxString& str) const,
345 "Expand any environment variables in str and return the result", "");
349 wxString , GetAppName() const,
353 wxString , GetVendorName() const,
358 void , SetAppName(const wxString& appName),
362 void , SetVendorName(const wxString& vendorName),
367 void , SetStyle(long style),
371 long , GetStyle() const,
374 %property(AppName, GetAppName, SetAppName, doc="See `GetAppName` and `SetAppName`");
375 %property(EntryType, GetEntryType, doc="See `GetEntryType`");
376 %property(FirstEntry, GetFirstEntry, doc="See `GetFirstEntry`");
377 %property(FirstGroup, GetFirstGroup, doc="See `GetFirstGroup`");
378 %property(NextEntry, GetNextEntry, doc="See `GetNextEntry`");
379 %property(NextGroup, GetNextGroup, doc="See `GetNextGroup`");
380 %property(NumberOfEntries, GetNumberOfEntries, doc="See `GetNumberOfEntries`");
381 %property(NumberOfGroups, GetNumberOfGroups, doc="See `GetNumberOfGroups`");
382 %property(Path, GetPath, SetPath, doc="See `GetPath` and `SetPath`");
383 %property(Style, GetStyle, SetStyle, doc="See `GetStyle` and `SetStyle`");
384 %property(VendorName, GetVendorName, SetVendorName, doc="See `GetVendorName` and `SetVendorName`");
388 //---------------------------------------------------------------------------
391 "This ConfigBase-derived class will use the registry on Windows,
392 and will be a wx.FileConfig on other platforms.", "");
394 class wxConfig : public wxConfigBase {
397 wxConfig(const wxString& appName = wxPyEmptyString,
398 const wxString& vendorName = wxPyEmptyString,
399 const wxString& localFilename = wxPyEmptyString,
400 const wxString& globalFilename = wxPyEmptyString,
401 long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE),
411 "This config class will use a file for storage on all platforms.", "");
413 class wxFileConfig : public wxConfigBase {
416 wxFileConfig(const wxString& appName = wxPyEmptyString,
417 const wxString& vendorName = wxPyEmptyString,
418 const wxString& localFilename = wxPyEmptyString,
419 const wxString& globalFilename = wxPyEmptyString,
420 long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE),
424 static wxString GetGlobalFileName(const wxString& szFile);
425 static wxString GetLocalFileName(const wxString& szFile, int style = 0);
430 //---------------------------------------------------------------------------
432 DocStr(wxConfigPathChanger,
433 "A handy little class which changes current path to the path of given
434 entry and restores it in the destructoir: so if you declare a local
435 variable of this type, you work in the entry directory and the path is
436 automatically restored when the function returns.", "");
438 class wxConfigPathChanger
442 wxConfigPathChanger(const wxConfigBase *config, const wxString& entry),
445 ~wxConfigPathChanger();
448 const wxString& , Name() const,
449 "Get the key name", "");
453 //---------------------------------------------------------------------------
458 wxString , wxExpandEnvVars(const wxString &sz),
459 "Replace environment variables ($SOMETHING) with their values. The
460 format is $VARNAME or ${VARNAME} where VARNAME contains alphanumeric
461 characters and '_' only. '$' must be escaped ('\$') in order to be
462 taken literally.", "");
466 //---------------------------------------------------------------------------