예제 #1
0
def test_view_tab_bar(qtbot: QtBot):
    viewspace = ViewSpace()
    qtbot.addWidget(viewspace)
    viewspace.show()
    viewspace.splitActiveHorizontal()
    view = viewspace.views[0]
    tabs = view.tabs

    tabs.view.addTab("1", _TestViewWidget(1, view, editable=True))
    tabs.view.addTab("2", _TestViewWidget(2, view))
    # Test double click rename
    dlg = tabs.tabRenameDialog(0)
    assert dlg.textValue() == "1"
    dlg.textValueSelected.emit("3")
    dlg.close()
    assert tabs.tabText(0) == "3"
    # Rename on non editable will not open dialog
    assert tabs.tabRenameDialog(1) is None

    # Test drag and drop same bar
    with qtbot.assertNotEmitted(tabs.view.numTabsChanged, wait=100):
        qtbot.mousePress(tabs,
                         QtCore.Qt.LeftButton,
                         pos=tabs.tabRect(0).center())
        qtbot.mouseRelease(tabs,
                           QtCore.Qt.LeftButton,
                           pos=tabs.tabRect(1).center())
    assert tabs.tabText(0) == "3"
    assert tabs.tabText(1) == "2"
예제 #2
0
def test_view_tabs(qtbot: QtBot):
    viewspace = ViewSpace()
    qtbot.addWidget(viewspace)
    viewspace.show()
    view = viewspace.activeView()
    # Creating tabs
    with qtbot.waitSignal(view.numTabsChanged):
        view.addTab("1", _TestViewWidget(1, view))
    with qtbot.waitSignal(viewspace.numTabsChanged):
        view.addTab("3", _TestViewWidget(3, view))
    with qtbot.waitSignal(view.numTabsChanged):
        view.insertTab(1, "2", _TestViewWidget(2, view))
    assert view.tabs.count() == 3
    assert [view.tabs.tabText(i) for i in range(3)] == ["1", "2", "3"]
    assert [view.stack.widget(i).idx for i in range(3)] == [1, 2, 3]
    # Moving tabs
    with qtbot.assertNotEmitted(view.numTabsChanged, wait=100):
        view.tabs.moveTab(2, 0)
    assert [view.tabs.tabText(i) for i in range(3)] == ["3", "1", "2"]
    assert [view.stack.widget(i).idx for i in range(3)] == [3, 1, 2]
    # Removing tabs
    with qtbot.waitSignal(viewspace.numTabsChanged):
        view.removeTab(1)
    assert view.tabs.count() == 2
    assert [view.tabs.tabText(i) for i in range(2)] == ["3", "2"]
    assert [view.stack.widget(i).idx for i in range(2)] == [3, 2]

    # view.setTabModified(0, True)
    # assert view.tabs.tabIcon(0).name() == "document-save"
    # assert view.tabs.tabIcon(1).name() == ""

    view.removeTab(0)
    assert len(view.widgets()) == 1
    view.removeTab(0)
    assert len(view.widgets()) == 0
예제 #3
0
def test_mouse_press_redirect_filter(qtbot: QtBot):
    a = EventTestWidget()
    b = EventTestWidget()
    qtbot.addWidget(a)
    qtbot.addWidget(b)

    b.installEventFilter(MousePressRedirectFilter(a))

    with qtbot.waitSignal(a.eventSuccess):
        qtbot.mousePress(b, QtCore.Qt.LeftButton)

    with qtbot.waitSignal(b.eventSuccess):
        qtbot.mousePress(b, QtCore.Qt.LeftButton)

    with qtbot.assertNotEmitted(a.eventSuccess):
        qtbot.keyPress(b, QtCore.Qt.Key_Enter)
