def _create_theme_menu(self):
        theme_menu = QMenu(self)
        theme_menu.setTitle('Buttons Theme')
        theme_menu.setTearOffEnabled(True)
        theme_menu.setWindowTitle(TAG)
        theme_actions = QActionGroup(self)
        theme_actions.setExclusive(True)
        # create ordered theme list
        custom_order_theme = sorted(THEMES.iterkeys())
        custom_order_theme.remove('Maya Theme')
        custom_order_theme.insert(0, 'Maya Theme')
        default_item = True
        for theme in custom_order_theme:
            current_theme_action = QAction(theme, theme_actions)
            current_theme_action.setCheckable(True)
            current_theme_action.setChecked(
                MTTSettings.value('theme', 'Maya Theme') == theme)
            current_theme_action.triggered.connect(self.on_change_theme)
            theme_menu.addAction(current_theme_action)

            if default_item:
                theme_menu.addSeparator()
                default_item = False

        return theme_menu
    def _create_theme_menu(self):
        theme_menu = QMenu(self)
        theme_menu.setTitle('Buttons Theme')
        theme_menu.setTearOffEnabled(True)
        theme_menu.setWindowTitle(TAG)
        theme_actions = QActionGroup(self)
        theme_actions.setExclusive(True)
        # create ordered theme list
        custom_order_theme = sorted(THEMES.iterkeys())
        custom_order_theme.remove('Maya Theme')
        custom_order_theme.insert(0, 'Maya Theme')
        default_item = True
        for theme in custom_order_theme:
            current_theme_action = QAction(theme, theme_actions)
            current_theme_action.setCheckable(True)
            current_theme_action.setChecked(
                MTTSettings.value('theme', 'Maya Theme') == theme)
            current_theme_action.triggered.connect(self.on_change_theme)
            theme_menu.addAction(current_theme_action)

            if default_item:
                theme_menu.addSeparator()
                default_item = False

        return theme_menu
示例#3
0
def javaLoadCommand(self, cmdName):
    qDebug("javaLoadCommand(%s)" % qPrintable(cmdName))
    #NOTE: Every QScriptProgram must have a unique function name to call. If every function was called main(), then
    #      the QScriptEngine would only call the last script evaluated (which happens to be main() in another script).
    #      Thus, adding the cmdName before main(), becomes line_main(), circle_main(), etc...
    #      Do not change self code unless you really know what you are doing. I mean it.
    #FIXME/PORT# appDir = QApplication.instance().applicationDirPath()  ##qApp.applicationDirPath()
    appDir = gAppDir
    ##file = QFile(appDir + "/commands/" + cmdName + "/" + cmdName + ".js")
    ##file.open(QIODevice.ReadOnly)
    ##script = str(file.readAll())  #FIXME/PORT#
    ##file.close()
    with open(appDir + "/commands/" + cmdName + "/" + cmdName + ".js") as f:
        script = f.read()

    done = False
    findNextIndex = True
    findFunc = "function"
    funcName = ""
    funcList = []  # QStringList
    index = 0
    funcNameIndex = 0
    while not done:
        if findNextIndex:
            index = script.find(findFunc, index)
            if index == -1:
                done = True
            else:
                index += len(findFunc)
                funcNameIndex = index
                findNextIndex = False
        else:
            ch = script[index]
            if ch == '(':
                funcName = script[funcNameIndex:index].strip()
                funcList.append(funcName)
                funcName = ""
                findNextIndex = True
            else:
                index += 1

    validBeforeChars = (  # QList<QChar>
        '\t', '\n', '\v', '\f', '\r', ' ', ';', '(', ')',
        '{', '}', 'not ', '=', '+', '-', '/', '*', '%',
        '<', '>', '&', '|', '?', ':', '^', '~')

    validAfterChars = ('\t', '\n', '\v', '\f', '\r', ' ', '(')  # QList<QChar>
    for functionName in funcList:
        findFunc = functionName
        funcName = cmdName + "_" + functionName

        found = 0
        done = False
        index = 0
        findNextIndex = True
        while not done:
            if findNextIndex:
                index = script.find(findFunc, index)
                if index == -1:
                    done = True
                else:
                    findNextIndex = False
            else:
                charBefore = script[index - 1]
                if charBefore in validBeforeChars:
                    i = 0
                    while True:
                        charAfter = script[index + i + len(findFunc)]  # QChar
                        if charAfter == '(':
                            found += 1
                            ##script.replace(index, len(findFunc), funcName)
                            #TODO/FIXME/PORT# inmprove this
                            script = script[:index] + funcName + script[index+len(findFunc):]
                            ##script.replace(findFunc, funcName)

                        i += 1

                        if charAfter not in validAfterChars:
                            break

                index += len(findFunc)
                findNextIndex = True

        qDebug("%s found: %d" % (qPrintable(findFunc), found))

    #TODO: low priority caveat: If a function name is within a string, is still replaced.

    script.replace("global = {};", "var " + cmdName + "_global = {};")
    script.replace("global.", cmdName + "_global.")

    self.engine.evaluate(script)

    #TODO/PORT/FIXME#
    settings = QSettings(appDir + "/commands/" + cmdName + "/" + cmdName + ".ini", QSettings.IniFormat)
    menuName = str(settings.value("Menu/Name", "Lost & Found"))  # .toString()
    menuPos = int(settings.value("Menu/Position", 0))  # .toInt()
    toolbarName = str(settings.value("ToolBar/Name", "Lost & Found"))  # .toString()
    toolbarPos = int(settings.value("ToolBar/Position", 0))  # .toInt()
    toolTip = str(settings.value("Tips/ToolTip", ""))  # .toString()
    statusTip = str(settings.value("Tips/StatusTip", ""))  # .toString()
    aliases = settings.value("Prompt/Alias") or []  # .toStringList()

    ACTION = self.createAction(cmdName, toolTip, statusTip, True)

    if toolbarName.upper() != "NONE":
        # If the toolbar doesn't exist, it.
        if toolbarName not in self.toolbarHash:
            tb = QToolBar(toolbarName, self)
            tb.setObjectName("toolbar" + toolbarName)
            tb.topLevelChanged.connect(self.floatingChangedToolBar)
            self.addToolBar(Qt.LeftToolBarArea, tb)
            self.addToolBarBreak(Qt.LeftToolBarArea)
            self.toolbarHash[toolbarName] = tb

        # TODO: order actions position in toolbar based on .ini setting
        self.toolbarHash[toolbarName].addAction(ACTION)

    if menuName.upper() != "NONE":
        # If the menu doesn't exist, it.
        if menuName not in self.menuHash:
            menu = QMenu(menuName, self)
            menu.setTearOffEnabled(True)
            self.menuBar().addMenu(menu)
            self.menuHash[menuName] = menu

        # TODO: order actions position in menu based on .ini setting
        self.menuHash[menuName].addAction(ACTION)

    for alias in aliases:
        self.prompt.addCommand(alias, cmdName)