wx.ConfigPathChanger¶
A handy little class which changes the current path in a Config object and restores it in dtor.
Declaring a local variable of this type, it’s possible to work in a specific directory and ensure that the path is automatically restored when the function returns.
For example:
# this function loads some settings from the given wx.Config object
# the path selected inside it is left unchanged
def LoadMySettings(config):
changer = wx.ConfigPathChanger(config, "/Foo/Data/SomeString")
strs = config.Read("SomeString")
if not strs:
wx.LogError("Couldn't read SomeString!")
return False
# NOTE: without wx.ConfigPathChanger it would be easy to forget to
# set the old path back into the wx.Config object before this return!
# do something useful with SomeString...
return True # again: wx.ConfigPathChanger dtor will restore the original wx.Config path
Class Hierarchy¶
Methods Summary¶
Changes the path of the given wx.ConfigBase object so that the key strEntry is accessible (for read or write). |
|
Returns the name of the key which was passed to the constructor. |
|
This method must be called if the original path inside the Config object (i.e. |
|
Class API¶
- class wx.ConfigPathChanger(object)¶
Possible constructors:
ConfigPathChanger(pContainer, strEntry) -> None
A handy little class which changes the current path in a Config object and restores it in dtor.
Methods¶
- __init__(self, pContainer, strEntry)¶
Changes the path of the given wx.ConfigBase object so that the key strEntry is accessible (for read or write).
In other words, the constructor uses
wx.ConfigBase.SetPath
with everything which precedes the last slash of strEntry, so that:wx.ConfigPathChanger(wx.ConfigBase.Get(), "/MyProgram/SomeKeyName")
has the same effect of:
wx.ConfigPathChanger(wx.ConfigBase.Get(), "/MyProgram/")
- Parameters:
pContainer (wx.ConfigBase)
strEntry (string)
- Return type:
None
- Name(self)¶
Returns the name of the key which was passed to the constructor.
The “name” is just anything which follows the last slash of the string given to the constructor.
- Return type:
str
- UpdateIfDeleted(self)¶
This method must be called if the original path inside the Config object (i.e.
the current path at the moment of creation of this wx.ConfigPathChanger object) could have been deleted, thus preventing wx.ConfigPathChanger from restoring the not existing (any more) path.
If the original path doesn’t exist any more, the path will be restored to the deepest still existing component of the old path.
- Return type:
None
- __enter__(self)¶
- __exit__(self, exc_type, exc_val, exc_tb)¶