예제 #4
0
    def test_click(self, qtbot: QtBot):
        widget = ColormapEdit()
        qtbot.addWidget(widget)
        width = widget.width() - 20
        with qtbot.waitSignal(widget.double_clicked):
            qtbot.mouseDClick(widget,
                              Qt.LeftButton,
                              pos=QPoint(30,
                                         widget.height() // 2))

        pos = 20 / width
        widget.add_color(ColorPosition(pos, Color(125, 231, 21)))
        assert len(widget.colormap) == 1
        with qtbot.assertNotEmitted(widget.double_clicked):
            qtbot.mouseDClick(widget,
                              Qt.LeftButton,
                              pos=QPoint(30,
                                         widget.height() // 2))
        assert len(widget.colormap) == 0
예제 #5
0
    def test_click(self, qtbot: QtBot):
        widget = ColormapEdit()
        qtbot.addWidget(widget)
        width = widget.width() - 20
        with qtbot.waitSignal(widget.double_clicked):
            qtbot.mouseDClick(widget,
                              Qt.LeftButton,
                              pos=QPoint(30,
                                         widget.height() // 2))

        pos = 20 / width
        widget.add_color(pos, Color(0.274, 0.02, 0.745))
        widget.add_color(pos / 2, Color(0.274, 0.2, 0.745))
        assert len(widget.colormap.colors) == 4
        with qtbot.assertNotEmitted(widget.double_clicked):
            qtbot.mouseDClick(widget,
                              Qt.LeftButton,
                              pos=QPoint(30,
                                         widget.height() // 2))
        assert len(widget.colormap.colors) == 3
예제 #6
0
def test_view_space_add_remove(qtbot: QtBot):
    viewspace = ViewSpace()
    qtbot.addWidget(viewspace)
    viewspace.show()

    assert len(viewspace.views) == 1

    with qtbot.waitSignal(viewspace.numViewsChanged):
        viewspace.splitActiveHorizontal()
    assert len(viewspace.views) == 2

    viewspace.setActiveView(viewspace.views[1])
    with qtbot.waitSignal(viewspace.numViewsChanged):
        viewspace.splitActiveVertical()
    assert len(viewspace.views) == 3

    with qtbot.waitSignal(viewspace.numViewsChanged):
        viewspace.splitView(viewspace.views[2], QtCore.Qt.Horizontal)
    assert len(viewspace.views) == 4

    # Should be 1 view on left, 1 on top right, 2 bottom right
    assert viewspace.count() == 2
    assert isinstance(viewspace.widget(0), View)
    assert isinstance(viewspace.widget(1), QtWidgets.QSplitter)

    assert viewspace.widget(1).count() == 2
    assert isinstance(viewspace.widget(1).widget(0), View)
    assert isinstance(viewspace.widget(1).widget(1), QtWidgets.QSplitter)

    assert viewspace.widget(1).widget(1).count() == 2
    assert isinstance(viewspace.widget(1).widget(1).widget(0), View)
    assert isinstance(viewspace.widget(1).widget(1).widget(1), View)

    with qtbot.waitSignal(viewspace.numViewsChanged):
        viewspace.closeView(viewspace.views[0])
    assert len(viewspace.views) == 3

    # Should be 1 view on top, 1 on bottom left, 1 bottom right
    # Original splitter changes orientation, inherits children of right splitter
    assert viewspace.count() == 2
    assert viewspace.orientation() == QtCore.Qt.Vertical
    assert isinstance(viewspace.widget(0), View)
    assert isinstance(viewspace.widget(1), QtWidgets.QSplitter)

    assert viewspace.widget(1).count() == 2
    assert isinstance(viewspace.widget(1).widget(0), View)
    assert isinstance(viewspace.widget(1).widget(1), View)

    # Active widget should be first in latest view
    for view in viewspace.views:
        view.addTab("", _ViewWidget(view))

    assert viewspace.activeWidget() == viewspace.views[2].widgets()[0]
    assert viewspace.countViewTabs() == 3

    # Close them all
    with qtbot.waitSignal(viewspace.numViewsChanged):
        viewspace.closeActiveView()
    assert len(viewspace.views) == 2
    with qtbot.waitSignal(viewspace.numViewsChanged):
        viewspace.closeActiveView()
    assert len(viewspace.views) == 1
    with qtbot.assertNotEmitted(viewspace.numViewsChanged, wait=100):
        viewspace.closeActiveView()
    assert len(viewspace.views) == 1

    assert viewspace.countViewTabs() == 1