]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_config.i
Added wx.combo.BitmapComboBox
[wxWidgets.git] / wxPython / src / _config.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _config.i
3// Purpose: SWIG interface for wxConfig, wxFileConfig, etc.
4//
5// Author: Robin Dunn
6//
7// Created: 25-Nov-1998
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17%newgroup
18
19%{
20%}
21
22//---------------------------------------------------------------------------
23
24
25%{
26 static PyObject* __EnumerationHelper(bool flag, wxString& str, long index) {
e6f85a85 27 wxPyBlock_t blocked = wxPyBeginBlockThreads();
d14a1e28
RD
28 PyObject* ret = PyTuple_New(3);
29 if (ret) {
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));
33 }
e6f85a85 34 wxPyEndBlockThreads(blocked);
d14a1e28
RD
35 return ret;
36 }
37%}
38
39
40enum
41{
42 wxCONFIG_USE_LOCAL_FILE,
43 wxCONFIG_USE_GLOBAL_FILE,
44 wxCONFIG_USE_RELATIVE_PATH,
45 wxCONFIG_USE_NO_ESCAPE_CHARACTERS
46};
47
48
49
6ad421ae
RD
50DocStr(wxConfigBase,
51"wx.ConfigBase class defines the basic interface of all config
d07d2bc9
RD
52classes. It can not be used by itself (it is an abstract base class)
53and you will always use one of its derivations: wx.Config or
54wx.FileConfig.
55
56wx.ConfigBase organizes the items in a tree-like structure, modeled
57after the Unix/Dos filesystem. There are groups that act like
58directories and entries, key/value pairs that act like files. There
59is always one current group given by the current path. As in the file
60system case, to specify a key in the config class you must use a path
61to it. Config classes also support the notion of the current group,
62which makes it possible to use relative paths.
11f0bb69
RD
63
64Keys are pairs \"key_name = value\" where value may be of string,
65integer floating point or boolean, you can not store binary data
d07d2bc9
RD
66without first encoding it as a string. For performance reasons items
67should be kept small, no more than a couple kilobytes.
68", "");
6ad421ae
RD
69
70
d14a1e28
RD
71class wxConfigBase {
72public:
73// wxConfigBase(const wxString& appName = wxPyEmptyString, **** An ABC
74// const wxString& vendorName = wxPyEmptyString,
75// const wxString& localFilename = wxPyEmptyString,
76// const wxString& globalFilename = wxPyEmptyString,
77// long style = 0);
78 ~wxConfigBase();
79
80 enum EntryType
81 {
82 Type_Unknown,
83 Type_String,
84 Type_Boolean,
85 Type_Integer, // use Read(long *)
86 Type_Float // use Read(double *)
87 };
88
89
214c4fbe 90 %disownarg( wxConfigBase *config );
6ad421ae
RD
91 DocDeclStr(
92 static wxConfigBase *, Set(wxConfigBase *config),
d07d2bc9
RD
93 "Sets the global config object (the one returned by Get) and returns a
94reference to the previous global config object.", "");
214c4fbe 95 %cleardisown( wxConfigBase *config );
d14a1e28 96
6ad421ae 97 DocDeclStr(
a72f4631 98 static wxConfigBase *, Get(bool createOnDemand = true),
d07d2bc9 99 "Returns the current global config object, creating one if neccessary.", "");
6ad421ae 100
d14a1e28 101
6ad421ae
RD
102 DocDeclStr(
103 static wxConfigBase *, Create(),
d07d2bc9
RD
104 "Create and return a new global config object. This function will
105create the \"best\" implementation of wx.Config available for the
106current platform.", "");
6ad421ae 107
d14a1e28 108
6ad421ae
RD
109
110 DocDeclStr(
111 static void , DontCreateOnDemand(),
d07d2bc9
RD
112 "Should Get() try to create a new log object if there isn't a current
113one?", "");
6ad421ae 114
d14a1e28 115
d14a1e28 116
d14a1e28 117
6ad421ae
RD
118 DocDeclStr(
119 virtual void , SetPath(const wxString& path),
d07d2bc9
RD
120 "Set current path: if the first character is '/', it's the absolute
121path, otherwise it's a relative path. '..' is supported. If the
122strPath doesn't exist it is created.", "");
6ad421ae 123
d14a1e28 124
6ad421ae
RD
125 DocDeclStr(
126 virtual const wxString& , GetPath() const,
d07d2bc9 127 "Retrieve the current path (always as absolute path)", "");
6ad421ae 128
d14a1e28
RD
129
130
d14a1e28 131 %extend {
6ad421ae
RD
132 DocAStr(GetFirstGroup,
133 "GetFirstGroup() -> (more, value, index)",
d07d2bc9
RD
134 "Allows enumerating the subgroups in a config object. Returns a tuple
135containing a flag indicating there are more items, the name of the
136current item, and an index to pass to GetNextGroup to fetch the next
137item.", "");
d14a1e28
RD
138 PyObject* GetFirstGroup() {
139 bool cont;
140 long index = 0;
141 wxString value;
142
143 cont = self->GetFirstGroup(value, index);
144 return __EnumerationHelper(cont, value, index);
145 }
6ad421ae
RD
146
147
148
149 DocAStr(GetNextGroup,
150 "GetNextGroup(long index) -> (more, value, index)",
d07d2bc9
RD
151 "Allows enumerating the subgroups in a config object. Returns a tuple
152containing a flag indicating there are more items, the name of the
153current item, and an index to pass to GetNextGroup to fetch the next
154item.", "");
d14a1e28
RD
155 PyObject* GetNextGroup(long index) {
156 bool cont;
157 wxString value;
158
159 cont = self->GetNextGroup(value, index);
160 return __EnumerationHelper(cont, value, index);
161 }
162
6ad421ae
RD
163
164 DocAStr(GetFirstEntry,
165 "GetFirstEntry() -> (more, value, index)",
d07d2bc9
RD
166 "Allows enumerating the entries in the current group in a config
167object. Returns a tuple containing a flag indicating there are more
168items, the name of the current item, and an index to pass to
169GetNextGroup to fetch the next item.", "");
d14a1e28
RD
170 PyObject* GetFirstEntry() {
171 bool cont;
172 long index = 0;
173 wxString value;
174
175 cont = self->GetFirstEntry(value, index);
176 return __EnumerationHelper(cont, value, index);
177 }
6ad421ae
RD
178
179
180 DocAStr(GetNextEntry,
181 "GetNextEntry(long index) -> (more, value, index)",
d07d2bc9
RD
182 "Allows enumerating the entries in the current group in a config
183object. Returns a tuple containing a flag indicating there are more
184items, the name of the current item, and an index to pass to
185GetNextGroup to fetch the next item.", "");
d14a1e28
RD
186 PyObject* GetNextEntry(long index) {
187 bool cont;
188 wxString value;
189
190 cont = self->GetNextEntry(value, index);
191 return __EnumerationHelper(cont, value, index);
192 }
193 }
194
195
196
6ad421ae 197 DocDeclStr(
a72f4631 198 virtual size_t , GetNumberOfEntries(bool recursive = false) const,
d07d2bc9
RD
199 "Get the number of entries in the current group, with or without its
200subgroups.", "");
6ad421ae
RD
201
202 DocDeclStr(
a72f4631 203 virtual size_t , GetNumberOfGroups(bool recursive = false) const,
d07d2bc9
RD
204 "Get the number of subgroups in the current group, with or without its
205subgroups.", "");
6ad421ae 206
d14a1e28 207
6ad421ae
RD
208
209 DocDeclStr(
210 virtual bool , HasGroup(const wxString& name) const,
d07d2bc9 211 "Returns True if the group by this name exists", "");
6ad421ae 212
d14a1e28 213
6ad421ae
RD
214 DocDeclStr(
215 virtual bool , HasEntry(const wxString& name) const,
d07d2bc9 216 "Returns True if the entry by this name exists", "");
6ad421ae 217
d14a1e28 218
6ad421ae
RD
219 DocDeclStr(
220 bool , Exists(const wxString& name) const,
d07d2bc9 221 "Returns True if either a group or an entry with a given name exists", "");
6ad421ae 222
d14a1e28
RD
223
224 // get the entry type
6ad421ae
RD
225 DocDeclStr(
226 virtual EntryType , GetEntryType(const wxString& name) const,
d07d2bc9 227 "Get the type of the entry. Returns one of the wx.Config.Type_XXX values.", "");
6ad421ae 228
d14a1e28
RD
229
230
6ad421ae
RD
231 DocDeclStr(
232 wxString , Read(const wxString& key, const wxString& defaultVal = wxPyEmptyString),
d07d2bc9 233 "Returns the value of key if it exists, defaultVal otherwise.", "");
6ad421ae 234
d14a1e28
RD
235
236 %extend {
6ad421ae 237 DocStr(ReadInt,
d07d2bc9 238 "Returns the value of key if it exists, defaultVal otherwise.", "");
d14a1e28
RD
239 long ReadInt(const wxString& key, long defaultVal = 0) {
240 long rv;
241 self->Read(key, &rv, defaultVal);
242 return rv;
243 }
6ad421ae
RD
244
245 DocStr(ReadFloat,
d07d2bc9 246 "Returns the value of key if it exists, defaultVal otherwise.", "");
d14a1e28
RD
247 double ReadFloat(const wxString& key, double defaultVal = 0.0) {
248 double rv;
249 self->Read(key, &rv, defaultVal);
250 return rv;
251 }
6ad421ae
RD
252
253 DocStr(ReadBool,
d07d2bc9 254 "Returns the value of key if it exists, defaultVal otherwise.", "");
a72f4631 255 bool ReadBool(const wxString& key, bool defaultVal = false) {
d14a1e28
RD
256 bool rv;
257 self->Read(key, &rv, defaultVal);
258 return rv;
259 }
260 }
261
262
dd9f7fea 263 // write the value (return True on success)
6ad421ae
RD
264 DocDeclStr(
265 bool , Write(const wxString& key, const wxString& value),
d07d2bc9 266 "write the value (return True on success)", "");
6ad421ae
RD
267
268 DocDeclStrName(
269 bool, Write(const wxString& key, long value),
d07d2bc9 270 "write the value (return True on success)", "",
6ad421ae
RD
271 WriteInt);
272
273 DocDeclStrName(
274 bool, Write(const wxString& key, double value),
d07d2bc9 275 "write the value (return True on success)", "",
6ad421ae
RD
276 WriteFloat);
277
278 DocDeclStrName(
279 bool, Write(const wxString& key, bool value),
d07d2bc9 280 "write the value (return True on success)", "",
6ad421ae
RD
281 WriteBool);
282
283
284 DocDeclStr(
a72f4631 285 virtual bool , Flush(bool currentOnly = false),
d07d2bc9 286 "permanently writes all changes", "");
6ad421ae
RD
287
288
289 DocDeclStr(
290 virtual bool , RenameEntry(const wxString& oldName,
291 const wxString& newName),
d07d2bc9
RD
292 "Rename an entry. Returns False on failure (probably because the new
293name is already taken by an existing entry)", "");
6ad421ae
RD
294
295 DocDeclStr(
296 virtual bool , RenameGroup(const wxString& oldName,
297 const wxString& newName),
d07d2bc9
RD
298 "Rename a group. Returns False on failure (probably because the new
299name is already taken by an existing entry)", "");
6ad421ae 300
d14a1e28
RD
301
302 // deletes the specified entry and the group it belongs to if
dd9f7fea 303 // it was the last key in it and the second parameter is True
6ad421ae
RD
304 DocDeclStr(
305 virtual bool , DeleteEntry(const wxString& key,
a72f4631 306 bool deleteGroupIfEmpty = true),
d07d2bc9
RD
307 "Deletes the specified entry and the group it belongs to if it was the
308last key in it and the second parameter is True", "");
6ad421ae
RD
309
310
311 DocDeclStr(
312 virtual bool , DeleteGroup(const wxString& key),
d07d2bc9 313 "Delete the group (with all subgroups)", "");
6ad421ae
RD
314
315
316 DocDeclStr(
317 virtual bool , DeleteAll(),
d07d2bc9
RD
318 "Delete the whole underlying object (disk file, registry key, ...)
319primarly intended for use by deinstallation routine.", "");
6ad421ae
RD
320
321
322
323 DocDeclStr(
a72f4631 324 void , SetExpandEnvVars(bool doIt = true),
d07d2bc9
RD
325 "We can automatically expand environment variables in the config
326entries this option is on by default, you can turn it on/off at any
327time)", "");
6ad421ae
RD
328
329 DocDeclStr(
330 bool , IsExpandingEnvVars() const,
d07d2bc9 331 "Are we currently expanding environment variables?", "");
6ad421ae
RD
332
333
334 DocDeclStr(
a72f4631 335 void , SetRecordDefaults(bool doIt = true),
d07d2bc9 336 "Set whether the config objec should record default values.", "");
6ad421ae
RD
337
338 DocDeclStr(
339 bool , IsRecordingDefaults() const,
d07d2bc9 340 "Are we currently recording default values?", "");
6ad421ae
RD
341
342
343 DocDeclStr(
344 wxString , ExpandEnvVars(const wxString& str) const,
d07d2bc9 345 "Expand any environment variables in str and return the result", "");
6ad421ae
RD
346
347
348 DocDeclStr(
349 wxString , GetAppName() const,
d07d2bc9 350 "", "");
6ad421ae
RD
351
352 DocDeclStr(
353 wxString , GetVendorName() const,
d07d2bc9 354 "", "");
6ad421ae
RD
355
356
357 DocDeclStr(
358 void , SetAppName(const wxString& appName),
d07d2bc9 359 "", "");
6ad421ae
RD
360
361 DocDeclStr(
362 void , SetVendorName(const wxString& vendorName),
d07d2bc9 363 "", "");
6ad421ae
RD
364
365
366 DocDeclStr(
367 void , SetStyle(long style),
d07d2bc9 368 "", "");
6ad421ae
RD
369
370 DocDeclStr(
371 long , GetStyle() const,
d07d2bc9 372 "", "");
6ad421ae 373
0eae5d09
RD
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`");
6ad421ae 385};
d14a1e28 386
d14a1e28 387
6ad421ae 388//---------------------------------------------------------------------------
d14a1e28 389
6ad421ae
RD
390DocStr(wxConfig,
391"This ConfigBase-derived class will use the registry on Windows,
d07d2bc9 392and will be a wx.FileConfig on other platforms.", "");
d14a1e28 393
6ad421ae
RD
394class wxConfig : public wxConfigBase {
395public:
396 DocCtorStr(
397 wxConfig(const wxString& appName = wxPyEmptyString,
398 const wxString& vendorName = wxPyEmptyString,
399 const wxString& localFilename = wxPyEmptyString,
400 const wxString& globalFilename = wxPyEmptyString,
d43699ef 401 long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE),
d07d2bc9 402 "", "");
6ad421ae
RD
403
404 ~wxConfig();
405};
d14a1e28 406
d14a1e28 407
d14a1e28 408
d14a1e28 409
6ad421ae 410DocStr(wxFileConfig,
d07d2bc9 411 "This config class will use a file for storage on all platforms.", "");
d14a1e28 412
6ad421ae
RD
413class wxFileConfig : public wxConfigBase {
414public:
415 DocCtorStr(
416 wxFileConfig(const wxString& appName = wxPyEmptyString,
417 const wxString& vendorName = wxPyEmptyString,
418 const wxString& localFilename = wxPyEmptyString,
419 const wxString& globalFilename = wxPyEmptyString,
77c7f5c9 420 long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE),
d07d2bc9 421 "", "");
6ad421ae
RD
422
423 ~wxFileConfig();
d14a1e28
RD
424};
425
426
427//---------------------------------------------------------------------------
428
6ad421ae 429DocStr(wxConfigPathChanger,
d07d2bc9
RD
430"A handy little class which changes current path to the path of given
431entry and restores it in the destructoir: so if you declare a local
432variable of this type, you work in the entry directory and the path is
433automatically restored when the function returns.", "");
6ad421ae 434
d14a1e28
RD
435class wxConfigPathChanger
436{
437public:
6ad421ae
RD
438 DocCtorStr(
439 wxConfigPathChanger(const wxConfigBase *config, const wxString& entry),
d07d2bc9 440 "", "");
6ad421ae
RD
441
442 ~wxConfigPathChanger();
443
444 DocDeclStr(
445 const wxString& , Name() const,
d07d2bc9 446 "Get the key name", "");
d14a1e28
RD
447};
448
449
450//---------------------------------------------------------------------------
451
d14a1e28 452
d14a1e28 453
6ad421ae
RD
454DocDeclStr(
455 wxString , wxExpandEnvVars(const wxString &sz),
d07d2bc9
RD
456 "Replace environment variables ($SOMETHING) with their values. The
457format is $VARNAME or ${VARNAME} where VARNAME contains alphanumeric
458characters and '_' only. '$' must be escaped ('\$') in order to be
459taken literally.", "");
d14a1e28 460
d14a1e28
RD
461
462
463//---------------------------------------------------------------------------