Ejemplo n.º 1
0
def test_gridlayout():
    layout = widgets.GridLayout()
    widget = widgets.RadioButton()
    layout[0:1, 0:3] = widget
    assert layout[0, 0] == widget
    layout.set_size_mode("maximum")
    layout.set_alignment("left")
    with open("data.pkl", "wb") as jar:
        pickle.dump(layout, jar)
    with open("data.pkl", "rb") as jar:
        layout = pickle.load(jar)
    assert len(layout) == len(list(layout)) == 1
    repr(layout)
    layout += widgets.RadioButton()
Ejemplo n.º 2
0
def test_toolbox():
    w = widgets.RadioButton("test1")
    w2 = widgets.RadioButton("test2")
    w2.id = "test_name"
    widget = widgets.ToolBox()
    widget.add_widget(w, "title", "mdi.timer")
    widget.add_widget(w2)
    assert widget["test_name"] == w2
    for w in widget:
        pass
    assert widget[1] == w2
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 def add_item(self, title, data=None):
     rb = widgets.RadioButton(title)
     rb.toggled.connect(self.update_choice)
     self.buttons[rb] = data
     if len(self.buttons) == 1:
         rb.setChecked(True)
     self.layout.addWidget(rb)
Ejemplo n.º 5
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.layout = widgets.BoxLayout("horizontal")
        self.rb_other = widgets.RadioButton("Other")
        self.buttons = dict()
        # self.rb_comma.setChecked(True)

        self.setLayout(self.layout)
Ejemplo n.º 6
0
 def add(self, title: str, data=None):
     rb = widgets.RadioButton(title)
     rb.toggled.connect(self.update_choice)
     self.buttons[rb] = data
     if len(self.buttons) == 1:
         with rb.block_signals():
             rb.set_value(True)
     self.box += rb
Ejemplo n.º 7
0
 def add(self, title: str, data=None, icon: types.IconType = None):
     # TODO: make use of icon kwarg
     rb = widgets.RadioButton(title)
     rb.toggled.connect(self.update_choice)
     self.buttons[rb] = data
     if len(self.buttons) == 1:
         with rb.block_signals():
             rb.set_value(True)
     self.box.add(rb)
Ejemplo n.º 8
0
def test_formlayout():
    widget = widgets.FormLayout()
    widget.set_size_mode("maximum")
    with pytest.raises(ValueError):
        widget.set_size_mode("bla")
    widget[0, "left"] = "0, left"
    widget[1, "left"] = widgets.RadioButton("1, left")
    widget[0, "right"] = "label 1 right"
    widget[1, "right"] = widgets.RadioButton("1, right")
    widget[2] = "by str"
    widget[3] = widgets.RadioButton("widget[3]")
    widget += widgets.RadioButton("added with +=")
    widget += ("added with +=", widgets.RadioButton("tuple"))
    widget = widgets.FormLayout.from_dict({"from": "dict"})
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    assert len(widget) == 2
    repr(widget)
Ejemplo n.º 9
0
def test_groupbox():
    widget = widgets.GroupBox()
    ly = widgets.BoxLayout("horizontal")
    widget.set_layout(ly)
    ly += widgets.RadioButton("+=")
    widget.set_alignment("left")
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    widget.set_enabled(False)
    repr(widget)
Ejemplo n.º 10
0
def test_stackedlayout():
    layout = widgets.StackedLayout()
    widget = widgets.RadioButton("test")
    layout += widget
    layout.set_size_mode("maximum")
    layout.set_margin(0)
    with open("data.pkl", "wb") as jar:
        pickle.dump(layout, jar)
    with open("data.pkl", "rb") as jar:
        layout = pickle.load(jar)
    assert len(layout) == 1
    return True
Ejemplo n.º 11
0
 def __init__(
     self,
     label: str = "",
     layout: constants.OrientationStr = "horizontal",
     parent: QtWidgets.QWidget | None = None,
 ):
     super().__init__(title=label, parent=parent)
     self.box = widgets.BoxLayout(layout)
     self.widget_custom: widgets.Widget | None = None
     self.rb_other = widgets.RadioButton()
     self.buttons: dict[widgets.RadioButton, Any] = {}
     self.set_layout(self.box)
