setCompositeMode in python

Hi all,

currently I am trying to set the composite mode (Tools > Sequence to Replace ) via python.
The Mu Command API Browser pointed me to rvui, but it seems like there is no rvui.setCompositeMode() or rvui.isCompositeMode() for python... 

Am I missing something here, or is there only the "Mu way" to solve this?



  • 0
    Seth Rosenthal

    Hello Carl,

    Thanks for the question. I'm not quite sure exactly what you are trying to do. So I'm going to give an overly general answer that I think will cover your question.

    First, the idea of a 'composite mode' is actually a bit misleading. RV views like stack and layout have a composite type setting (e.g. over or add). This is a setting on the view itself. It is not a mode of RV. So if you have multiple stacks in RV, they can each be set to a different composite type.

    Second, the menu items in RV like Tools->Over actually do a few actions all at once.

    Looking at rvui.mu is actually a good way of figuring out how to accomplish various operations in RV (even if you are then going to implement those operations in Python). rvui.mu is part of the RV distribution. You can open it up and look through the code. In this case, you will find that setCompositeMode is just a utility function that looks like this:

    \: setCompositeMode ((void;Event); string type)
    \: (void; Event ev)
    setStringProperty("#RVStack.composite.type", string[]{type});

    So you can see that all that this function does is simply setting a string property on the current stacks. The values for the string are:

    • over
    • add
    • difference
    • replace
    • topmost

     If you have any experience setting properties, you may already understand the '#RVStack' notation in the property name. But in case you are not familiar with it (and for anyone else reading this answer) you may want to look at the RV user's manual section on addressing properties. The short story is that the '#nodeType' syntax will select all of the active nodes of that type and set their corresponding property. 

    However, you seem to be asking how to accomplish the same thing as the menu items like Tools->Over. This requires another step. In a case like this, where you want to mimic behavior from the menus, it can be useful to search through rvui.mu looking for the menu text. E.g. in this case you can search RVUI for "Tools" which help you find the section that defines the Tools menu items. That looks something like this:


    {"Tools", Menu {
        {"Default Views", nil, nil, inactiveState},
        {"   Sequence", setCompModeAndView(nil,"defaultSequence"), nil, viewNodeState("defaultSequence")},
        {"   Replace", setCompModeAndView("replace","defaultStack"), nil, isStackAndCompMode("replace")},
        {"   Over", setCompModeAndView("over","defaultStack"), nil, isStackAndCompMode("over")},
        {"   Add", setCompModeAndView("add","defaultStack"), nil, isStackAndCompMode("add")},

     You can see that the Tools Over Menu item calls a function called setCompModeAndView with two arguments, one for the mode and one for the view to set.

    That function looks like this: 

    \: setCompModeAndView ((void;Event); string ctype, string view)
        \: (void; Event ev)
            if (ctype neq nil) setStringProperty("defaultStack_stack.composite.type", string[]{ctype});
            bool playing = isPlaying();
            if (playing) stop();
            if (playing) play();
            //displayFeedback("Composite Mode: %s" % type);

     So you can see (hopefully) that to duplicate the behavior of the Tools->Over menu item, all you have to do is call:

    setStringProperty("defaultStack_stack.composite.type", string[]{"over"});

     or the equivalent in python, which would be:

    setStringProperty("defaultStack_stack.composite.type", ["over"])

     Hopefully that answers your question.

    Also, in the case where you find functions in existing Mu code that you would like to use directly, you can call them using the python->Mu bridge. That's documented in the RV reference manual section about calling Mu from Python



  • 0
    Carl Schröter

    Hi Seth,

    That's an excellent answer and exactly what I was looking for.
    Consider my question more than answered.

    Thanks a lot.