Exemplo n.º 1
0
def test_statusbar():
    widget = widgets.MainWindow()
    status_bar = widgets.StatusBar()
    status_bar.set_color("black")
    label = widgets.Label("test")
    status_bar.addWidget(label)
    status_bar.setup_default_bar()
    status_bar.show_message("test")
    status_bar.add_action(widgets.Action())
    status_bar += widgets.Action()
    widget.setStatusBar(status_bar)
    status_bar.add_widget(widgets.Widget())
    status_bar += widgets.Widget()
    status_bar.add_widget(widgets.Widget(), permanent=True)
Exemplo n.º 2
0
def test_tabwidget():
    widget = widgets.TabWidget()
    widget.add_tab(widgets.Widget(), "mdi.timer")
    widget.insert_tab(0, widgets.Widget(), "test", "mdi.timer")
    w = widgets.Widget()
    widget.add_tab(w, "test", "mdi.timer")
    assert widget[2] == w
    widget.set_tab(0, "right", None)
    widget.set_detachable()
    widget.detach_tab(0, core.Point())
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    widget.remove_tab(0)
Exemplo n.º 3
0
def test_application(qapp):
    assert qapp.get_mainwindow() is None
    wnd = widgets.MainWindow()
    mw_widget = widgets.Widget()
    mw_widget.set_id("test")
    wnd.setCentralWidget(mw_widget)
    assert qapp.get_mainwindow() == wnd
    widget = qapp.get_widget(name="test")
    assert widget == mw_widget
    widget = widgets.Application["test"]
    assert widget == mw_widget
    with pytest.raises(InvalidParamError):
        qapp.get_style_icon("testus")
    icon = qapp.get_style_icon("warning")
    assert isinstance(icon, QtGui.QIcon)
    qapp.set_effect_enabled("animate_toolbox")
    with pytest.raises(InvalidParamError):
        qapp.set_effect_enabled("test")
    # assert qapp.is_effect_enabled("animate_toolbox")
    # qapp.set_navigation_mode("keypad_directional")
    # with pytest.raises(InvalidParamError):
    #     qapp.set_navigation_mode("test")
    # assert qapp.get_navigation_mode("keypad_directional")
    for widget in qapp:
        pass
    qapp.store_widget_states()
    qapp.restore_widget_states()
    event = QtGui.QKeyEvent(
        QtCore.QEvent.Type.KeyPress, QtCore.Qt.Key.Key_Down, QtCore.Qt.KeyboardModifier(0)
    )
    assert qapp.send_event("test", event) is True
    qapp.post_event("test", event)
    with qapp.edit_stylesheet():
        pass
Exemplo n.º 4
0
def test_widget():
    widget = widgets.Widget()
    layout = widgets.BoxLayout()
    widget.set_layout(layout)
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    with widget.block_signals():
        pass
    widget.set_enabled()
    widget.set_disabled()
    widget.set_min_size(1, 1)
    widget.set_max_size(2, 2)
    widget.title = "test"
    assert widget.title == "test"
    with widget.updates_off():
        widget.set_title("test2")
    widget.enabled = True
    assert widget.enabled is True
    widget.set_modality("window")
    with pytest.raises(ValueError):
        widget.set_modality("test")
    assert widget.get_modality() == "window"
    widget.center()
    widget.set_layout("horizontal")
    widget.set_layout("form")
    widget.set_layout("stacked")
    widget.set_layout("flow")
Exemplo n.º 5
0
    def createEditor(
        self,
        parent: QtWidgets.QWidget,
        option: QtWidgets.QStyleOptionViewItem,
        index: QtCore.QModelIndex,
    ) -> widgets.Widget:
        editor = widgets.Widget(parent)
        editor.set_margin(0)
        editor.setAutoFillBackground(True)
        # create a button group to keep track of the checked radio
        editor.button_group = widgets.ButtonGroup()
        # adding the widget as an argument to the layout constructor automatically
        # applies it to the widget
        layout = widgets.BoxLayout("horizontal", parent=editor)
        layout.set_margin(0)
        for i, k in enumerate(self.items):
            rb = widgets.RadioButton(k)
            layout.addWidget(rb)
            # prevent the radio to get focus from keyboard or mouse
            rb.set_focus_policy("none")
            rb.installEventFilter(self)
            editor.button_group.addButton(rb, i)
        # add a stretch to always align contents to the left
        layout.addStretch(1)

        # set a property that will be used for the mask
        editor.setProperty("offMask",
                           gui.Region(editor.rect()))  # type: ignore
        editor.installEventFilter(self)
        return editor