Ejemplo n.º 12
0
def test_radiobutton():
    widget = widgets.RadioButton("Test")
    widget.set_icon("mdi.timer")
    widget.set_enabled()
    widget.set_disabled()
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    assert bool(widget) is False
    repr(widget)
    widget.set_value(True)
    assert widget.get_value() is True
Ejemplo n.º 13
0
def test_dialog(qtbot):
    dlg = widgets.Dialog(layout="horizontal")
    qtbot.addWidget(dlg)
    qtbot.keyPress(dlg, QtCore.Qt.Key_F11)
    dlg.delete_on_close()
    dlg.add_widget(widgets.RadioButton("test"))
    dlg.set_icon("mdi.timer")
    with open("data.pkl", "wb") as jar:
        pickle.dump(dlg, jar)
    with open("data.pkl", "rb") as jar:
        dlg = pickle.load(jar)
    dlg.resize(0, 400)
    dlg.resize((0, 400))
    dlg.add_buttonbox()
Ejemplo n.º 14
0
def test_boxlayout():
    layout = widgets.BoxLayout("horizontal")
    widget = widgets.RadioButton("test")
    layout += widget
    layout.set_size_mode("maximum")
    with pytest.raises(ValueError):
        layout.set_size_mode("bla")
    layout.set_margin(0)
    with open("data.pkl", "wb") as jar:
        pickle.dump(layout, jar)
    with open("data.pkl", "rb") as jar:
        layout = pickle.load(jar)
    assert len(layout) == 1
    repr(layout)
Ejemplo n.º 15
0
 def __init__(self,
              title: str = "",
              parent: QtWidgets.QWidget | None = None):
     super().__init__(checkable=False, title=title)
     self.set_layout("vertical")
     self.rb_lineedit = widgets.RadioButton("String")
     self.lineedit = widgets.LineEdit()
     self.rb_spinbox = widgets.RadioButton("Number")
     self.spinbox = widgets.DoubleSpinBox()
     layout_lineedit = widgets.BoxLayout("horizontal")
     layout_lineedit.add(self.rb_lineedit)
     layout_lineedit.add(self.lineedit)
     layout_spinbox = widgets.BoxLayout("horizontal")
     layout_spinbox.add(self.rb_spinbox)
     layout_spinbox.add(self.spinbox)
     self.box.add(layout_lineedit)
     self.box.add(layout_spinbox)
     self.rb_spinbox.toggled.connect(self.spinbox.setEnabled)
     self.rb_spinbox.toggled.connect(self.lineedit.setDisabled)
     self.rb_lineedit.toggled.connect(self.lineedit.setEnabled)
     self.rb_lineedit.toggled.connect(self.spinbox.setDisabled)
     self.spinbox.value_changed.connect(self.on_value_change)
     self.lineedit.value_changed.connect(self.on_value_change)
     self.rb_lineedit.setChecked(True)
Ejemplo n.º 16
0
def test_boxlayout():
    layout = widgets.BoxLayout("horizontal", margin=0)
    widget = widgets.RadioButton("test")
    layout += widget
    layout2 = widgets.BoxLayout("horizontal")
    layout += layout2
    assert layout[1] == layout2
    layout.set_size_mode("maximum")
    assert layout.get_size_mode() == "maximum"
    layout.set_alignment("left")
    # assert layout.get_alignment() == "left"
    with pytest.raises(ValueError):
        layout.set_size_mode("bla")
    layout.set_margin(0)
    with open("data.pkl", "wb") as jar:
        pickle.dump(layout, jar)
    with open("data.pkl", "rb") as jar:
        layout = pickle.load(jar)
    assert len(layout) == 2
    repr(layout)
    layout.add_stretch(1)
    layout.add_spacing(1)
Ejemplo n.º 17
0
        for item in state["items"]:
            self.add(item)

    def __iter__(self):
        return iter(self.get_children())

    def __len__(self):
        return self.count()

    def __add__(self, other):
        if isinstance(other, (QtWidgets.QWidget, QtWidgets.QLayout)):
            self.add(other)
            return self

    def get_children(self):
        return [self[i] for i in range(self.count())]


