0

Event Bad Argument Error, RV Python Package

Hi, I'm working on a Python package for RV, and I used the Simple Package section from the Reference Manual as a template (shown below)

from rv.rvtypes import *
from rv.commands import *
from rv.extra_commands import *
​
class PyMyStuffMode(MinorMode):
​
   def __init__(self):
        MinorMode.__init__(self)
        self.init("py-mystuff-mode",
                  [ ("key-down-->", self.faster, "speed up fps"),
                    ("key-down--<", self.slower, "slow down fps") ],
                  None,
                  [ ("MyStuff", 
                     [ ("Increase FPS", self.faster, "=", None),
                       ("Decrease FPS", self.slower, "-", None)] )] )
​
    def faster(self, event):
        setFPS(fps() * 1.5)
        displayFeedback("%g fps" % fps(), 2.0);
​
    def slower(self, event):
        setFPS(fps() * 1.0/1.5)
        displayFeedback("%g fps" % fps(), 2.0);
​
​
def createMode():
    return PyMyStuffMode()

 

In my callback function I'm trying to access the event information, specifically the name of the menu item that triggered the event. So for example if the slower callback function is triggered by the user selecting the Decrease FPS menuItem, I assume that somewhere in the event parameter I would be able to find  the string "Decrease FPS".

However, I get errors when I'm trying to find this information. I'm thinking it's maybe event.sender() (I'm not actually even sure, so if I'm totally off here, that would be valuable information too!), but when I try to call this function I get the following error: "ERROR: Bad argument", which doesn't make much sense since it doesn't take an argument (as far as I know), and I'm not even trying to provide one. I get this error with some other event functions, like event.contents(). Some other event functions work though, like event.name(), which returns "menu".

Anyone run into this before? I'm not the most experienced person, so maybe it's something really silly. Any help is appreciated!

Thanks,

Ray

 

 

6 comments

  • 0
    Avatar
    Ray K

    For anyone who might end up here:

    I didn't end up getting anything out of the event object. What I was hoping to do was basically equivalent to pass parameters to the menu item callback function. You can do this by wrapping the callback in a function which accepts the parameters. I don't know how good of an idea it is, but anyway it goes something like:

    def self.myTest(self, param):
        def func(event):
            print param
        return func
    

    And then when you're creating menu items:

    myParam = "asdf"
    callback = self.myTest(myParam)
    ("test menu item", callback, "", None)
    

     

    Hope that kinda makes sense.

  • 0
    Avatar
    Ray K

    Heh, that's pretty ugly. Don't see any way to edit, oh well.

  • 0
    Avatar
    Mary Ferrante

    Hi Ray, I am having some problems too starting with Python on RV. Did you manage to solve your problem?

  • 0
    Avatar
    Jim Hourihan

    Hey Guys, sorry we didn't see this question earlier. 

    Ray, the event doesn't have the information you want. If you open the Mu Commmand API Browser (under Help menu) you can scroll down in the leftmost list widget for the Event type and see what methods it has (same in python as they are in mu). Your solution (using a closure) is exactly what you should do. That technique will allow you to wrap up any amount of information into the callback that you want.

    Marianna, what problems are you having?

       -Jim

  • 0
    Avatar
    Mary Ferrante

    Seems like I solved it for the moment, I was having trouble installing my package but seems I figured it out. Thanks a lot for the quick answer!

  • 0
    Avatar
    Andry Jong

    Hi all, I don't know if this is completely related. I want to create a separate timeline that mirrors the current timeline, but per-shot basis (Just like how it is in Revolver). I can get the frame information using rv.commands.frame(), but I can't get it to update every time it changes.

    Any clue will be much appreciated!

    Andry

Please sign in to leave a comment.