Exemplo n.º 6
0
def test_scrollarea():
    widget = widgets.ScrollArea()
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    widget.set_widget(widgets.Widget())
Exemplo n.º 7
0
def test_dockwidget():
    widget = widgets.DockWidget()
    widget.setup_title_bar()
    widget.maximise()
    w = widgets.Widget()
    widget.set_widget(w)
    w.raise_dock()
Exemplo n.º 8
0
 def __init__(self, parent: QtWidgets.QWidget | None = None):
     super().__init__(parent)
     self.set_frame_shape("styled_panel")
     self.set_frame_shadow("plain")
     # layout
     self._layout = widgets.BoxLayout("vertical")
     self._layout.set_margin(0)
     self._layout.setSpacing(0)
     self.setLayout(self._layout)
     # button
     self._button = widgets.ToolButton(self)
     self._button.set_arrow_type("right")
     self._button.set_style("text_beside_icon")
     self._button.setAutoRaise(False)
     self._button.set_text("CollapsibleFrame")
     self.set_size_policy("minimum_expanding", "fixed")
     self._layout.addWidget(self._button, 0)
     self._button.setVisible(True)
     # group box
     self._panel = widgets.Widget(self)
     self._layout.addWidget(self._panel)
     self._panel.setVisible(False)
     self._panel_layout = widgets.BoxLayout("vertical")
     self._panel_layout.set_margin(1)
     self._panel_layout.setSpacing(2)
     self._panel.setLayout(self._panel_layout)
     # connect signals
     self._button.clicked.connect(self.on_button_click)
     # private state variables
     self._is_collapsed = True
Exemplo n.º 9
0
 def paintEvent(self, event):
     painter = gui.Painter(self)
     painter.use_antialiasing()
     painter.set_pen("none")
     painter.set_transparent_background(False)
     painter.set_transparent_background(True)
     painter.set_brush(gui.Brush())
     with painter.paint_on(widgets.Widget()):
         pass
     painter.set_brush(gui.Color("red"))
     painter.fill_rect((0, 1, 3, 5), "transparent")
     painter.fill_rect(core.Rect(), "transparent")
     with pytest.raises(InvalidParamError):
         painter.fill_rect(core.Rect(), "transparent", "test")
     with pytest.raises(ValueError):
         painter.fill_rect(core.Rect(), "testus")
     painter.set_color("black")
     painter.set_composition_mode("source_atop")
     painter.get_composition_mode() == "source_atop"
     with pytest.raises(InvalidParamError):
         painter.set_composition_mode("test")
     painter.set_clip_path(gui.PainterPath(), "replace")
     with pytest.raises(InvalidParamError):
         painter.set_clip_path(gui.PainterPath(), "test")
     with pytest.raises(InvalidParamError):
         painter.set_pen(style="test")
     with painter.backup_state():
         pass
     assert painter.get_text_rect("test") is not None
Exemplo n.º 10
0
def test_collapsibleframe(qtbot):
    frame = custom_widgets.CollapsibleFrame()
    widget = widgets.Widget()
    frame.add_widget(widget)
    frame.set_title("CollapsibleFrame")
    frame.expand()
    assert frame.is_expanded() is True
    frame.collapse()
    frame.remove_widget(widget)
Exemplo n.º 11
0
 def add(self, item) -> int:
     if isinstance(item, QtWidgets.QWidget):
         return self.addWidget(item)
     elif isinstance(item, QtWidgets.QLayout):
         w = widgets.Widget()
         w.set_layout(item)
         return self.addWidget(w)
     else:
         raise TypeError("add_item only supports widgets and layouts")
Exemplo n.º 12
0
 def add(self, *item: QtWidgets.QWidget | QtWidgets.QLayout):
     for i in item:
         if isinstance(i, QtWidgets.QWidget):
             self.addWidget(i)
         elif isinstance(i, QtWidgets.QLayout):
             w = widgets.Widget()
             w.set_layout(i)
             self.addWidget(w)
         else:
             raise TypeError("add_item only supports widgets and layouts")