if __name__ == "__main__":
    from prettyqt import widgets
    app = widgets.app()
    layout = StackedLayout()
    widget = widgets.Widget()
    widget2 = widgets.RadioButton("Test")
    widget3 = widgets.RadioButton("Test 2")
    layout += widget2
    layout += widget3
    widget.set_layout(layout)
    widget.show()
    app.exec_()
Ejemplo n.º 18
0
    def __init__(self, obj, name: str = ""):
        super().__init__()
        self.set_title("Object browser")
        self._instance_nr = self._add_instance()
        self.set_icon("mdi.language-python")
        self._attr_cols = DEFAULT_ATTR_COLS
        self._attr_details = DEFAULT_ATTR_DETAILS

        logger.debug("Reading model settings for window: %d",
                     self._instance_nr)
        with core.Settings(
                settings_id=self._settings_group_name("model")) as settings:
            self._auto_refresh = settings.get("auto_refresh", False)
            self._refresh_rate = settings.get("refresh_rate", 2)
            show_callable_attrs = settings.get("show_callable_attrs", True)
            show_special_attrs = settings.get("show_special_attrs", True)
        self._tree_model = objectbrowsertreemodel.ObjectBrowserTreeModel(
            obj, name, attr_cols=self._attr_cols)

        self._proxy_tree_model = objectbrowsertreemodel.ObjectBrowserTreeProxyModel(
            show_callable_attrs=show_callable_attrs,
            show_special_attrs=show_special_attrs,
        )

        self._proxy_tree_model.setSourceModel(self._tree_model)
        # self._proxy_tree_model.setSortRole(RegistryTableModel.SORT_ROLE)
        self._proxy_tree_model.setDynamicSortFilter(True)
        # self._proxy_tree_model.setSortCaseSensitivity(Qt.CaseInsensitive)

        # Views
        self._setup_actions()
        self.central_splitter = widgets.Splitter(
            parent=self, orientation=constants.VERTICAL)
        self.setCentralWidget(self.central_splitter)

        # Tree widget
        self.obj_tree = widgets.TreeView()
        self.obj_tree.setRootIsDecorated(True)
        self.obj_tree.setAlternatingRowColors(True)
        self.obj_tree.set_model(self._proxy_tree_model)
        self.obj_tree.set_selection_behaviour("rows")
        self.obj_tree.setUniformRowHeights(True)
        self.obj_tree.setAnimated(True)

        # Stretch last column?
        # It doesn't play nice when columns are hidden and then shown again.
        self.obj_tree.h_header.set_id("table_header")
        self.obj_tree.h_header.setSectionsMovable(True)
        self.obj_tree.h_header.setStretchLastSection(False)
        self.central_splitter.addWidget(self.obj_tree)

        # Bottom pane
        bottom_pane_widget = widgets.Widget()
        bottom_pane_widget.set_layout("horizontal", spacing=0, margin=5)
        self.central_splitter.addWidget(bottom_pane_widget)

        group_box = widgets.GroupBox("Details")
        bottom_pane_widget.box.addWidget(group_box)

        group_box.set_layout("horizontal", margin=2)

        # Radio buttons
        radio_widget = widgets.Widget()
        radio_widget.set_layout("vertical", margin=0)

        self.button_group = widgets.ButtonGroup(self)
        for button_id, attr_detail in enumerate(self._attr_details):
            radio_button = widgets.RadioButton(attr_detail.name)
            radio_widget.box.addWidget(radio_button)
            self.button_group.addButton(radio_button, button_id)

        self.button_group.buttonClicked.connect(self._change_details_field)
        self.button_group.button(0).setChecked(True)

        radio_widget.box.addStretch(1)
        group_box.box.addWidget(radio_widget)

        # Editor widget
        font = gui.Font("Courier")
        font.setFixedPitch(True)
        # font.setPointSize(14)

        self.editor = widgets.PlainTextEdit()
        self.editor.setReadOnly(True)
        self.editor.setFont(font)
        group_box.box.addWidget(self.editor)

        # Splitter parameters
        self.central_splitter.setCollapsible(0, False)
        self.central_splitter.setCollapsible(1, True)
        self.central_splitter.setSizes([400, 200])
        self.central_splitter.setStretchFactor(0, 10)
        self.central_splitter.setStretchFactor(1, 0)

        selection_model = self.obj_tree.selectionModel()
        selection_model.currentChanged.connect(self._update_details)
        menubar = self.menuBar()
        file_menu = menubar.add_menu("&File")
        file_menu.addAction("C&lose", self.close, "Ctrl+W")
        file_menu.addAction("E&xit", lambda: widgets.app().closeAllWindows(),
                            "Ctrl+Q")

        view_menu = menubar.add_menu("&View")
        view_menu.addAction("&Refresh", self._tree_model.refresh_tree,
                            "Ctrl+R")
        view_menu.addAction(self.toggle_auto_refresh_action)

        view_menu.addSeparator()
        self.show_cols_submenu = widgets.Menu("Table columns")
        view_menu.add_menu(self.show_cols_submenu)
        actions = self.obj_tree.h_header.get_header_actions()
        self.show_cols_submenu.add_actions(actions)
        view_menu.addSeparator()
        view_menu.addAction(self.toggle_callable_action)
        view_menu.addAction(self.toggle_special_attribute_action)

        assert self._refresh_rate > 0
        self._refresh_timer = core.Timer(self)
        self._refresh_timer.setInterval(self._refresh_rate * 1000)
        self._refresh_timer.timeout.connect(self._tree_model.refresh_tree)

        # Update views with model
        self.toggle_special_attribute_action.setChecked(show_special_attrs)
        self.toggle_callable_action.setChecked(show_callable_attrs)
        self.toggle_auto_refresh_action.setChecked(self._auto_refresh)

        # Select first row so that a hidden root node will not be selected.
        first_row_index = self._proxy_tree_model.first_item_index()
        self.obj_tree.setCurrentIndex(first_row_index)
        if self._tree_model.inspected_node_is_visible:
            self.obj_tree.expand(first_row_index)
