Old 09-12-2012, 05:50 AM   #1
Veto
Human being with feelings
 
Join Date: Aug 2010
Posts: 140
Default -----

-----

Last edited by Veto; 05-28-2018 at 08:46 AM.
Veto is offline   Reply With Quote
Old 09-21-2012, 05:58 PM   #2
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Quote:
Originally Posted by Veto View Post
If somebody should be interested, of course "except" should be "finally", thats it.
And ReaScript error messages will show too.
Code:
finally:
    gofer_gets(what_Veto_says)
thanks for the link to Recovering and continuing with finally in the other thread . That will prove helpful.

Undo Block is still often not behaving as I expect, even if I think I do it right.
gofer is offline   Reply With Quote
Old 09-25-2012, 02:10 AM   #3
gofer
-blänk-
 
gofer's Avatar
 
Join Date: Jun 2008
Posts: 11,359
Default

Oops, haven't got around even trying. Yes, it seems to work perfect .
gofer is offline   Reply With Quote
Old 09-25-2012, 01:51 PM   #4
fingers
Human being with feelings
 
fingers's Avatar
 
Join Date: Dec 2009
Location: Wellington, NZ
Posts: 300
Default

This is perfect for a python decorator. Here is an example:

Code:
from reaper_python import *

class Undoable(object):
    ALL = 0xFFFFFFFF
    TRACKCFG = 1 
    FX = 2
    ITEMS = 4
    MISCCFG = 8

    def __init__(self, msg, undo_flags = ALL):
        self._msg = msg
        self._undo_flags = undo_flags

    def __call__(self, f):
        def wrapped():
            RPR_Undo_BeginBlock()
            RPR_PreventUIRefresh(1)
            try:
                f()
            except Exception, e:
                RPR_MB(str(e), "Error", 0)
            RPR_Undo_EndBlock(self._msg, self._undo_flags)
            RPR_PreventUIRefresh(-1)
            RPR_UpdateArrange()
            RPR_UpdateTimeline()
            RPR_TrackList_AdjustWindows(False)
        return wrapped

@Undoable("Insert new track")
def my_script():
    RPR_InsertTrackAtIndex(0, False)

my_script()
The code in my_script is not important, it just inserts a new track. But all the undo and gui refresh calls are done inside the Undoable class which you decorate the function my_script with. You specify your undo message as the first argument to the Undoable decorator.

You can set a different undo flag like so:

Code:
@Undoable("Insert new track", Undoable.TRACKCFG)
def my_script():
    RPR_InsertTrackAtIndex(0, False)
fingers is offline   Reply With Quote
Old 01-13-2013, 05:45 AM   #5
timlloyd
Human being with feelings
 
Join Date: Mar 2010
Posts: 4,713
Default

Fwiw, line 20 needs to be changed to "except Exception as e:" for Python 3.
timlloyd is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.