Exemplo n.º 13
0
def test_tabwidget():
    widget = widgets.TabWidget(detachable=True)
    widget.add_tab(widgets.Widget(), "mdi.timer")
    widget.insert_tab(0, widgets.Widget(), "test", "mdi.timer")
    assert len(widget) == 2
    w = widgets.Widget()
    widget.add_tab(w, "test", "mdi.timer")
    assert widget[2] == w
    widget.set_tab(0, "right", None)
    widget.set_detachable()
    widget.detach_tab(0, core.Point())
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    with pytest.raises(ValueError):
        widget.set_tab_shape("test")
    widget.remove_tab(0)
    widget.add_tab(widgets.BoxLayout("horizontal"), "mdi.timer")
    widget.close_detached_tabs()
Exemplo n.º 14
0
def test_widget():
    widget = widgets.Widget()
    layout = widgets.BoxLayout()
    widget.set_layout(layout)
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    with widget.block_signals():
        pass
    widget.set_enabled()
    widget.set_disabled()
Exemplo n.º 15
0
 def add_tab(self, item, label, icon=None):
     if isinstance(item, QtWidgets.QLayout):
         widget = widgets.Widget()
         widget.set_layout(item)
     else:
         widget = item
     if not icon:
         return self.addTab(widget, label)
     else:
         if isinstance(icon, str):
             icon = qta.icon(icon)
         return self.addTab(widget, icon, label)
Exemplo n.º 16
0
 def setup_title_bar(self):
     title_bar = widgets.Widget()
     layout = widgets.BoxLayout("horizontal")
     layout.set_alignment("right")
     title_bar.setLayout(layout)
     maximise_button = widgets.PushButton()
     layout.addWidget(maximise_button)
     maximise_button.set_style_icon("maximise")
     maximise_button.clicked.connect(self.maximise)
     close_button = widgets.PushButton()
     close_button.set_style_icon("close")
     layout.addWidget(close_button)
     close_button.clicked.connect(self.close)
     self.setTitleBarWidget(title_bar)
Exemplo n.º 17
0
 def add_widget_as_dock(self,
                        name: str,
                        title: str,
                        vertical: bool = True,
                        position: str = "left") -> widgets.DockWidget:
     dock_widget = widgets.DockWidget(self, name=name, title=title)
     widget = widgets.Widget()
     widget.id = f"{name}.widget"
     orientation = "vertical" if vertical else "horizontal"
     layout = widgets.BoxLayout(orientation, widget, margin=0)
     dock_widget.setWidget(widget)
     self.add_dockwidget(dock_widget, position)
     dock_widget.box = layout
     return dock_widget
Exemplo n.º 18
0
 def __init__(
     self,
     parent: QtWidgets.QWidget | None = None,
     show_settings: bool = False,
     main_layout: widgets.widget.LayoutStr | QtWidgets.QLayout = "vertical",
 ):
     super().__init__(parent=parent)
     self.button_map: dict[QtWidgets.QWidget, QtWidgets.QToolButton] = {}
     self.icon_map: dict[QtWidgets.QWidget, gui.Icon] = {}
     self.sidebar = widgets.ToolBar()
     self.sidebar.set_id("SidebarWidget")
     self.sidebar.set_title("Sidebar")
     self.sidebar.set_style("text_below_icon")
     self.sidebar.set_context_menu_policy("prevent")
     self.sidebar.setFloatable(False)
     self.sidebar.set_allowed_areas("all")
     self.settings_menu = widgets.Menu()
     self.sidebar.set_icon_size(60)
     if show_settings:
         self.settings_btn = self.sidebar.add_menu_button(
             "", icon="mdi.wrench", menu=self.settings_menu)
         self.settings_btn.setFixedSize(self.BUTTON_WIDTH,
                                        self.SETTINGS_BUTTON_HEIGHT)
         self.settings_btn.set_style("icon")
         self.sidebar.orientationChanged.connect(
             self._on_orientation_change)
         self.sidebar.add_separator()
     self.spacer_action = self.sidebar.add_spacer()
     self.add_toolbar(self.sidebar, "left")
     self.area = widgets.Widget()
     self.area.set_layout("stacked")
     w = widgets.Widget()
     w.set_layout(main_layout)
     self.main_layout = w.box
     self.main_layout.set_margin(0)
     self.main_layout += self.area
     self.setCentralWidget(w)