Ejemplo n.º 19
0
 def __init__(self, label="", layout="horizontal", parent=None):
     super().__init__(title=label, parent=parent)
     self.box = widgets.BoxLayout(layout)
     self.rb_other = widgets.RadioButton()
     self.buttons = dict()
     self.set_layout(self.box)
Ejemplo n.º 20
0
        Raises:
            InvalidParamError: corner does not exist
        """
        if corner not in constants.CORNER:
            raise InvalidParamError(corner, constants.CORNER)
        self.setOriginCorner(constants.CORNER[corner])

    def get_origin_corner(self) -> constants.CornerStr:
        """Return current origin corner.

        Returns:
            origin corner
        """
        return constants.CORNER.inverse[self.originCorner()]


if __name__ == "__main__":
    app = widgets.app()
    layout = GridLayout()
    layout[1, 5:6] = widgets.RadioButton("1 2 3 jk jkjl j kföldsjfköj")
    layout[3:5, 7:8] = widgets.RadioButton("2")
    layout[3:5, 1:4] = widgets.RadioButton("3")
    layout += widgets.RadioButton("3")
    layout += widgets.RadioButton("4")
    widget = widgets.Widget()
    widget.set_layout(layout)
    print(layout)
    widget.show()
    app.main_loop()
Ejemplo n.º 21
0
    def __getitem__(self, idx):
        if isinstance(idx, tuple):
            return self.itemAtPosition(*idx)
        else:
            return self.itemAt(idx)

    def __len__(self):
        return self.count()

    def set_size_mode(self, mode: str):
        if mode not in MODES:
            raise ValueError(f"{mode} not a valid size mode.")
        self.setSizeConstraint(MODES[mode])

    def set_alignment(self, alignment: str):
        if alignment not in ALIGNMENTS:
            raise ValueError(f"{alignment} not a valid alignment.")
        self.setAlignment(ALIGNMENTS[alignment])


if __name__ == "__main__":
    app = widgets.Application.create_default_app()
    layout = GridLayout()
    layout[1, 5:6] = widgets.RadioButton("1")
    layout[3:5, 7:8] = widgets.RadioButton("2")
    layout[3:5, 1:4] = widgets.RadioButton("3")
    widget = widgets.Widget()
    widget.setLayout(layout)
    widget.show()
    app.exec_()
Ejemplo n.º 22
0
def test_optionalwidget(qtbot):
    w = widgets.RadioButton()
    container = custom_widgets.OptionalWidget(w, "Test")
    container.get_value()
    container.enabled = False
    assert container.enabled is False
Ejemplo n.º 23
0
        Args:
            direction: direction

        Raises:
            InvalidParamError: direction does not exist
        """
        if direction not in DIRECTION:
            raise InvalidParamError(direction, DIRECTION)
        self.setDirection(DIRECTION[direction])

    def get_direction(self) -> DirectionStr:
        """Return current direction.

        Returns:
            direction
        """
        return DIRECTION.inverse[self.direction()]


