.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2020 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.ConfigPathChanger:

==========================================================================================================================================
|phoenix_title|  **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 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| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>ConfigPathChanger</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.ConfigPathChanger_inheritance.png" alt="Inheritance diagram of ConfigPathChanger" usemap="#dummy" class="inheritance"/></center>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.ConfigPathChanger.html" title="wx.ConfigPathChanger" alt="" coords="5,5,173,35"/> </map> 
   </p>
   </div>

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.ConfigPathChanger.__init__`                                           Changes the path of the given :ref:`wx.ConfigBase`  object so that the key `strEntry`  is accessible (for read or write).
:meth:`~wx.ConfigPathChanger.Name`                                               Returns the name of the key which was passed to the constructor.
:meth:`~wx.ConfigPathChanger.UpdateIfDeleted`                                    This method must be called if the original path inside the Config object (i.e.
:meth:`~wx.ConfigPathChanger.__enter__`                                          
:meth:`~wx.ConfigPathChanger.__exit__`                                           
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: wx.ConfigPathChanger(object)

   **Possible constructors**::

       ConfigPathChanger(pContainer, strEntry)
       
   
   A handy little class which changes the current path in a Config
   object and restores it in dtor.



   .. method:: __init__(self, pContainer, strEntry)

      Changes the path of the given :ref:`wx.ConfigBase`  object so that the key `strEntry`  is accessible (for read or write).                  

      In other words, the constructor uses :meth:`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/")

                 


      :param `pContainer`: 
      :type `pContainer`: wx.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:`wx.ConfigPathChanger`  object) could have been deleted, thus preventing :ref:`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.                   





   .. method:: __enter__(self)




   .. method:: __exit__(self, exc_type, exc_val, exc_tb)



