Weird python issue in custom rv package

Hello,
I have created a package that applies a custom crop. It provides a new menu with one sub-menu. The crop does work (though I’d be more than happy to learn if there is a more performance better way of doing it).

So the issue I am having is that I want to track the state of the menu. I have created a variable called self._active in the init function but it’s value does not carry over into the crop function. It’s set to False in init but if I print out the value after init it’s set to True. Now maybe I am simply not seeing a mistake on my part which would not surprise me at all. I’ll also point out that once in the crop function self._active does remember it’s value, it’s just in the init that it does not stay correct. It’s set to False in init but immediately upon printing the value in the crop method it’s True. Again, maybe I am just not seeing something simple.

This is my first RV package and I am still trying to learn the what the nodes do and how to interact with them.

A second question I have is can anyone point out how I can have a checkmark next to the menu item when it’s enabled?

Thanks for any tips. As you can see I am not a python pro but overall the menu item is working.

from rv import rvtypes, commands, extra_commands
import os, re, urlparse, platform


def groupMemberOfType(node, memberType):
    for n in commands.nodesInGroup(node):
        if commands.nodeType(n) == memberType:
            return n
    return None


class PyMyStuffMode(rvtypes.MinorMode):


    def uhd_crop(self, event):
        print("working crop menu selected")
        #print("active: {}".format(os.environ['RV_WW_CROP_ENABLED']))
        print("in uhd_crop. crop active: {}",self._active)

        fmt_node = None
        fsource_node = None
        node_list = commands.nodes()
        for item in node_list:
            #print item
            if commands.nodeType(item) == 'RVSourceGroup':
                a = commands.nodesInGroup(item)

                for i in a:
                    #print commands.nodeType(i)
                    if commands.nodeType(i) == 'RVFormat':
                        fmt_node = i

                    if commands.nodeType(i) == 'RVFileSource':
                        fsource_node = i


                if fmt_node != None and fsource_node != None:
                    # commands.soureMediaInfo takes entire RVFileSource Node as it's input arg
                    sourceInfo = commands.sourceMediaInfo(fsource_node)
                    width = sourceInfo['width']
                    height = sourceInfo['height']
                    image_size = "{}x{}".format(width, height)
                    print(image_size)




                    #if os.environ['RV_WW_CROP_ENABLED'] == 'False':  # no crop applied
                    if self._active == False:  # no crop applied
                        print("in if")
                        #os.environ['RV_WW_CROP_ENABLED'] = 'True'
                        if image_size == '6720x4480':
                            # FULLFRAME TO UHD
                            crop_x_max_prop =  fmt_node + '.crop.xmax'
                            commands.setIntProperty(crop_x_max_prop, [5279], False)
                            crop_x_min_prop =  fmt_node + '.crop.xmin'
                            commands.setIntProperty(crop_x_min_prop, [1440], False)
                            crop_y_max_prop =  fmt_node + '.crop.ymax'
                            commands.setIntProperty(crop_y_max_prop, [3319], False)
                            crop_y_min_prop =  fmt_node + '.crop.ymin'
                            commands.setIntProperty(crop_y_min_prop, [1160], False)
                            commands.setIntProperty( fmt_node + '.crop.active', [1], False)
                            self._active = True
                            extra_commands.displayFeedback("UHD Crop ENABLED", 4.0)

                            # WORKING TO UHD
                        elif image_size == '4518x3012':
                            crop_x_max_prop =  fmt_node + '.crop.xmax'
                            commands.setIntProperty(crop_x_max_prop, [4179], False)
                            crop_x_min_prop =  fmt_node + '.crop.xmin'
                            commands.setIntProperty(crop_x_min_prop, [340], False)
                            crop_y_max_prop =  fmt_node + '.crop.ymax'
                            commands.setIntProperty(crop_y_max_prop, [2586], False)
                            crop_y_min_prop =  fmt_node + '.crop.ymin'
                            commands.setIntProperty(crop_y_min_prop, [427], False)
                            commands.setIntProperty( fmt_node + '.crop.active', [1], False)
                            self._active = True
                            extra_commands.displayFeedback("UHD Crop ENABLED", 4.0)
                        print(self._active)




                    else:
                        print("in else")
                        commands.setIntProperty( fmt_node + '.crop.active', [0], False)
                        extra_commands.displayFeedback("UHD Crop DISABLED", 4.0)
                        #os.environ['RV_WW_CROP_ENABLED'] = 'False'
                        self._active = False
                        print(self._active)





    def __init__(self):
        self._active = False
        rvtypes.MinorMode.__init__(self)
        #os.environ['RV_WW_CROP_ENABLED'] = 'False'
        self.init(
            "rv_plugin_crop_test-mode",
            [

            ],
            None,
            [
                (
                    "TestMenu",
                    [

                        ("UHD_Crop", self.uhd_crop, "", None),

                    ],
                )
            ],

        )




def createMode():
    return PyMyStuffMode()

Hello,

_active is a property of the parent MinorMode class, that gets set when the mode is activated (during the init in this case).
Try using a different name for your variable, that should do the trick :wink:

For the menu to reflect the current state, you’ll need to add a callback as the last item in your menu definition, that would return rv.commands.CheckedMenuState or rv.commands.UncheckedMenuState based on your “active” variable.

I highly recommend checking the plugins from the RV install for examples, I know I find myself referring to them much more than to the reference manual !

Ah. That would do it. I changed self._active to something else and it does now work as expected. Thank you so much.!

-cablet

For others wanting to set the state of the menu here is what I did to get it work.

The function:

    def menuSelectState(self):
        if self._menu_state:
            return commands.CheckedMenuState
        return commands.UncheckedMenuState

The menu declaration in init


("UHD_Crop", self.uhd_crop, "", self.menuSelectState),
1 Like