469,332 Members | 6,969 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Undo class

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

--
Mickel Grönroos, application specialist, linguistics, Research support,CSC
PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
CSC is the Finnish IT center for science, www.csc.fi

Jul 18 '05 #1
5 3556
Mickel Grönroos wrote:
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.
--
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #2
In article <bo**********@news-reader3.wanadoo.fr>,
Eric Brunel <er*********@pragmadev.N0SP4M.com> wrote:
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!


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

--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
Jul 18 '05 #3
David Eppstein <ep******@ics.uci.edu> writes:
In article <bo**********@news-reader3.wanadoo.fr>,
Eric Brunel <er*********@pragmadev.N0SP4M.com> wrote:
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
[...] 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).

[...]

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
Jul 18 '05 #4
On Mon, 10 Nov 2003, Eric Brunel wrote:
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

--
Mickel Grönroos, application specialist, linguistics, Research support,CSC
PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
CSC is the Finnish IT center for science, www.csc.fi

Jul 18 '05 #5
I have seen a 'transaction manager' for 'undo/redo' mechanism in SMW
http://www.abo.fi/~iporres/html/download.html

Look in smw/metamodel/TransactionManager.py.

Regards
Fabrice Clement

p.s.: sorry for my bad english !
Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by black | last post: by
2 posts views Thread by Tony Nelson | last post: by
reply views Thread by Wiktor Zychla | last post: by
2 posts views Thread by Christian H | last post: by
10 posts views Thread by John Richardson | last post: by
7 posts views Thread by call_me_anything | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.