472,121 Members | 1,604 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

undo and redo ?

I'm coding with Tkinter and i wonder whether we could get current OS' clipboard available, and event more, anyone can inspires me how we can achieve undo and redo function ?

thanx~
---------------------------------
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
Jul 18 '05 #1
1 2347
> I'm coding with Tkinter and i wonder whether we could get current OS'
clipboard available, and event more, anyone can inspires me how we can
achieve undo and redo function ?


When working with a MVC-approach, the actions you the user can invoke on the
model could be created as objects that know how to undo/invert their
effects. Then you store a list of these actions and performing undo takes
the last action and apply its inverted action to your model. Right from my
head:

class InsertAction:
def __init__(_, index, needle):
_.index = index
_.needle = needle

def do(_, haystack):
haystack[index:index] = _.needle

def undo(_, haystack):
del haystack[_.index : _.index + len(_.needle)]
Hope this gives you an idea. You can also have to types of actions -
primitive and complex. Performing undo will then undo all primitve actions
until the action queue is empty or a complex actions is reached. This
allows e.g. in a text-editor to perform undo subsequently inserted
characters at once.

HTH,

Diez
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jay | last post: by
reply views Thread by John Benson | last post: by
4 posts views Thread by thanigai | last post: by
11 posts views Thread by Mad Joe | last post: by
3 posts views Thread by Teis Draiby | last post: by
1 post views Thread by Alan | last post: by
2 posts views Thread by Christian H | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.