def on_show_prompt_instance_delay_menu(self):
        prompt_instance_state = cmds.optionVar(query='MTT_prompt_instance_state')

        if prompt_instance_state == PROMPT_INSTANCE_WAIT:
            elapsed_time = time() - cmds.optionVar(query='MTT_prompt_instance_suspend')
            if elapsed_time > PROMPT_INSTANCE_WAIT_DURATION:
                prompt_instance_state = PROMPT_INSTANCE_ASK
                cmds.optionVar(iv=['MTT_prompt_instance_state', prompt_instance_state])
            else:
                mtt_log('Remaining %.2fs' % (PROMPT_INSTANCE_WAIT_DURATION - elapsed_time))
        elif prompt_instance_state == PROMPT_INSTANCE_SESSION:
            if 'mtt_prompt_session' not in __main__.__dict__:
                prompt_instance_state = PROMPT_INSTANCE_ASK
                cmds.optionVar(iv=['MTT_prompt_instance_state', prompt_instance_state])

        self.instance_menu.clear()

        prompt_delay = QActionGroup(self)
        prompt_delay.setExclusive(True)
        for i in range(len(PROMPT_INSTANCE_STATE.keys())):
            current_delay_action = QAction(PROMPT_INSTANCE_STATE[i], prompt_delay)
            current_delay_action.setCheckable(True)
            current_delay_action.setChecked(prompt_instance_state == i)
            current_delay_action.triggered.connect(
                partial(self.view.on_choose_instance_delay, i, prompt=i != 0))
            self.instance_menu.addAction(current_delay_action)
    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 on_show_prompt_instance_delay_menu(self):
        prompt_instance_state = cmds.optionVar(
            query='MTT_prompt_instance_state')

        if prompt_instance_state == PROMPT_INSTANCE_WAIT:
            elapsed_time = time() - cmds.optionVar(
                query='MTT_prompt_instance_suspend')
            if elapsed_time > PROMPT_INSTANCE_WAIT_DURATION:
                prompt_instance_state = PROMPT_INSTANCE_ASK
                cmds.optionVar(
                    iv=['MTT_prompt_instance_state', prompt_instance_state])
            else:
                mtt_log('Remaining %.2fs' %
                        (PROMPT_INSTANCE_WAIT_DURATION - elapsed_time))
        elif prompt_instance_state == PROMPT_INSTANCE_SESSION:
            if 'mtt_prompt_session' not in __main__.__dict__:
                prompt_instance_state = PROMPT_INSTANCE_ASK
                cmds.optionVar(
                    iv=['MTT_prompt_instance_state', prompt_instance_state])

        self.instance_menu.clear()

        prompt_delay = QActionGroup(self)
        prompt_delay.setExclusive(True)
        for i in range(len(PROMPT_INSTANCE_STATE.keys())):
            current_delay_action = QAction(PROMPT_INSTANCE_STATE[i],
                                           prompt_delay)
            current_delay_action.setCheckable(True)
            current_delay_action.setChecked(prompt_instance_state == i)
            current_delay_action.triggered.connect(
                partial(self.view.on_choose_instance_delay, i, prompt=i != 0))
            self.instance_menu.addAction(current_delay_action)
    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
