2017-12-25 6 views
0

wxWidgetsのグラフィカル要素の値をPythonで保存(および復元)する方法は? 私はウィンドウを閉じてアプリケーションをロードするときに復元するときに、forを使用して、すべての要素を削り取り、現在の値をtxtに保存するという、よりフレンドリーな方法が必要です。私が追加するそれぞれの新しい要素に2行のコード(保存と復元)を入力する必要はありません。wxWidgets Pythonはチェックボックスと他の要素の値をテキストに保存します

+0

{wx} pythonのどのバージョンをお使いですか?どのOS /ツールキットですか? – Igor

+0

wxWidets = 4.0.0a3 gtk2(phoenix)、Python 3 in Ubuntu 16.04 – hildogjr

+0

参考までにhttp://docs.wxwidgets.org/trunk/classwx_config_base.htmlを参照してください。 – Igor

答えて

0

@Igor、ご利用のヒントconfig_baseありがとうございます。

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())) 
    . 
    . 
    . 

復元するには、このコードの逆のロジックを使用します。

関連する問題