1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2018 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>
</div>
<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,168,35"/> </map>
</p>
|
|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)
|