Exemplo n.º 19
0
def test_mdiarea():
    area = widgets.MdiArea()
    area.set_window_order("activation")
    with pytest.raises(ValueError):
        area.set_window_order("test")
    assert area.get_window_order() == "activation"
    area.set_view_mode("default")
    with pytest.raises(ValueError):
        area.set_view_mode("test")
    assert area.get_view_mode() == "default"
    area.set_tab_position("north")
    with pytest.raises(ValueError):
        area.set_tab_position("test")
    assert area.get_tab_position() == "north"
    area.set_background("black")
    area.add(widgets.Widget())
Exemplo n.º 20
0
 def add_widget_as_dock(
     self,
     name: str,
     title: str,
     vertical: bool = True,
     position: constants.DockPositionStr = "left",
 ) -> widgets.DockWidget:
     dock_widget = widgets.DockWidget(self, name=name, title=title)
     widget = widgets.Widget()
     widget.set_id(f"{name}.widget")
     layout = widgets.BoxLayout(
         "vertical" if vertical else "horizontal", widget, margin=0
     )
     dock_widget.setWidget(widget)
     self.add_dockwidget(dock_widget, position)
     dock_widget.box = layout
     return dock_widget
Exemplo n.º 21
0
 def add_dockwidget(self,
                    name: str,
                    title: str,
                    vertical: bool = True,
                    position: str = "left") -> widgets.DockWidget:
     dock_widget = widgets.DockWidget(self, name=name, title=title)
     widget = widgets.Widget()
     widget.setObjectName(f"{name}.widget")
     if vertical:
         layout = QtWidgets.QVBoxLayout(widget)
     else:
         layout = QtWidgets.QHBoxLayout(widget)
     layout.setContentsMargins(0, 0, 0, 0)
     dock_widget.setWidget(widget)
     position = DOCK_POSITIONS[position]
     self.addDockWidget(QtCore.Qt.DockWidgetArea(position), dock_widget)
     dock_widget.layout = layout
     return dock_widget
Exemplo n.º 22
0
def test_screen(qapp):
    screen = qapp.get_primary_screen()
    screen.get_geometry()
    screen.get_size()
    screen.get_available_geometry()
    screen.get_available_size()
    screen.get_available_virtual_geometry()
    screen.get_available_virtual_size()
    screen.get_virtual_geometry()
    screen.get_virtual_size()
    screen.get_native_orientation()
    screen.get_orientation()
    screen.get_primary_orientation()
    screen.get_physical_size()
    screen.get_angle_between("primary", "landscape")
    w = widgets.Widget()
    screen.grab_window(w.winId())
    screen.get_virtual_siblings()
Exemplo n.º 23
0
def test_flowlayout():
    widget = widgets.Widget()
    layout = custom_widgets.FlowLayout()
    btn = widgets.PushButton("Short")
    layout += btn
    layout += widgets.PushButton("Longer")
    layout += widgets.PushButton("Different text")
    layout += widgets.PushButton("More text")
    layout += widgets.PushButton("Even longer button text")
    widget.set_layout(layout)
    assert layout[0] == btn
    for i in range(len(layout)):
        pass
    layout.get_children()
    with open("data.pkl", "wb") as jar:
        pickle.dump(layout, jar)
    with open("data.pkl", "rb") as jar:
        layout = pickle.load(jar)
Exemplo n.º 24
0
def test_splitter():
    widget = widgets.Splitter("vertical")
    test = widgets.Label("test")
    test2 = widgets.Label("test2")
    widget.add_widget(test)
    widget += test2
    assert len(widget) == 2
    assert widget[0] == test
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    for item in widget:
        pass
    widget.set_size_policy("expanding", "expanding")
    widget.set_orientation("horizontal")
    with pytest.raises(ValueError):
        widget.set_orientation("test")
    widget.add_layout(widgets.BoxLayout("horizontal"))
    widgets.Splitter.from_widgets([widgets.Widget()])