Exemplo n.º 5
0
class PluginBaseInstruments(IPlugin):
    def __init__(self, data_singleton):
        self.data_singleton = data_singleton
        self.mw = self.data_singleton.mainWindow
        self.menu_instruments = None
        self.base_inst_tool_bar = None
        self.base_inst_action_group = None
        self.instruments = []

    def name(self):
        return 'Base Instruments'

    def version(self):
        return '0.0.1'

    def description(self):
        return 'Base Instruments'

    def initialize(self):
        self.instruments.append(EraserInstrument(self.data_singleton))
        self.instruments.append(PencilInstrument(self.data_singleton))
        self.instruments.append(LineInstrument(self.data_singleton))
        self.instruments.append(RectangleInstrument(self.data_singleton))
        self.instruments.append(FillInstrument(self.data_singleton))

        self.base_inst_tool_bar = self.mw.addToolBar(self.description())
        self.base_inst_tool_bar.setObjectName(self.name())
        self.base_inst_tool_bar.setToolButtonStyle(Qt.ToolButtonIconOnly)

        self.base_inst_action_group = QActionGroup(self.base_inst_tool_bar)
        self.base_inst_action_group.setExclusive(True)
        self.base_inst_action_group.triggered.connect(lambda x: self.triggered_action_instrument(x))

        self.menu_instruments = self.mw.ui.menuInstruments

        for inst in self.instruments:
            act = self.base_inst_tool_bar.addAction(inst.name())
            # TODO: objectName вида <class 'baseinstruments.rectangleinstrument.RectangleInstrument'>
            # кажется неудобным, может другое значение составлять
            act.setObjectName(str(type(inst)))
            act.setToolTip(inst.description())
            if inst.icon():
                act.setIcon(inst.icon())
            act.setCheckable(True)

            self.base_inst_action_group.addAction(act)
            self.menu_instruments.addActions(self.base_inst_action_group.actions())
            self.data_singleton.action_inst_dict[act] = inst

    def destroy(self):
        self.instruments.clear()

        self.mw.removeToolBar(self.base_inst_tool_bar)

        # base_inst_tool_bar удалит и base_inst_action_group, и действия
        self.base_inst_tool_bar.deleteLater()
        self.base_inst_tool_bar = None
        self.base_inst_action_group = None

        self.data_singleton.action_inst_dict.clear()
        self.data_singleton.current_instrument = None

    def triggered_action_instrument(self, action):
        instrument = self.data_singleton.action_inst_dict[action]
        self.data_singleton.current_instrument = instrument