if __name__ == "__main__":
    from prettyqt import widgets

    app = widgets.app()
    layout = BoxLayout("vertical")
    widget = widgets.Widget()
    widget2 = widgets.RadioButton("Test")
    layout.add(widget2)
    widget.set_layout(layout)
    widget.show()
    app.main_loop()
Ejemplo n.º 24
0
# -*- coding: utf-8 -*-
"""
@author: Philipp Temminghoff
"""

from qtpy import QtWidgets

from prettyqt import widgets

QtWidgets.QWizard.__bases__ = (widgets.BaseDialog, )


class Wizard(QtWidgets.QWizard):
    def add_widget_as_page(self, widget):
        page = widgets.WizardPage(self)
        layout = widgets.BoxLayout("vertical", self)
        layout += widget
        page.set_layout(layout)


if __name__ == "__main__":
    app = widgets.app()
    dlg = Wizard()
    dlg.add_widget_as_page(widgets.RadioButton("test"))
    dlg.show()
    app.exec_()
Ejemplo n.º 25
0
        super().__init__(checkable=True, title=title)
        self.set_layout("vertical")
        self.box.add(widget)
        self.widget = widget
        self.toggled.connect(self.widget.setEnabled)

    def __getattr__(self, value: str):
        return self.widget.__getattribute__(value)

    @property
    def enabled(self) -> bool:
        return self.isChecked()

    @enabled.setter
    def enabled(self, state: bool):
        self.setChecked(state)

    def get_value(self):
        if self.isChecked():
            return self.widget.get_value()
        return None


if __name__ == "__main__":
    app = widgets.app()
    img = widgets.RadioButton("test")
    widget = OptionalWidget(img, "Test")
    widget.show()
    app.main_loop()
    print(widget.enabled)
Ejemplo n.º 26
0
def test_buttongroup():
    widget = widgets.ButtonGroup()
    btn = widgets.RadioButton("test")
    widget.addButton(btn, id=2)
    assert widget[2] == btn
Ejemplo n.º 27
0
        self[self.rowCount(), 0:self.columnCount() - 1] = item

    def set_column_alignment(self, column: int,
                             alignment: constants.AlignmentStr):
        if alignment not in constants.ALIGNMENTS:
            raise InvalidParamError(alignment, constants.ALIGNMENTS)
        self.setColumnAlignment(column, constants.ALIGNMENTS[alignment])

    def set_row_alignment(self, row: int, alignment: constants.AlignmentStr):
        if alignment not in constants.ALIGNMENTS:
            raise InvalidParamError(alignment, constants.ALIGNMENTS)
        self.setRowAlignment(row, constants.ALIGNMENTS[alignment])


if __name__ == "__main__":
    app = widgets.app()
    layout = GraphicsGridLayout()
    item = widgets.GraphicsProxyWidget()
    item.setWidget(widgets.RadioButton("Test"))
    item2 = widgets.GraphicsProxyWidget()
    item2.setWidget(widgets.RadioButton("Test"))
    layout[1, 5:6] = item
    layout += item2
    widget = widgets.GraphicsWidget()
    widget.set_layout(layout)
    scene = widgets.GraphicsScene()
    scene.add(widget)
    view = widgets.GraphicsView(scene)
    view.show()
    app.main_loop()
Ejemplo n.º 28
0
def test_radiobutton():
    widget = widgets.RadioButton("Test")
    widget.show()