Esempio n. 1
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
Esempio n. 2
0
def test_toolbutton():
    widget = widgets.ToolButton()
    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)
    widget.set_enabled()
    widget.set_shortcut("Ctrl+A")
Esempio n. 3
0
    def __init__(
        self,
        title: str = "",
        animation_duration: int = 300,
        parent: QtWidgets.QWidget | None = None,
    ):
        super().__init__(parent=parent)

        self._animation_duration = animation_duration

        self.expand_btn = widgets.ToolButton()
        self.expand_btn.set_text(title)
        with self.expand_btn.edit_stylesheet() as ss:
            ss.QToolButton.border.setValue(None)
        self.expand_btn.set_style("text_beside_icon")
        self.expand_btn.set_arrow_type("right")
        self.expand_btn.setCheckable(True)
        self.expand_btn.setChecked(False)

        header_line = widgets.Frame()
        header_line.set_frame_shape("h_line")
        header_line.set_frame_shadow("sunken")
        header_line.set_size_policy("expanding", "maximum")

        self.content_area = widgets.ScrollArea()
        with self.expand_btn.edit_stylesheet() as ss:
            ss.QAbstractScrollArea.border.setValue(None)
        self.content_area.set_size_policy("expanding", "fixed")
        self.content_area.setMaximumHeight(1)
        # self.content_area.setMinimumHeight(0)

        self.toggle_anim = core.ParallelAnimationGroup()
        self.toggle_anim.add_property_animation(self, "minimumHeight")
        self.toggle_anim.add_property_animation(self, "maximumHeight")
        self.toggle_anim.add_property_animation(self.content_area, "maximumHeight")
        base_layout = widgets.GridLayout()
        base_layout.setVerticalSpacing(0)
        base_layout.set_margin(0)
        base_layout.addWidget(
            self.expand_btn, 0, 0, 1, 1, constants.ALIGN_LEFT
        )  # type: ignore
        base_layout[0, 2] = header_line
        base_layout[1, 0:2] = self.content_area
        self.setLayout(base_layout)
        # self.toggle_anim.setStartValue(0)
        # self.toggle_anim.setEndValue(300)

        def expand_view(checked: bool):
            self.expand_btn.set_arrow_type("down" if checked else "right")
            self.toggle_anim.set_direction("forward" if checked else "backward")
            self.toggle_anim.start()

        # === SIGNALS === #
        self.expand_btn.toggled.connect(expand_view)
        self.toggle_anim.set_duration(0)
        self.toggle_anim.set_duration(self._animation_duration)
Esempio n. 4
0
 def __init__(self, font=None, parent=None):
     super().__init__(parent)
     self.current_font = font
     layout = widgets.BoxLayout("horizontal", self)
     layout.set_margin(0)
     self.lineedit = widgets.LineEdit()
     self.lineedit.set_read_only()
     layout += self.lineedit
     action = widgets.Action()
     action.triggered.connect(self.choose_font)
     self.button = widgets.ToolButton()
     self.button.setDefaultAction(action)
     layout += self.button
Esempio n. 5
0
 def __init__(self, color=None, parent=None):
     super().__init__(parent)
     layout = widgets.BoxLayout("horizontal", self)
     layout.set_margin(0)
     self.lineedit = widgets.LineEdit()
     self.lineedit.set_regex_validator(r"^#(?:[0-9a-fA-F]{6})$")
     layout += self.lineedit
     action = widgets.Action(icon="mdi.format-color-fill")
     action.triggered.connect(self.choose_color)
     self.button = widgets.ToolButton()
     self.button.setDefaultAction(action)
     layout += self.button
     if color is not None:
         self.set_color(color)
Esempio n. 6
0
def test_toolbutton():
    widget = widgets.ToolButton()
    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)
    widget.set_enabled()
    widget.set_shortcut("Ctrl+A")
    with pytest.raises(ValueError):
        widget.set_popup_mode("test")
    assert widget.get_popup_mode() == "delayed"
    with pytest.raises(ValueError):
        widget.set_arrow_type("test")
    widget.set_arrow_type("left")
    assert widget.get_arrow_type() == "left"
