def set_layout( self, layout: LayoutStr | QtWidgets.QLayout | None, margin: int | None = None, spacing: int | None = None, ): if layout is None: return if layout == "horizontal": self.box = widgets.BoxLayout("horizontal") elif layout == "vertical": self.box = widgets.BoxLayout("vertical") elif layout == "grid": self.box = widgets.GridLayout() elif layout == "form": self.box = widgets.FormLayout() elif layout == "stacked": self.box = widgets.StackedLayout() elif layout == "flow": from prettyqt import custom_widgets self.box = custom_widgets.FlowLayout() elif isinstance(layout, QtWidgets.QLayout): self.box = layout else: raise ValueError("Invalid Layout") self.setLayout(self.box) if margin is not None: self.box.set_margin(margin) if spacing is not None: self.box.setSpacing(spacing)
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)
def __init__(self, parent: QtWidgets.QWidget | None = None): super().__init__(parent) self.resize(608, 353) self.gridLayout = widgets.GridLayout(self) self.gridLayout.setObjectName("gridLayout") self.textedit_quickref = widgets.TextEdit(parent=self) self.textedit_quickref.setReadOnly(True) self.textedit_quickref.setObjectName("textedit_quickref") self.gridLayout.addWidget(self.textedit_quickref, 0, 0, 1, 1) html_file = pathlib.Path("ref.html") text = html_file.read_text() self.textedit_quickref.setHtml(text)
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)
def __init__(self, parent: QtWidgets.QWidget | None = None): super().__init__(parent) # Remove window title bar and frame self.setWindowFlags(QtCore.Qt.WindowFlag.Window # type: ignore | QtCore.Qt.WindowFlag.FramelessWindowHint) self.title_bar = CustomTitleBar(self) self.main_widget = widgets.MainWindow() # Set up layout self.main_layout = widgets.BoxLayout("vertical") self.main_layout.addWidget(self.title_bar) self.main_layout.addWidget(self.main_widget) self.main_layout.setContentsMargins(0, 0, 0, 0) self.main_layout.setSpacing(0) self.grip_layout = widgets.GridLayout() self.grip_layout.addLayout(self.main_layout, 1, 1) self.grip_layout.addWidget(EdgeGrip("top"), 0, 1) self.grip_layout.addWidget(EdgeGrip("right"), 1, 2) self.grip_layout.addWidget(EdgeGrip("bottom"), 2, 1) self.grip_layout.addWidget(EdgeGrip("left"), 1, 0) self.grip_layout.addWidget(EdgeGrip("top_left"), 0, 0) self.grip_layout.addWidget(EdgeGrip("top_right"), 0, 2) self.grip_layout.addWidget(EdgeGrip("bottom_left"), 2, 0) self.grip_layout.addWidget(EdgeGrip("bottom_right"), 2, 2) self.grip_layout.setContentsMargins(0, 0, 0, 0) self.grip_layout.setSpacing(0) self.setLayout(self.grip_layout) if sys.platform == "win32": self.hwnd = self.winId().__int__() window_style = win32gui.GetWindowLong(self.hwnd, GWL_STYLE) win32gui.SetWindowLong( self.hwnd, GWL_STYLE, window_style | WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, )
def set_layout(self, layout): if layout in ["horizontal", "vertical"]: self.box = widgets.BoxLayout(layout) elif layout == "grid": self.box = widgets.GridLayout() elif layout == "form": self.box = widgets.FormLayout() elif layout == "stacked": self.box = widgets.StackedLayout() elif layout == "flow": from prettyqt import custom_widgets self.box = custom_widgets.FlowLayout() else: self.box = layout if self.box is not None: self.setLayout(self.box)
def __init__( self, title: str = "Regex Editor", regex: str = "", teststring: str = "", parent: QtWidgets.QWidget | None = None, ): super().__init__(parent) self.resize(1200, 800) self.set_title(title) self.set_icon("mdi.regex") self.set_layout("horizontal") self.left_layout = widgets.BoxLayout("vertical") self.right_layout = widgets.BoxLayout("vertical") self.prog: Pattern | None = None self.matches: list[Match] = list() self.groupbox = widgets.GroupBox(title="Regular expression") self.grid = widgets.GridLayout(self.groupbox) self.layout_toprow = widgets.BoxLayout("horizontal") self.regexinput = custom_widgets.RegexInput() self.regexinput.set_min_size(400, 0) self.layout_toprow.add(self.regexinput) self.grid.add(self.layout_toprow, 1, 0) self.left_layout.add(self.groupbox) self.groupbox_teststring = widgets.GroupBox(title="Test strings") self.groupbox_teststring.set_layout("grid") self.textedit_teststring = widgets.PlainTextEdit(teststring) self.textedit_teststring.set_min_size(400, 0) self.groupbox_teststring.box.add(self.textedit_teststring, 0, 0) self.label_num_matches = widgets.Label("No match") self.label_num_matches.set_alignment("center") self.left_layout.add(self.groupbox_teststring) self.groupbox_sub = widgets.GroupBox(title="Substitution", checkable=True) self.layout_sub = widgets.GridLayout(self.groupbox_sub) self.lineedit_sub = widgets.LineEdit() self.lineedit_sub.textChanged.connect(self.update_sub_textedit) self.textedit_sub = widgets.PlainTextEdit() self.textedit_sub.set_min_size(400, 0) self.textedit_sub.set_read_only() self.layout_sub.add(self.lineedit_sub, 0, 0) self.layout_sub.add(self.textedit_sub, 1, 0) self.left_layout.add(self.groupbox_sub) self.cb_quickref = widgets.CheckBox("Show Regular Expression Quick Reference") self.left_layout.add(self.cb_quickref) self.table_matches = widgets.TableView() self.table_matches.setup_list_style() self.box.add(self.left_layout) self.box.add(self.right_layout) self.right_layout.add(self.label_num_matches) self.right_layout.add(self.table_matches) model = custom_models.RegexMatchesModel() self.table_matches.set_model(model) self.table_matches.setColumnWidth(0, 60) self.table_matches.setColumnWidth(1, 60) self.groupbox_sub.toggled.connect(self.lineedit_sub.setVisible) self.groupbox_sub.toggled.connect(self.textedit_sub.setVisible) doc = self.textedit_teststring.document() self._highlighter = RegexMatchHighlighter(doc) self._highlighter.rehighlight() self.cb_quickref.stateChanged.connect(self.quick_ref_requested) self.regexinput.value_changed.connect(self._update_view) self.textedit_teststring.textChanged.connect(self._update_view) self.regexinput.pattern = regex self._update_view()