File: test_qmainwindow.py

package info (click to toggle)
app-model 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 688 kB
  • sloc: python: 5,471; makefile: 4
file content (52 lines) | stat: -rw-r--r-- 1,449 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from __future__ import annotations

from typing import TYPE_CHECKING

import pytest
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QAction, QApplication

from app_model.backends.qt import QModelMainWindow, QModelToolBar
from app_model.types._action import Action

if TYPE_CHECKING:
    from pytestqt.qtbot import QtBot

    from ..conftest import FullApp  # noqa: TID252


@pytest.mark.needs_network
def test_qmodel_main_window(
    qtbot: QtBot, qapp: QApplication, full_app: FullApp
) -> None:
    win = QModelMainWindow(full_app)
    qtbot.addWidget(win)

    win.setModelMenuBar(
        {
            full_app.Menus.FILE: "File",
            full_app.Menus.EDIT: "Edit",
            full_app.Menus.HELP: "Help",
        }
    )
    assert [a.text() for a in win.menuBar().actions()] == ["File", "Edit", "Help"]

    tb = win.addModelToolBar(
        full_app.Menus.FILE,
        toolbutton_style=Qt.ToolButtonStyle.ToolButtonTextBesideIcon,
    )
    assert isinstance(tb, QModelToolBar)
    win.addModelToolBar(full_app.Menus.EDIT, area=Qt.ToolBarArea.RightToolBarArea)

    full_app.register_action(
        Action(
            id="late-action",
            title="Late Action",
            keybindings=[{"primary": "Shift+L"}],
            menus=[{"id": full_app.Menus.FILE}],
            callback=lambda: None,
        )
    )

    action = qapp.findChild(QAction, "late-action")
    assert action.shortcut().toString() == "Shift+L"