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 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 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)
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)