Undo class

  • Thread starter =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=
  • Start date
?

=?ISO-8859-1?Q?Mickel_Gr=F6nroos?=

Hello everybody

I'm developing a tool in Tkinter and would like to add Undo and Redo
commands to my Edit menu. Does somebody know if anybody has implemented
standard Undo/Redo as a Python module? I could not find any info with
Google on the matter.

Cheers,

Mickel Grönroos
 
E

Eric Brunel

Mickel said:
Hello everybody

I'm developing a tool in Tkinter and would like to add Undo and Redo
commands to my Edit menu. Does somebody know if anybody has implemented
standard Undo/Redo as a Python module? I could not find any info with
Google on the matter.

On what king of widget? If it's a Text, you can use the native tk undo/redo
features: create the Text widget with the option undo set to 1, then use the
methods edit_undo() and edit_redo(). These are tk 8.4 features, so it may not
work for Python versions older than 2.3 (it doesn't work with 2.1; don't know
about 2.2)

For other widgets, I doubt there can be a generic mechanism to manage the
undo/redo functions for you: after all, only you can tell what actions should be
able to be undone or redone. But I'd be really happy if someone can prove me wrong!

HTH anyway.
 
D

David Eppstein

I'm developing a tool in Tkinter and would like to add Undo and Redo
commands to my Edit menu. Does somebody know if anybody has implemented
standard Undo/Redo as a Python module? I could not find any info with
Google on the matter.

On what king of widget? If it's a Text, you can use the native tk undo/redo
features: create the Text widget with the option undo set to 1, then use the
methods edit_undo() and edit_redo(). These are tk 8.4 features, so it may not
work for Python versions older than 2.3 (it doesn't work with 2.1; don't know
about 2.2)

For other widgets, I doubt there can be a generic mechanism to manage the
undo/redo functions for you: after all, only you can tell what actions should
be
able to be undone or redone. But I'd be really happy if someone can prove me
wrong![/QUOTE]

The "only you can tell" argument is not convincing -- if you can tell,
you can tell it to the undo manager.

Take a look at the Cocoa UndoManager functionality.
Basically, while you're handle a change to a UI object, you call
U = undoManager.prepareWithInvocationTarget(self)
U.methods(arguments...)
where self.methods(arguments...) would be the calls you'd do
to reverse the change, and it saves the method names and arguments for
you. Later, when an undo is requested, it performs the calls you
prototyped for it. Very convenient, shouldn't be too hard to program in
Python directly (in fact it is available in Python on OS X now, via
PyObj).
 
J

John J. Lee

[...]
Take a look at the Cocoa UndoManager functionality.
Basically, while you're handle a change to a UI object, you call
U = undoManager.prepareWithInvocationTarget(self)
U.methods(arguments...)
where self.methods(arguments...) would be the calls you'd do
to reverse the change, and it saves the method names and arguments for
you. Later, when an undo is requested, it performs the calls you
prototyped for it. Very convenient, shouldn't be too hard to program in
Python directly (in fact it is available in Python on OS X now, via
PyObj).[/QUOTE]
[...]

Another Undo API that does things in just the same way (pure Python,
with docs!):

http://sketch.sourceforge.net/Doc/devguide-19.html


While you're at it, you could do a lot worse than pinching his GUI
component publisher / subscriber code.


John
 
?

=?ISO-8859-1?Q?Mickel_Gr=F6nroos?=

For other widgets, I doubt there can be a generic mechanism to manage
the undo/redo functions for you: after all, only you can tell what
actions should be able to be undone or redone. But I'd be really happy
if someone can prove me wrong!

I need to undo some complex actions involving several steps, not only
entries in Text widgets. I'll take a look at UndoManager and Sketch as
suggested by David Eppstein and John Lee. Basically, I would like to have
a stack of undo commands that I can push to and pop from. I reckon this is
what UndoManager and Sketch does. I'll have a look. Thanks for the
pointers!

/Mickel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top