首页 > 解决方案 > How do I use PM_PERSIST_CONTROL_VALUE?

问题描述

I am writing a program in Python and am busy implementing PersistenceManager for my program. One of the main features of the interface is a wx.treectrl for which I would like to save the state.

I have got things to the point that the main frame's size and position are saved/restored and I also have the expansion of tree items implemented. I cannot get my head around how to implement PM_PERSISTENT_CONTROL_VALUE, which seems what I need in order to restore the selected item on the tree.

See: https://wxpython.org/Phoenix/docs/html/wx.lib.agw.persist.persistencemanager.PersistenceManager.html#wx.lib.agw.persist.persistencemanager.PersistenceManager.SaveValue

Here is the code that I have at the end of init of my main frame:

self.SetName('MyApp')
self.document_tree.SetName('DocumentTree')
_configFile = os.path.join(os.path.expanduser("~"), "Documents", "MyApp.pm")
self._persistMgr = pm.PersistenceManager.Get()
self._persistMgr.SetPersistenceFile(_configFile)
self._persistMgr.RegisterAndRestoreAll(self)
self._persistMgr.Save(self)

I have tried a couple of things, but cannot seem to get the "document_tree" control to highlight the value that was highlighted when the program was closed.

Thank you in advance for your suggestions.

Marc.

标签: wxpythonpersistence

解决方案


好的,这是我必须添加到我的代码中的内容:

self._persistMgr.SetManagerStyle(pm.PM_DEFAULT_STYLE|pm.PM_SAVE_RESTORE_TREE_LIST_SELECTIONS)

我把上面的直接放在下面

self._persistMgr = pm.PersistenceManager.Get()

...现在它可以工作了。

马克。


推荐阅读