Exemplo n.º 1
0
def add_action(title, to, funct, checkable=False):
    action = QAction(_(title), mw)
    if checkable:
        action.setCheckable(True)
    action.triggered.connect(funct)
    to.addAction(action)
    return action
def main_setup_menus():  # noqa
    global alreadyrun
    if alreadyrun:
        return
    alreadyrun = True

    view = get_menu(mw, "&View")

    action = QAction(mw)
    action.setText("Card Stats")
    action.setCheckable(True)
    action.setChecked(sidebar_visibility)
    action.setShortcut(QKeySequence("Shift+C"))
    view.addAction(action)
    action.toggled.connect(card_stats)
Exemplo n.º 3
0
def add_menu_item(path, text, func, keys=None, checkable=False, checked=False):
    action = QAction(text, mw)

    if keys:
        action.setShortcut(QKeySequence(keys))

    if checkable:
        action.setCheckable(checkable)
        action.toggled.connect(func)
        if not hasattr(mw, 'action_groups'):
            mw.action_groups = {}
        if path not in mw.action_groups:
            mw.action_groups[path] = QActionGroup(None)
        mw.action_groups[path].addAction(action)
        action.setChecked(checked)
    else:
        action.triggered.connect(func)

    add_menu(path)
    mw.custom_menus[path].addAction(action)
    normalizationDisabled = not normalizationDisabled

    unicodedata.normalize = normalizationActions[normalizationDisabled]

    normalizationAction.setChecked(normalizationDisabled)


# config
def loadConfig():
    global normalizationDisabled

    normalizationDisabled = mw.pm.profile.get("normalizationDisabled", False)

    normalizationAction.setChecked(normalizationDisabled)


def saveConfig():
    mw.pm.profile["normalizationDisabled"] = normalizationDisabled


# create menu item
normalizationAction = QAction("Disable Unicode Normalization")
normalizationAction.setCheckable(True)
normalizationAction.triggered.connect(toggleNormalization)

mw.form.menuTools.addAction(normalizationAction)

# hooks
addHook("profileLoaded", loadConfig)
addHook("unloadProfile", saveConfig)