Skip to content

menus

Full documentation pages are generated for docstring reference only and may contain symbols imported from other modules. Imported symbols are not distinguished from locally defined symbols and will appear in any module that they are imported into. For better information on where symbols should be imported from, review the sourcecode on the github.

FoSpy.ui.app.menus

MENU_BUILDERS module-attribute

MENU_BUILDERS = {}

add_menu

add_menu(win, menu_bar, label, specs, parent=None)
Source code in FoSpy/ui/app/menus.py
def add_menu(win, menu_bar, label, specs:dict|tuple[tuple], parent=None):
    label_txt = "&"+label.capitalize()
    if parent is None:
        menu = menu_bar.addMenu(label_txt)
        win.menus[label] = menu
        def add_action(action, *_, m=menu):
            return m.addAction(action)
    else:
        menu = parent.addMenu(label_txt)

        exclusive = isinstance(specs, tuple)

        if exclusive:
            group = QActionGroup(win)
            group.setExclusive(True)

            def add_action(action, i, *_, g=group, m=menu):
                g.addAction(action)
                if i == 0:
                    action.setChecked(True)
                return m.addAction(action)
        else:
            def add_action(action, *_, m=menu):
                return m.addAction(action)

    if isinstance(specs, dict):
        specs = specs.items()

    for i, (name, spec) in enumerate(specs):
        if isinstance(spec, (tuple,dict)):
            add_menu(win, menu, name, spec, parent=menu)
            continue

        action_func = spec
        if len(name) == 2:
            action_label, shortcut = name
        else:
            action_label = name
            shortcut = None

        action = QAction(action_label, win)
        if shortcut:
            action.setShortcut(shortcut)
        action.triggered.connect(action_func)
        add_action(action, i)

    return menu

add_to_menus

add_to_menus(name)
Source code in FoSpy/ui/app/menus.py
def add_to_menus(name):
    def decorator(func, n=name):
        def builder(win, menu_bar, _n=n, _f=func):
            specs = _f(win)
            add_menu(win, menu_bar, _n, specs)
        MENU_BUILDERS[n] = builder
        return func
    return decorator

app_menu

app_menu(win)
Source code in FoSpy/ui/app/menus.py
@add_to_menus("app")
def app_menu(win):
    import platform

    from ._utils import add_to_start, register_app
    from .check_update import update_dlg

    menu = {
        "Update FoSpy": lambda *_, w=win: update_dlg(w),
        "Add as *.fos Editor": register_app,
        "Add to Start Menu": add_to_start
    }

    current_os = platform.system()
    if current_os == "Windows":
        menu["Add to Start Menu"] = add_to_start

    return menu

file_menu

file_menu(win)
Source code in FoSpy/ui/app/menus.py
@add_to_menus("file")
def file_menu(win):

    return {
        "Open...": win._open_dlg,
        "Open A Copy...": lambda *_: win._open_dlg(copy=True),
        "Edit A Copy": win._edit_copy,
        "Save": win.save,
        "Save As...": win.save_dlg
    }

help_menu

help_menu(win)
Source code in FoSpy/ui/app/menus.py
@add_to_menus("help")
def help_menu(win):
    return {
        "Docs Site": win._open_docs_site,
        "Github": lambda *_: QDesktopServices.openUrl(QUrl("https://github.com/errthumt/FoSpy"))
    }

tools_menu

tools_menu(win)
Source code in FoSpy/ui/app/menus.py
@add_to_menus("tools")
def tools_menu(win):
    return {
        "Python Console": win._open_console
    }

view_menu

view_menu(win)
Source code in FoSpy/ui/app/menus.py
@add_to_menus("view")
def view_menu(win):
    from .window import AVAILABLE_THEMES, DEFAULT_THEME

    theme_options = []

    available = [DEFAULT_THEME]
    available.extend(t for t in AVAILABLE_THEMES if t != DEFAULT_THEME)

    win._choose_theme(DEFAULT_THEME)

    for theme_id in available:
        label = theme_id.capitalize()

        def choose_theme(*_, t=theme_id):
            win._choose_theme(t)

        theme_options.append((label, choose_theme))

    theme_options = tuple(theme_options)

    return {
        "theme": theme_options
    }

window_menu

window_menu(win)
Source code in FoSpy/ui/app/menus.py
@add_to_menus("window")
def window_menu(win):
    return {
        "Refresh Window": lambda *_: win.hard_refresh(to_blk=True)
    }