.. include:: headings.inc .. _ConfigPathChanger: ========================================================================================================================================== |phoenix_title| **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 somes 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| Inheritance Diagram ===================================== Inheritance diagram for class **ConfigPathChanger** .. raw:: html

Inheritance diagram of ConfigPathChanger

| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~ConfigPathChanger.__init__` Changes the path of the given :ref:`ConfigBase` object so that the key `strEntry` is accessible (for read or write). :meth:`~ConfigPathChanger.Name` Returns the name of the key which was passed to the constructor. :meth:`~ConfigPathChanger.UpdateIfDeleted` This method must be called if the original path inside the Config object (i.e. :meth:`~ConfigPathChanger.__enter__` :meth:`~ConfigPathChanger.__exit__` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: ConfigPathChanger(object) A handy little class which changes the current path in a Config object and restores it in dtor. **Possible constructors**:: ConfigPathChanger(pContainer, strEntry) .. method:: __init__(self, pContainer, strEntry) Changes the path of the given :ref:`ConfigBase` object so that the key `strEntry` is accessible (for read or write). In other words, the constructor uses :meth:`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/") :param `pContainer`: :type `pContainer`: ConfigBase :param `strEntry`: :type `strEntry`: string .. method:: 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. :rtype: `string` .. method:: 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 :ref:`ConfigPathChanger` object) could have been deleted, thus preventing :ref:`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. .. method:: __enter__(self) .. method:: __exit__(self, exc_type, exc_val, exc_tb)