Exemplo n.º 6
0
class Actions:

    def __init__(self, window, fontSizeSpinBox=None):
        self.window = window
        self.state = window.state
        self.fontSizeSpinBox = fontSizeSpinBox
        if self.fontSizeSpinBox is not None:
            self.fontSizeSpinBox.valueChanged.connect(self.setFontSize)
        self.boldAction = Lib.createAction(
            window, ":/format-text-bold.svg", "&Bold", self.toggleBold,
            QKeySequence.Bold, """<p><b>Format→Bold</b> ({})</p>
<p>Toggle bold on or off.</p>""".format(QKeySequence(
                                        QKeySequence.Bold).toString()))
        self.italicAction = Lib.createAction(
            window, ":/format-text-italic.svg", "&Italic",
            self.toggleItalic, QKeySequence.Italic, """\
<p><b>Format→Italic</b> ({})</p>
<p>Toggle italic on or off.</p>""".format(QKeySequence(
                                          QKeySequence.Italic).toString()))
        self.underlineAction = Lib.createAction(
            window, ":/format-text-underline.svg", "&Underline",
            self.toggleUnderline, QKeySequence.Underline, """\
<p><b>Format→Underline</b> ({})</p>
<p>Toggle underline on or off.</p>""".format(
                QKeySequence(QKeySequence.Underline).toString()))
        self.noSuperSubscriptAction = Lib.createAction(
            window, ":/nosupersubscript.svg",
            "&No Superscript or Subscript", self.noSuperSubscript,
            tooltip="""\
<p><b>Format→No superscript or subscript</b></p>
<p>Clear superscript or subscript and return to normal.</p>""")
        self.superscriptAction = Lib.createAction(
            window, ":/superscript.svg", "Su&perscript",
            self.setSuperscript, tooltip="""<p><b>Format→Superscript</b></p>
<p>Set superscript on.</p>""")
        self.subscriptAction = Lib.createAction(
            window, ":/subscript.svg", "Subs&cript", self.setSubscript,
            tooltip="""<p><b>Format→Subscript</b></p>
<p>Set subscript on.</p>""")
        self.superSubGroup = QActionGroup(self.window)
        self.superSubGroup.setExclusive(True)
        for action in (self.superscriptAction, self.subscriptAction,
                       self.noSuperSubscriptAction):
            self.superSubGroup.addAction(action)
        self.stdFontAction = Lib.createAction(
            window, ":/font-std.svg", "&Standard Font", self.setStdFont,
            tooltip="""<p><b>Format→Standard Font</b></p>
<p>Set the standard font.</p>""")
        self.altFontAction = Lib.createAction(
            window, ":/font-alt.svg", "&Alternate Font", self.setAltFont,
            tooltip="""<p><b>Format→Alternate Font</b></p>
<p>Set the alternate font.</p>""")
        self.monoFontAction = Lib.createAction(
            window, ":/font-mono.svg", "&Monospace Font", self.setMonoFont,
            tooltip="""<p><b>Format→Monospace Font</b></p>
<p>Set the monospace font.</p>""")
        self.fontGroup = QActionGroup(self.window)
        self.fontGroup.setExclusive(True)
        for action in (self.stdFontAction, self.altFontAction,
                       self.monoFontAction):
            self.fontGroup.addAction(action)
        for action in (self.boldAction, self.italicAction,
                       self.underlineAction, self.superscriptAction,
                       self.subscriptAction, self.noSuperSubscriptAction,
                       self.stdFontAction, self.altFontAction,
                       self.monoFontAction):
            action.setCheckable(True)
        self.noSuperSubscriptAction.setChecked(True)
        self.stdFontAction.setChecked(True)


    def forMenu(self):
        return (self.boldAction, self.italicAction,
                self.underlineAction, None, self.noSuperSubscriptAction,
                self.superscriptAction, self.subscriptAction, None,
                self.stdFontAction, self.altFontAction,
                self.monoFontAction)


    def forToolbar(self):
        return (self.boldAction, self.italicAction,
                self.underlineAction, None, self.noSuperSubscriptAction,
                self.superscriptAction, self.subscriptAction, None,
                self.stdFontAction, self.altFontAction,
                self.monoFontAction)


    def updateEnabled(self):
        enable = False
        for editor in self.state.editors:
            if editor.hasFocus():
                enable = hasattr(editor, "toggleBold")
                break
        for action in (self.boldAction, self.italicAction,
                       self.underlineAction,
                       self.noSuperSubscriptAction,
                       self.superscriptAction, self.subscriptAction,
                       self.stdFontAction, self.altFontAction,
                       self.monoFontAction):
            action.setEnabled(enable)
        if self.fontSizeSpinBox is not None:
            self.fontSizeSpinBox.setEnabled(enable)
        return enable


    def update(self, bold, italic, underline, superscript, subscript,
               family, size=None):
        enable = self.updateEnabled()
        if enable:
            self.boldAction.setChecked(bold)
            self.italicAction.setChecked(italic)
            self.underlineAction.setChecked(underline)
            self.superscriptAction.setChecked(superscript)
            self.subscriptAction.setChecked(subscript)
            self.noSuperSubscriptAction.setChecked(
                not superscript and not subscript)
            family = family.casefold()
            if family == self.state.altFontFamily.casefold():
                self.altFontAction.setChecked(True)
            elif family == self.state.monoFontFamily.casefold():
                self.monoFontAction.setChecked(True)
            else:
                self.stdFontAction.setChecked(True)
            if size is not None and self.fontSizeSpinBox is not None:
                self.fontSizeSpinBox.setValue(size)


    def toggleBold(self):
        for editor in self.state.editors:
            if editor.hasFocus():
                if hasattr(editor, "toggleBold"):
                    editor.toggleBold()
                break


    def toggleItalic(self):
        for editor in self.state.editors:
            if editor.hasFocus():
                if hasattr(editor, "toggleItalic"):
                    editor.toggleItalic()
                break


    def toggleUnderline(self):
        for editor in self.state.editors:
            if editor.hasFocus():
                if hasattr(editor, "toggleUnderline"):
                    editor.toggleUnderline()
                break


    def setSuperscript(self):
        for editor in self.state.editors:
            if editor.hasFocus():
                if hasattr(editor, "setSuperscript"):
                    editor.setSuperscript()
                break


    def setSubscript(self):
        for editor in self.state.editors:
            if editor.hasFocus():
                if hasattr(editor, "setSubscript"):
                    editor.setSubscript()
                break


    def noSuperSubscript(self):
        for editor in self.state.editors:
            if editor.hasFocus():
                if hasattr(editor, "noSuperSubscript"):
                    editor.noSuperSubscript()
                break


    def setStdFont(self):
        for editor in self.state.editors:
            if editor.hasFocus():
                if hasattr(editor, "setStdFont"):
                    editor.setStdFont()
                break


    def setAltFont(self):
        for editor in self.state.editors:
            if editor.hasFocus():
                if hasattr(editor, "setAltFont"):
                    editor.setAltFont()
                break


    def setMonoFont(self):
        for editor in self.state.editors:
            if editor.hasFocus():
                if hasattr(editor, "setMonoFont"):
                    editor.setMonoFont()
                break


    def setFontSize(self, size):
        if self.fontSizeSpinBox is None:
            return
        for editor in self.state.editors:
            if editor.hasFocus():
                if hasattr(editor, "setFontSize"):
                    editor.setFontSize(size)
                break