Exemplo n.º 25
0
def test_waitingspinner(qtbot):
    test_widget = widgets.Widget()
    spinner = custom_widgets.WaitingSpinner(parent=test_widget)
    spinner.repaint()
    spinner.set_line_num(2)
    assert spinner.line_num() == 2
    spinner.set_line_length(2)
    assert spinner.line_length() == 2
    spinner.set_line_width(2)
    assert spinner.line_width() == 2
    spinner.set_inner_radius(2)
    assert spinner.inner_radius() == 2
    spinner.set_color("black")
    spinner.set_revolutions_per_second(2)
    spinner.set_trail_fade_percentage(2)
    spinner.set_minimum_trail_opacity(2)
    spinner._rotate()
    spinner.start()
    spinner.stop()
    spinner._update_position()
Exemplo n.º 26
0
def test_flowlayout():
    widget = widgets.Widget()
    layout = custom_widgets.FlowLayout(margin=1)
    btn = widgets.PushButton("Short")
    layout += btn
    layout += widgets.PushButton("Longer")
    layout += widgets.PushButton("Different text")
    layout += widgets.PushButton("More text")
    layout += widgets.PushButton("Even longer button text")
    layout.do_layout(core.Rect(), False)
    layout.sizeHint()
    widget.set_layout(layout)
    assert layout[0] == btn
    for i in layout:
        pass
    assert len(layout) == 5
    layout.get_children()
    with open("data.pkl", "wb") as jar:
        pickle.dump(layout, jar)
    with open("data.pkl", "rb") as jar:
        layout = pickle.load(jar)
Exemplo n.º 27
0
 def add_tab(
     self,
     item: QtWidgets.QWidget | QtWidgets.QLayout,
     label: str,
     icon: types.IconType = None,
     position: int | None = None,
     show: bool = False,
 ) -> int:
     if isinstance(item, QtWidgets.QLayout):
         widget = widgets.Widget()
         widget.set_layout(item)
     else:
         widget = item
     if position is None:
         position = len(self)
     if not icon:
         index = self.insertTab(position, widget, label)
     else:
         icon = iconprovider.get_icon(icon)
         index = self.insertTab(position, widget, icon, label)
     if show:
         self.setCurrentIndex(index)
     return index
Exemplo n.º 28
0
def test_buttondelegate():
    widget = custom_widgets.ButtonDelegate(parent=None)
    widget.setEditorData(widgets.Widget(), None)
    widget.createEditor(None, None, QtCore.QModelIndex())
    widget.currentIndexChanged()
Exemplo n.º 29
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Tests for `prettyqt` package."""

import pickle

from qtpy import QtCore, QtGui

from prettyqt import core, custom_widgets, gui, widgets
import prettyqt.custom_widgets.dataset as fo

test_widget = widgets.Widget()


def test_buttondelegate():
    widget = custom_widgets.ButtonDelegate(parent=None)
    widget.setEditorData(widgets.Widget(), None)
    widget.createEditor(None, None, QtCore.QModelIndex())
    widget.currentIndexChanged()


def test_colorchooserbutton():
    btn = custom_widgets.ColorChooserButton()
    btn.set_color("green")
    with open("data.pkl", "wb") as jar:
        pickle.dump(btn, jar)
    with open("data.pkl", "rb") as jar:
        btn = pickle.load(jar)
    repr(btn)
    assert btn.get_value() == gui.Color("green")
Exemplo n.º 30
0
        pos = self.getItemPosition(index)
        return pos[0], ROLES.inv[pos[1]]

    @classmethod
    def from_dict(cls, dct, parent=None):
        formlayout = cls(parent)
        for i, (k, v) in enumerate(dct.items(), start=1):
            if k is not None:
                formlayout[i, "left"] = k
            if v is not None:
                formlayout[i, "right"] = v
        return formlayout

    def add(self, item):
        if isinstance(item, (QtWidgets.QWidget, QtWidgets.QLayout)):
            self.addRow(item)
        if isinstance(item, tuple):
            self.addRow(*item)


if __name__ == "__main__":
    app = widgets.app()
    dct = {"key": widgets.Label("test"),
           None: widgets.Label("test 2")}
    layout = FormLayout.from_dict(dct)
    layout[3] = "hellooo"
    widget = widgets.Widget()
    widget.set_layout(layout)
    widget.show()
    app.exec_()