Menu

Store Python Context and Restore

Help
2017-05-29
2017-05-29
  • Joerg Kreuzberger

    Hi!

    I want to implement an undo mechanism in python with PythonQt. for this i have to "store" the Python State in my C++ Application, execute new python code and want to "restore" old values".
    E.g.

    PythonQtObjectPtr createUniqueModule()
    executeScript("i=3;i++")
    store() (saves the value of i with 4)
    executeScript("i='helloworld'") // i is now differnt type
    restore()
    executeScript("print(i)") // should give now 4 back

    So how is this implemented?
    Deep copy of the PyObject* in the PythonQtObjectPtr could not help cause there are uncopyable constructs (modules, functions, etc). But i can store locals and globals via PythonQt as QVariants and apply them later?

    Any help welcome :-)

     
  • Florian Link

    Florian Link - 2017-05-29

    No idea... I have never seen Python being used like that, since many side-effects are not easily undoable... But if you only store/restore values that can be deep copied, shouldn't that be enough for a start?

     
  • Joerg Kreuzberger

    Yes that will be sufficient.
    I am currently storing list of variables found in local and global context via pythonQt but will do this properly in core python context. found several source code for this, but my intention was to clarify if in pyhtonqt something similar is available.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.