How to save (and restore) the values of the graphical elements of the wxWidgets in Python?
I want some more friendly way, maybe using a for
to scrape all the elements and save the current value in a txt
when I close the window and restore when I load the app. I do not want to typing 2 line of code (save and restore) to each new element that I add.
@Igor, thanks by the tip of use config_base
. I created this code based on:
configHandle = wx.Config(CONFIG_FILE)
# Sweep all elements in `self()` to find the grafical ones
# instance of the wxPython and salve the specific configuration.
for wxElement_name, wxElement_handle in self.__dict__.items():
# Each wxPython object have a specific parameter value
# to be saved and restored in the software initialization.
if isinstance(wxElement_handle, wx._core.TextCtrl):
configHandle.Write(wxElement_name, wxElement_handle.GetValue() )
elif isinstance(wxElement_handle, wx._core.CheckBox):
configHandle.Write(wxElement_name, ('True' if wxElement_handle.GetValue() else 'False') )
elif isinstance(wxElement_handle, wx._core.SpinCtrl):
configHandle.Write(wxElement_name, str(wxElement_handle.GetValue()) )
.
.
.
To restore I use the reverse logic of this code.