From 5676d2550ec1dd754d41533e28540860efd9f0f8 Mon Sep 17 00:00:00 2001 From: ATATC Date: Tue, 16 Jul 2024 13:23:57 +0800 Subject: [PATCH] Supported `None` values as placeholders. (#296) --- leads_gui/prototype.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/leads_gui/prototype.py b/leads_gui/prototype.py index 5656d5a1..8b768642 100644 --- a/leads_gui/prototype.py +++ b/leads_gui/prototype.py @@ -341,7 +341,7 @@ def set(self, key: str, widget: _Widget) -> None: def get(self, key: str) -> _Widget: return self._widgets[key] - def parse_layout(self, layout: list[list[str | _Widget]]) -> list[list[_Widget]]: + def parse_layout(self, layout: list[list[str | _Widget | None]]) -> list[list[_Widget | None]]: for i in range(len(layout)): for j in range(len(layout[i])): e = layout[i][j] @@ -349,7 +349,7 @@ def parse_layout(self, layout: list[list[str | _Widget]]) -> list[list[_Widget]] layout[i][j] = self[e] return layout - def layout(self, layout: list[list[str | _Widget]]) -> None: + def layout(self, layout: list[list[str | _Widget | None]]) -> None: layout = self.parse_layout(layout) root = self._window.root() root.grid_columnconfigure(tuple(range(t := _lcm.reduce(tuple(map(len, layout))))), weight=1) @@ -359,7 +359,8 @@ def layout(self, layout: list[list[str | _Widget]]) -> None: row = layout[i] length = len(row) for j in range(length): - widget = row[j] + if (widget := row[j]) is None: + continue s = int(t / length) widget.configure(width=screen_width) widget.grid(row=i, column=j * s, sticky="NSEW", columnspan=s, ipadx=p, ipady=p, padx=p, pady=p)