Tuesday, March 12, 2013

Menus and menu items


class AR_OptionsWindow(object):

    def __init__(self):
        self.window = 'ar_optionsWindow';
        self.title = 'Meng\'s Window';
        self.size = (546, 350);
        self.supportsToolAction = False;
    def commonMenu(self):
        self.editMenu = cmds.menu(label='Edit');
        self.editMenuSave = cmds.menuItem(
            label='Save Settings'                                    
        );
        self.editMenuReset = cmds.menuItem(
            label='Reset Settings'
        );
        self.editMenuDiv = cmds.menuItem(d=True); //create a divider
        self.editMenuRadio = cmds.radioMenuItemCollection();  //call the radioMenuItemCollection command to initiate a sequence of items in a radio button group.
        self.editMenuTool = cmds.menuItem(
            label='As Tool',
            radioButton=True,
            enable=self.supportsToolAction
        );
        self.editMenuAction = cmds.menuItem(
            label='As Action',
            radioButton=True,
            enable=self.supportsToolAction
        );
        self.helpMenu = cmds.menu(label='Help');
        self.helpMenuItem = cmds.menuItem(
            label='Help on %s'%self.title
        );
    def create(self):
        if cmds.window(self.window, exists=True):
            cmds.deleteUI(self.window, window=True);
        self.window = cmds.window(
            self.window,
            title=self.title,
            widthHeight=self.size,
            menuBar=True
        );
        self.commonMenu();
        cmds.showWindow();
testWindow = AR_OptionsWindow();
testWindow.create();
PS: Although this menu looks pretty good by Autodesk's standards, none of its menu items actually do anything yet. At this point, I should look into adding some commands. I will do it tomorrow following the book.

No comments:

Post a Comment