Esempio n. 7
0
 def __init__(
     self, color: types.ColorType = None, parent: QtWidgets.QWidget | None = None
 ):
     super().__init__(parent)
     layout = widgets.BoxLayout("horizontal", self)
     layout.set_margin(0)
     self.lineedit = widgets.LineEdit()
     self.lineedit.set_regex_validator(r"^#(?:[0-9a-fA-F]{6})$")
     layout.add(self.lineedit)
     action = widgets.Action(icon="mdi.format-color-fill")
     action.triggered.connect(self.choose_color)
     self.button = widgets.ToolButton()
     self.button.setDefaultAction(action)
     layout.add(self.button)
     self._current_color: gui.Color = gui.Color("white")
     if color is not None:
         self.set_current_color(color)
Esempio n. 8
0
    def __init__(self, extensions=None, mode="save", parent=None):
        super().__init__(parent)
        self.path = None
        self.extensions = extensions
        self.mode = mode
        layout = widgets.BoxLayout("horizontal", self)
        layout.set_margin(0)
        self.lineedit = widgets.LineEdit()
        self.lineedit.set_read_only()
        layout += self.lineedit
        action = widgets.Action()
        action.set_icon("mdi.file-outline")
        action.triggered.connect(self.open_file)

        self.button = widgets.ToolButton()
        self.button.setDefaultAction(action)
        layout += self.button
Esempio n. 9
0
    def __init__(
        self,
        extensions: dict[str, list[str]] | None = None,
        mode: widgets.filedialog.AcceptModeStr = "save",
        file_mode: widgets.filedialog.FileModeStr = "existing_files",
        root: None | str | pathlib.Path = None,
        parent: QtWidgets.QWidget | None = None,
    ):
        """Initialize FileChooserButton.

        Args:
            extensions: dict allowed extensions
                        form: "'name': ['.ext1', '.ext2']"
            mode: Accept mode ("save" or "load")
            file_mode: File mode ("existing_files", "existing_file", "any_file",
                                  or "directory")
            root: Root path
            parent: parent widget
        """
        super().__init__(parent)
        self.path: pathlib.Path | None = None
        self.extensions = extensions
        self.mode: widgets.filedialog.AcceptModeStr = mode
        self.file_mode: widgets.filedialog.FileModeStr = file_mode
        self.root = root
        layout = widgets.BoxLayout("horizontal", self)
        layout.set_margin(0)
        self.lineedit = widgets.LineEdit()
        self.lineedit.set_read_only()
        layout.add(self.lineedit)
        action = widgets.Action()
        if self.file_mode == "directory":
            action.set_icon("mdi.folder-outline")
        else:
            action.set_icon("mdi.file-outline")
        action.triggered.connect(self.open_file)

        self.button = widgets.ToolButton()
        self.button.setDefaultAction(action)
        layout.add(self.button)
Esempio n. 10
0
                center.setY(obj.rect().top())
                delta = core.Point(0, -distance)
            elif position == "left":
                center.setX(obj.rect().right())
                delta = core.Point(distance, 0)
            elif position == "right":
                center.setX(obj.rect().left())
                delta = core.Point(-distance, 0)
            center = obj.mapToGlobal(center)
            self.slide_anim.set_start_value(center + delta)
            self.slide_anim.set_end_value(center)
            self.animation.start_animation()
        elif event.type() == QtCore.QEvent.Type.Leave:
            self.tool_tip.hide()
            self.animation.stop()
        elif event.type() == QtCore.QEvent.Type.ToolTip:
            return True
        return super().eventFilter(obj, event)


if __name__ == "__main__":
    app = widgets.app()
    w = widgets.ToolButton()
    ef = AnimatedToolTipEventFilter()
    w.installEventFilter(ef)
    w.setText("test")
    w.set_icon("mdi.timer")
    w.set_tooltip("testus")
    w.show()
    app.main_loop()