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 :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 :-)
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?
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.