Ejemplo n.º 1
0
def connect_menu(main_window, profile_controller, network_thread):
    # probably overdoing it with partial functions here... but none of these
    # need to be classes honestly
    top_menu = QMenu("&Killstreaks", main_window)
    game_menu = QMenu("Select Game", main_window)

    halo_3_action = game_menu.addAction("Halo 3")
    halo_3_action.setCheckable(True)
    halo_3_action.triggered.connect(
        partial(
            set_current_game_id,
            game_id="halo_3",
            get_settings_repo=profile_controller.get_settings_repo,
            on_game_changed=profile_controller.change_game,
        )
    )

    mw2_action = game_menu.addAction("Call of Duty: Modern Warfare 2")
    mw2_action.setCheckable(True)
    mw2_action.triggered.connect(
        partial(
            set_current_game_id,
            game_id="mw2",
            get_settings_repo=profile_controller.get_settings_repo,
            on_game_changed=profile_controller.change_game,
        )
    )

    halo_5_action = game_menu.addAction("Halo 5")
    halo_5_action.setCheckable(True)
    halo_5_action.triggered.connect(
        partial(
            set_current_game_id,
            game_id="halo_5",
            get_settings_repo=profile_controller.get_settings_repo,
            on_game_changed=profile_controller.change_game,
        )
    )

    ca_action = game_menu.addAction("Combat Arms")
    ca_action.setCheckable(True)
    ca_action.triggered.connect(
        partial(
            set_current_game_id,
            game_id="ca",
            get_settings_repo=profile_controller.get_settings_repo,
            on_game_changed=profile_controller.change_game,
        )
    )

    top_menu.addMenu(game_menu)

    game_menu.aboutToShow.connect(
        partial(
            check_correct_game_in_menu,
            menu_actions_by_game_id=dict(
                halo_3=halo_3_action, mw2=mw2_action, halo_5=halo_5_action, ca=ca_action,
            ),
            load_current_game_id=partial(
                load_current_game_id,
                get_settings_repo=profile_controller.get_settings_repo,
            ),
        )
    )

    sound_on_action = top_menu.addAction("&Enable sounds")
    sound_on_action.setCheckable(True)
    sound_on_action.triggered.connect(
        partial(
            toggle_sound_on,
            get_settings_repo=profile_controller.get_settings_repo,
            on_sound_on_toggled=profile_controller.on_sound_on_toggled,
        )
    )

    auto_switch_game_action = top_menu.addAction("&Automatically Switch Games")
    auto_switch_game_action.setCheckable(True)
    auto_switch_game_action.triggered.connect(
        partial(
            toggle_auto_switch_game,
            get_settings_repo=profile_controller.get_settings_repo,
            on_auto_switch_game_toggled=profile_controller.on_auto_switch_game_toggled,
        )
    )

    top_menu.aboutToShow.connect(
        partial(
            set_check_for_auto_switch_game,
            action=auto_switch_game_action,
            load_auto_switch_game_status=partial(
                load_auto_switch_game_status,
                get_settings_repo=profile_controller.get_settings_repo,
            ),
        )
    )
    leaderboard_action = top_menu.addAction("&Leaderboards")
    leaderboard_action.triggered.connect(
        lambda: webbrowser.open(networking.sra_base_url)
    )

    profile_settings_action = top_menu.addAction("&Profile settings...")
    profile_settings_action.triggered.connect(
        lambda: profile_settings.show_dialog(main_window, network_thread, profile_controller.get_user_repo(), profile_controller.get_achievements_repo())
    )

    chase_mode_action = top_menu.addAction("&Chase mode")
    chase_mode_action.setCheckable(True)
    chase_mode_action.triggered.connect(
        partial(
            chase_mode.toggle_chase_mode,
            profile_controller=profile_controller,
            main_window=main_window,
        )
    )
    top_menu.aboutToShow.connect(
        partial(
            set_check_for_show_chase_mode,
            action=chase_mode_action,
            get_settings_repo=profile_controller.get_settings_repo
        )
    )

    main_window.form.menubar.addMenu(top_menu)
Ejemplo n.º 2
0
def setupMenu(browser):
    o = QMenu("Export selected ...", browser)
    browser.form.menuEdit.addMenu(o)

    s = QMenu("cards with columns shown", browser)
    o.addMenu(s)

    s_csv = QMenu(".. to csv", browser)
    s.addMenu(s_csv)

    s_xls = QMenu(".. to xlsx", browser)
    s.addMenu(s_xls)

    u = s_csv.addAction("keep html")
    u.triggered.connect(
        lambda _, b=browser: exp_brows_visi(b, ftype="csv", keephtml=True))

    u = s_csv.addAction("remove html")
    u.triggered.connect(
        lambda _, b=browser: exp_brows_visi(b, ftype="csv", keephtml=False))

    u = s_xls.addAction("keep html")
    u.triggered.connect(
        lambda _, b=browser: exp_brows_visi(b, ftype="xlsx", keephtml=True))

    u = s_xls.addAction("remove html")
    u.triggered.connect(
        lambda _, b=browser: exp_brows_visi(b, ftype="xlsx", keephtml=False))

    m = QMenu("according to add-on settings", browser)
    o.addMenu(m)

    c = QMenu("cards to ...", browser)
    m.addMenu(c)

    c_csv = QMenu(".. to csv", browser)
    c.addMenu(c_csv)

    c_xls = QMenu(".. to xlsx", browser)
    c.addMenu(c_xls)

    n = QMenu("underlying notes of selected cards to ...", browser)
    m.addMenu(n)

    ncsv = QMenu(".. to csv, one file per note type ...", browser)
    n.addMenu(ncsv)

    nxls = QMenu(".. to xlsx ", browser)
    n.addMenu(nxls)

    u = c_csv.addAction("keep html")
    u.triggered.connect(lambda _, b=browser: exp(
        b, ftype="csv", keephtml=True, notesonly=False))

    u = c_csv.addAction("remove html")
    u.triggered.connect(lambda _, b=browser: exp(
        b, ftype="csv", keephtml=False, notesonly=False))

    u = c_xls.addAction("keep html")
    u.triggered.connect(lambda _, b=browser: exp(
        b, ftype="xlsx", keephtml=True, notesonly=False))

    u = c_xls.addAction("remove html")
    u.triggered.connect(lambda _, b=browser: exp(
        b, ftype="xlsx", keephtml=False, notesonly=False))

    u = ncsv.addAction("keep html")
    u.triggered.connect(lambda _, b=browser: exp(
        b, ftype="csv", keephtml=True, notesonly=True))

    u = ncsv.addAction("remove html")
    u.triggered.connect(lambda _, b=browser: exp(
        b, ftype="csv", keephtml=False, notesonly=True))

    u = nxls.addAction("keep html")
    u.triggered.connect(lambda _, b=browser: exp(
        b, ftype="xlsx", keephtml=True, notesonly=True))

    u = nxls.addAction("remove html")
    u.triggered.connect(lambda _, b=browser: exp(
        b, ftype="xlsx", keephtml=False, notesonly=True))