pygui_simple 0.2.0__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/PKG-INFO +1 -1
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/pyproject.toml +1 -1
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/src/pygui_simple/tkcalendar.py +5 -5
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/src/pygui_simple/tkscrollpicker.py +8 -8
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/src/pygui_simple/tkslideswitch.py +4 -4
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/src/pygui_simple/tkwin.py +37 -50
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/src/pygui_simple/winbasic.py +123 -71
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/LICENSE +0 -0
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/README.md +0 -0
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/src/pygui_simple/__init__.py +0 -0
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/src/pygui_simple/cv2_utilities.py +0 -0
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/src/pygui_simple/py.typed +0 -0
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/src/pygui_simple/tkcontrol.py +0 -0
- {pygui_simple-0.2.0 → pygui_simple-0.3.1}/src/pygui_simple/tkmatplot.py +0 -0
|
@@ -8,7 +8,7 @@ import tkinter as tk
|
|
|
8
8
|
import tkinter.font as tkFont
|
|
9
9
|
from tkinter import ttk
|
|
10
10
|
|
|
11
|
-
from pygui_simple.winbasic import
|
|
11
|
+
from pygui_simple.winbasic import Container
|
|
12
12
|
from pygui_simple.tkcontrol import tkControl
|
|
13
13
|
|
|
14
14
|
|
|
@@ -34,7 +34,7 @@ class CalendarCtrl(tkControl):
|
|
|
34
34
|
_cmb_month: ttk Combobox for month selection
|
|
35
35
|
_items: List of Treeview item IDs for calendar week rows
|
|
36
36
|
"""
|
|
37
|
-
def __init__(self, parent: tk.Misc, owner:
|
|
37
|
+
def __init__(self, parent: tk.Misc, owner: Container, idself: str, **kwargs: object):
|
|
38
38
|
""" Initialize the calendar control widget.
|
|
39
39
|
|
|
40
40
|
Args:
|
|
@@ -48,7 +48,7 @@ class CalendarCtrl(tkControl):
|
|
|
48
48
|
super().__init__(parent, "", idself, ctrl)
|
|
49
49
|
|
|
50
50
|
self._master: tk.Misc = parent
|
|
51
|
-
self._owner:
|
|
51
|
+
self._owner: Container = owner
|
|
52
52
|
|
|
53
53
|
# first day of week, default to Monday)
|
|
54
54
|
fwday = cast(int, kwargs.get("fwday", 0))
|
|
@@ -429,7 +429,7 @@ class CalendarCtrl(tkControl):
|
|
|
429
429
|
self._canvas.place_forget()
|
|
430
430
|
|
|
431
431
|
|
|
432
|
-
class CalendarDialog(
|
|
432
|
+
class CalendarDialog(Container):
|
|
433
433
|
""" A modal, borderless pop-up dialog for date selection.
|
|
434
434
|
|
|
435
435
|
This class creates a top-level tkinter window containing a CalendarCtrl widget
|
|
@@ -452,7 +452,7 @@ class CalendarDialog(Dialog):
|
|
|
452
452
|
point: Optional (x, y) screen coordinates for the dialog window;
|
|
453
453
|
defaults to screen center if None
|
|
454
454
|
"""
|
|
455
|
-
super().__init__(
|
|
455
|
+
super().__init__()
|
|
456
456
|
|
|
457
457
|
# Initialize hidden top-level window
|
|
458
458
|
self._top: tk.Toplevel = tk.Toplevel()
|
|
@@ -9,7 +9,7 @@ from typing import override, cast
|
|
|
9
9
|
from typing import TypeAlias, Callable, Any
|
|
10
10
|
from typing import Generic, TypeVar
|
|
11
11
|
|
|
12
|
-
from pygui_simple.winbasic import
|
|
12
|
+
from pygui_simple.winbasic import Container
|
|
13
13
|
from pygui_simple.tkcontrol import tkControl
|
|
14
14
|
|
|
15
15
|
|
|
@@ -171,13 +171,13 @@ class ScrollPicker(tk.Frame, Generic[T]):
|
|
|
171
171
|
|
|
172
172
|
|
|
173
173
|
class ScrollPickerCtrl(tkControl, Generic[T]):
|
|
174
|
-
def __init__(self, parent: tk.Misc, owner:
|
|
174
|
+
def __init__(self, parent: tk.Misc, owner: Container, idself: str,
|
|
175
175
|
width: int, height: int,
|
|
176
176
|
val_list: list[T],
|
|
177
177
|
initial: T | None = None,
|
|
178
178
|
background: str = "white"):
|
|
179
179
|
self._master: tk.Misc = parent
|
|
180
|
-
self._owner:
|
|
180
|
+
self._owner: Container = owner
|
|
181
181
|
|
|
182
182
|
self._frame: tk.Frame = tk.Frame(self._master,
|
|
183
183
|
background=background,
|
|
@@ -355,12 +355,12 @@ class DateScrollPickerDialog:
|
|
|
355
355
|
|
|
356
356
|
|
|
357
357
|
class TimeScrollPickerCtrl(tkControl):
|
|
358
|
-
def __init__(self, parent: tk.Misc, owner:
|
|
358
|
+
def __init__(self, parent: tk.Misc, owner: Container, idself: str,
|
|
359
359
|
width: int, height: int,
|
|
360
360
|
background: str = "white",
|
|
361
361
|
title: str = "", initial: str = ""):
|
|
362
362
|
self._master: tk.Misc = parent
|
|
363
|
-
self._owner:
|
|
363
|
+
self._owner: Container = owner
|
|
364
364
|
|
|
365
365
|
self._frame: tk.Frame = tk.Frame(self._master,
|
|
366
366
|
background=background,
|
|
@@ -439,10 +439,10 @@ class TimeScrollPickerCtrl(tkControl):
|
|
|
439
439
|
return f"{self._selected_hour:02d}:{self._selected_minute:02d}"
|
|
440
440
|
|
|
441
441
|
|
|
442
|
-
class TimeScrollPickerDialog(
|
|
442
|
+
class TimeScrollPickerDialog(Container):
|
|
443
443
|
def __init__(self, point: tuple[int, int] | None = None,
|
|
444
444
|
title: str = "", initial: str = ""):
|
|
445
|
-
super().__init__(
|
|
445
|
+
super().__init__()
|
|
446
446
|
|
|
447
447
|
self._master: tk.Toplevel = tk.Toplevel()
|
|
448
448
|
self._master.withdraw()
|
|
@@ -498,7 +498,6 @@ class TimeScrollPickerDialog(Dialog):
|
|
|
498
498
|
self._master.focus_set()
|
|
499
499
|
self._master.wait_window()
|
|
500
500
|
|
|
501
|
-
@override
|
|
502
501
|
def _confirm(self, **kwargs: object):
|
|
503
502
|
self._exit()
|
|
504
503
|
return True, ""
|
|
@@ -540,6 +539,7 @@ class TimeScrollPickerDialog(Dialog):
|
|
|
540
539
|
def destroy(self, **kwargs: object):
|
|
541
540
|
pass
|
|
542
541
|
|
|
542
|
+
|
|
543
543
|
if __name__ == "__main__":
|
|
544
544
|
class ScrollPickerCtrl_test():
|
|
545
545
|
def __init__(self):
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import tkinter as tk
|
|
4
4
|
from typing import Callable, cast, override
|
|
5
5
|
|
|
6
|
-
from pygui_simple.winbasic import
|
|
6
|
+
from pygui_simple.winbasic import Container
|
|
7
7
|
from pygui_simple.tkcontrol import tkControl
|
|
8
8
|
|
|
9
9
|
|
|
@@ -27,7 +27,7 @@ class SlideSwitchCtrl(tkControl):
|
|
|
27
27
|
def __init__(
|
|
28
28
|
self,
|
|
29
29
|
parent: tk.Misc,
|
|
30
|
-
owner:
|
|
30
|
+
owner: Container,
|
|
31
31
|
idself: str,
|
|
32
32
|
width: int = 80,
|
|
33
33
|
height: int = 40,
|
|
@@ -59,7 +59,7 @@ class SlideSwitchCtrl(tkControl):
|
|
|
59
59
|
"""
|
|
60
60
|
ctrl = tk.Canvas(parent, width=width, height=height, highlightthickness=0)
|
|
61
61
|
super().__init__(parent, "", idself, ctrl)
|
|
62
|
-
self._master:
|
|
62
|
+
self._master: Container = owner
|
|
63
63
|
|
|
64
64
|
self._width: int = width
|
|
65
65
|
self._height: int = height
|
|
@@ -364,7 +364,7 @@ class SlideSwitchCtrl(tkControl):
|
|
|
364
364
|
|
|
365
365
|
|
|
366
366
|
if __name__ == "__main__":
|
|
367
|
-
class tkBasic(
|
|
367
|
+
class tkBasic(Container):
|
|
368
368
|
"""Demonstration application for the SlideSwitch widget.
|
|
369
369
|
|
|
370
370
|
Creates a simple Tkinter window with the SlideSwitch widget,
|
|
@@ -40,7 +40,7 @@ IS_WINDOWS = platform.system() == "Windows"
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
class LabelCtrl(tkControl):
|
|
43
|
-
def __init__(self, parent: tk.Misc, owner:
|
|
43
|
+
def __init__(self, parent: tk.Misc, owner: Container, idself: str,
|
|
44
44
|
text: str, clickable: bool, **options: Any):
|
|
45
45
|
# po(f"{idself}: {options}")
|
|
46
46
|
ctrl = ttk.Label(parent, text=text, **options)
|
|
@@ -103,11 +103,11 @@ class ImagePanelCtrl(tkControl):
|
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
class ButtonCtrl(tkControl):
|
|
106
|
-
def __init__(self, parent: tk.Misc, owner:
|
|
106
|
+
def __init__(self, parent: tk.Misc, owner: Container, idself: str, text: str,
|
|
107
107
|
**options: Any):
|
|
108
108
|
ctrl = ttk.Button(parent, text=text, **options)
|
|
109
109
|
tkControl.__init__(self, parent, text, idself, ctrl)
|
|
110
|
-
self._owner:
|
|
110
|
+
self._owner: Container = owner
|
|
111
111
|
_ = ctrl.configure(command=self._btn_clicked, **options)
|
|
112
112
|
|
|
113
113
|
def _btn_clicked(self):
|
|
@@ -117,7 +117,7 @@ class ButtonCtrl(tkControl):
|
|
|
117
117
|
|
|
118
118
|
|
|
119
119
|
class ImageBtttonCtrl(tkControl):
|
|
120
|
-
def __init__(self, parent: tk.Misc, owner:
|
|
120
|
+
def __init__(self, parent: tk.Misc, owner: Container, idself: str, *,
|
|
121
121
|
respath: str, imagefile: str, text: str | None,
|
|
122
122
|
width: int = 0, height: int = 0,
|
|
123
123
|
**options: Any):
|
|
@@ -169,7 +169,7 @@ class ImageBtttonCtrl(tkControl):
|
|
|
169
169
|
|
|
170
170
|
|
|
171
171
|
class CheckButtonCtrl(tkControl):
|
|
172
|
-
def __init__(self, parent: tk.Misc, owner:
|
|
172
|
+
def __init__(self, parent: tk.Misc, owner: Container, idself: str, *,
|
|
173
173
|
text: str, vartext: str, select: bool, **options: Any):
|
|
174
174
|
ctrl = tk.Checkbutton(parent)
|
|
175
175
|
tkControl.__init__(self, parent, "", idself, ctrl)
|
|
@@ -190,7 +190,7 @@ class CheckButtonCtrl(tkControl):
|
|
|
190
190
|
|
|
191
191
|
|
|
192
192
|
class ComboboxCtrl(tkControl):
|
|
193
|
-
def __init__(self, parent: tk.Misc, owner:
|
|
193
|
+
def __init__(self, parent: tk.Misc, owner: Container, *,
|
|
194
194
|
idself: str, default: int, **options: Any):
|
|
195
195
|
ctrl = ttk.Combobox(parent)
|
|
196
196
|
super().__init__(parent, "", idself, ctrl)
|
|
@@ -237,12 +237,12 @@ class ListboxCtrl(tkControl):
|
|
|
237
237
|
|
|
238
238
|
|
|
239
239
|
class RadioButtonCtrl(tkControl):
|
|
240
|
-
def __init__(self, parent: tk.Misc, owner:
|
|
240
|
+
def __init__(self, parent: tk.Misc, owner: Container, idself: str, *,
|
|
241
241
|
text: str, vartext: str, value: int, **options: Any):
|
|
242
242
|
ctrl = ttk.Radiobutton(parent)
|
|
243
243
|
tkControl.__init__(self, parent, "", idself, ctrl)
|
|
244
244
|
# self._app: GuiBasic = app
|
|
245
|
-
self._master:
|
|
245
|
+
self._master: Container = owner
|
|
246
246
|
self._vartext: str = vartext
|
|
247
247
|
if self._vartext not in self._master.__dict__:
|
|
248
248
|
self._master.__dict__[self._vartext] = tk.IntVar()
|
|
@@ -258,7 +258,7 @@ class RadioButtonCtrl(tkControl):
|
|
|
258
258
|
|
|
259
259
|
|
|
260
260
|
class RadioButtonGroupCtrl(tkControl):
|
|
261
|
-
def __init__(self, parent: tk.Misc, app: WinBasic, owner:
|
|
261
|
+
def __init__(self, parent: tk.Misc, app: WinBasic, owner: Container, idself: str, *,
|
|
262
262
|
text: str, subctrlcfg: et.Element,
|
|
263
263
|
level: int, **options: Any):
|
|
264
264
|
ctrl = ttk.LabelFrame(parent)
|
|
@@ -267,7 +267,7 @@ class RadioButtonGroupCtrl(tkControl):
|
|
|
267
267
|
# self._var_val: tk.IntVar = tk.IntVar()
|
|
268
268
|
self._vartext: str = "_var" + text.replace(" ", "_")
|
|
269
269
|
self._app: WinBasic = app
|
|
270
|
-
self._owner:
|
|
270
|
+
self._owner: Container = owner
|
|
271
271
|
# pv(options)
|
|
272
272
|
_ = self.configure(text=text, **options)
|
|
273
273
|
# self._radbutton_lst: list[ttk.Radiobutton] = []
|
|
@@ -309,7 +309,7 @@ class RadioButtonGroupCtrl(tkControl):
|
|
|
309
309
|
|
|
310
310
|
|
|
311
311
|
class NotebookCtrl(tkControl):
|
|
312
|
-
def __init__(self, parent: tk.Misc, app: WinBasic, owner:
|
|
312
|
+
def __init__(self, parent: tk.Misc, app: WinBasic, owner: Container, idself: str, *,
|
|
313
313
|
subctrlcfg_list: list[et.Element], level: int, **options: Any):
|
|
314
314
|
ctrl = ttk.Notebook(parent, **options)
|
|
315
315
|
tkControl.__init__(self, parent, "", idself, ctrl)
|
|
@@ -650,16 +650,15 @@ class tkWM(Generic[T], Widget):
|
|
|
650
650
|
class DialogCtrl(Dialog):
|
|
651
651
|
def __init__(self, app: tkWin, dlg_cfg: et.Element):
|
|
652
652
|
attr_dict = dlg_cfg.attrib
|
|
653
|
-
super().__init__(attr_dict.get("text", ""), int(attr_dict["Width"]),
|
|
653
|
+
super().__init__(attr_dict.get("text", ""), int(attr_dict["Width"]), int(attr_dict["Height"]), app)
|
|
654
654
|
# options: dict[str, Any] = {}
|
|
655
655
|
# if "options" in attr_dict:
|
|
656
656
|
# options = eval(attr_dict["options"])
|
|
657
657
|
self._parent: tk.Tk | tk.Toplevel = app.win
|
|
658
658
|
# self._owner: Dialog | None = None
|
|
659
|
-
self._xx: int = 0
|
|
660
|
-
self._yy: int = 0
|
|
659
|
+
# self._xx: int = 0
|
|
660
|
+
# self._yy: int = 0
|
|
661
661
|
self._top: tkWM[tk.Toplevel] | None = None
|
|
662
|
-
self._app: tkWin = app
|
|
663
662
|
self._alive: bool = False
|
|
664
663
|
self._idself: str = attr_dict["id"]
|
|
665
664
|
self._subctrlcfg_list: list[et.Element] = list(dlg_cfg)
|
|
@@ -673,9 +672,8 @@ class DialogCtrl(Dialog):
|
|
|
673
672
|
# else:
|
|
674
673
|
# return self._app
|
|
675
674
|
|
|
676
|
-
@override
|
|
677
675
|
def set_title(self, val: str):
|
|
678
|
-
|
|
676
|
+
self._title = val
|
|
679
677
|
if self._top is not None:
|
|
680
678
|
self._top.control.title(self._title)
|
|
681
679
|
|
|
@@ -706,53 +704,46 @@ class DialogCtrl(Dialog):
|
|
|
706
704
|
# self.withdraw()
|
|
707
705
|
iddlg = self._idself
|
|
708
706
|
|
|
709
|
-
frmdlg_xml = self.
|
|
707
|
+
frmdlg_xml = self.create_xml("Top", {})
|
|
710
708
|
|
|
711
709
|
id_frmain = f"frmMain{iddlg}"
|
|
712
710
|
# frmain_xml = self._app.create_xml("Frame", {"id": id_frmain}, frmdlg_xml)
|
|
713
|
-
frmain_xml = self.
|
|
711
|
+
frmain_xml = self.create_xml("ScrollableFrame", {"id": id_frmain,
|
|
714
712
|
"Width": f"{self._ww-30}", "Height": f"{self._hh-160}"}, frmdlg_xml)
|
|
715
|
-
_, frmmain_ctrl = self.
|
|
716
|
-
frmain_xml, 0
|
|
713
|
+
_, frmmain_ctrl = self.create_control(self._top,
|
|
714
|
+
frmain_xml, 0)
|
|
717
715
|
# self._idctrl_list.append(id_frmain)
|
|
718
716
|
self._idctrl_dict[id_frmain] = frmmain_ctrl
|
|
719
717
|
# frm_main = cast(tkControl, frmmain).control
|
|
720
718
|
# frm_main = cast(tkControl, frmmain_ctrl)
|
|
721
719
|
|
|
722
720
|
for sub_ctrl in self._subctrlcfg_list:
|
|
723
|
-
|
|
724
|
-
# self._idctrl_list.extend(subidctrl_list)
|
|
725
|
-
self._idctrl_dict.update(subidctrl_dict)
|
|
721
|
+
_ = self.create_controls(frmmain_ctrl, sub_ctrl, 1)
|
|
726
722
|
|
|
727
|
-
_ = self.
|
|
723
|
+
_ = self.assemble_control(frmmain_ctrl, {"layout": "pack",
|
|
728
724
|
"pack": "{'side':'top','fill':'both','expand':True,'padx':5,'pady':5}"})
|
|
729
725
|
|
|
730
|
-
frmbot_xml = self.
|
|
731
|
-
|
|
732
|
-
frmbot_xml, 0
|
|
733
|
-
# self._idctrl_list.append(id_frmbot)
|
|
734
|
-
self._idctrl_dict[id_frmbot] = frmbot_ctrl
|
|
726
|
+
frmbot_xml = self.create_xml("Frame", {"id": f"frmBot{iddlg}"}, frmdlg_xml)
|
|
727
|
+
_, frmbot_ctrl = self.create_control(self._top,
|
|
728
|
+
frmbot_xml, 0)
|
|
735
729
|
|
|
736
|
-
btnConfirm_xml = self.
|
|
730
|
+
btnConfirm_xml = self.create_xml("Button", {"id": f"btnConfirm{iddlg}",
|
|
737
731
|
"text": "Confirm", "options": "{'width':20}"}, frmbot_xml)
|
|
738
|
-
id_btnconfirm, btnConfirm_ctrl = self.
|
|
739
|
-
btnConfirm_xml, 1
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
_ = self._app.assemble_control(btnConfirm_ctrl, {"layout":"pack",
|
|
732
|
+
id_btnconfirm, btnConfirm_ctrl = self.create_control(frmbot_ctrl,
|
|
733
|
+
btnConfirm_xml, 1)
|
|
734
|
+
|
|
735
|
+
_ = self.assemble_control(btnConfirm_ctrl, {"layout":"pack",
|
|
743
736
|
"pack":"{'side':'right','fill':'both','expand':True,'padx':5,'pady':5}"}, f"{' '*1}")
|
|
744
737
|
|
|
745
|
-
bntcancel_xml = self.
|
|
738
|
+
bntcancel_xml = self.create_xml("Button", {"id": f"btnCancel{iddlg}",
|
|
746
739
|
"text": "Cancel", "options": "{'width':20}"}, frmbot_xml)
|
|
747
|
-
id_btncancel, btncancel_ctrl = self.
|
|
748
|
-
bntcancel_xml, 1
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
# pv(self._idctrl_list)
|
|
752
|
-
_ = self._app.assemble_control(btncancel_ctrl, {"layout":"pack",
|
|
740
|
+
id_btncancel, btncancel_ctrl = self.create_control(frmbot_ctrl,
|
|
741
|
+
bntcancel_xml, 1)
|
|
742
|
+
|
|
743
|
+
_ = self.assemble_control(btncancel_ctrl, {"layout":"pack",
|
|
753
744
|
"pack":"{'side':'right','fill':'both','expand':True,'padx':5,'pady':5}"}, f"{' '*1}")
|
|
754
745
|
|
|
755
|
-
_ = self.
|
|
746
|
+
_ = self.assemble_control(frmbot_ctrl, {"layout": "pack",
|
|
756
747
|
"pack": "{'side':'bottom','fill':'x','expand':True,'padx':5,'pady':5}"})
|
|
757
748
|
|
|
758
749
|
self._extral_msg = kwargs
|
|
@@ -783,9 +774,6 @@ class DialogCtrl(Dialog):
|
|
|
783
774
|
self._top.control.wait_window()
|
|
784
775
|
# pv(self._id_list)
|
|
785
776
|
|
|
786
|
-
def get_control(self, idctrl: str) -> object:
|
|
787
|
-
return self._app.get_control(idctrl)
|
|
788
|
-
|
|
789
777
|
def _do_cancel(self, **kwargs: object):
|
|
790
778
|
# po(f"Dialog {self._idself} _do_cancel")
|
|
791
779
|
self.destroy(confirm=False, **kwargs)
|
|
@@ -954,9 +942,8 @@ class tkWin(WinBasic):
|
|
|
954
942
|
# 设置窗口大小并居中
|
|
955
943
|
self._win.geometry(f"{width}x{hight}+{cen_x}+{cen_y}")
|
|
956
944
|
|
|
957
|
-
@override
|
|
958
945
|
def set_title(self, val: str):
|
|
959
|
-
|
|
946
|
+
self._title = val
|
|
960
947
|
self._win.title(self._title)
|
|
961
948
|
|
|
962
949
|
@override
|
|
@@ -970,7 +957,7 @@ class tkWin(WinBasic):
|
|
|
970
957
|
|
|
971
958
|
@override
|
|
972
959
|
def create_control(self, parent: Widget, ctrl_cfg: et.Element,
|
|
973
|
-
level: int = 0, owner:
|
|
960
|
+
level: int = 0, owner: Container | None = None) -> tuple[str, Widget]:
|
|
974
961
|
if owner is None:
|
|
975
962
|
owner = self
|
|
976
963
|
tag = ctrl_cfg.tag
|
|
@@ -81,13 +81,17 @@ class Control(Widget, metaclass=abc.ABCMeta):
|
|
|
81
81
|
pass
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
class Container(Widget):
|
|
84
|
+
class Container(Widget, metaclass=abc.ABCMeta):
|
|
85
85
|
def __init__(self, owner: Container | None = None):
|
|
86
86
|
super().__init__()
|
|
87
87
|
self._eventhandler_dict: dict[str, list[EventHanlder]] = {}
|
|
88
88
|
self._msgs_hanlders: list[tuple[int, list[str], EventsHanlder]] = []
|
|
89
89
|
self._owner: Container | None = owner
|
|
90
90
|
|
|
91
|
+
self._backed: bool = True
|
|
92
|
+
|
|
93
|
+
self._idctrl_dict: OrderedDict[str, Widget] = OrderedDict()
|
|
94
|
+
|
|
91
95
|
@property
|
|
92
96
|
def owner(self):
|
|
93
97
|
return self._owner
|
|
@@ -96,6 +100,15 @@ class Container(Widget):
|
|
|
96
100
|
def owner(self, val: "Container"):
|
|
97
101
|
self._owner = val
|
|
98
102
|
|
|
103
|
+
def back(self, bset: bool = True):
|
|
104
|
+
for idctrl, ctrl in self._idctrl_dict.items():
|
|
105
|
+
try:
|
|
106
|
+
ctrl = cast(Control, ctrl).back(bset)
|
|
107
|
+
except AttributeError as _:
|
|
108
|
+
# po(f"{idctrl} doesn't support back")
|
|
109
|
+
print(f"{idctrl} doesn't support back")
|
|
110
|
+
self._backed = bset
|
|
111
|
+
|
|
99
112
|
def register_eventhandler(self, idmsg: str, handler: EventHanlder):
|
|
100
113
|
"""_summary_
|
|
101
114
|
|
|
@@ -155,73 +168,9 @@ class Container(Widget):
|
|
|
155
168
|
|
|
156
169
|
if self._owner is not None:
|
|
157
170
|
return self._owner.process_message(idmsg, **kwargs)
|
|
158
|
-
|
|
171
|
+
print(f"Container: undeal msg of {idmsg} with {kwargs}")
|
|
159
172
|
return None
|
|
160
173
|
|
|
161
|
-
|
|
162
|
-
class Dialog(Container, metaclass=abc.ABCMeta):
|
|
163
|
-
def __init__(self, title: str, width: int, height: int):
|
|
164
|
-
super().__init__()
|
|
165
|
-
self._xx: int = 0
|
|
166
|
-
self._yy: int = 0
|
|
167
|
-
self._title: str = title
|
|
168
|
-
self._ww: int = width
|
|
169
|
-
self._hh: int = height
|
|
170
|
-
self._backed: bool = True
|
|
171
|
-
self._idctrl_dict: OrderedDict[str, Widget] = OrderedDict()
|
|
172
|
-
|
|
173
|
-
@property
|
|
174
|
-
def title(self):
|
|
175
|
-
return self._title
|
|
176
|
-
|
|
177
|
-
def set_title(self, val: str):
|
|
178
|
-
self._title = val
|
|
179
|
-
|
|
180
|
-
@property
|
|
181
|
-
def pos(self):
|
|
182
|
-
return self._xx, self._yy
|
|
183
|
-
|
|
184
|
-
@property
|
|
185
|
-
def size(self):
|
|
186
|
-
return self._ww, self._hh
|
|
187
|
-
|
|
188
|
-
@property
|
|
189
|
-
def backed(self):
|
|
190
|
-
return self._backed
|
|
191
|
-
|
|
192
|
-
def back(self, bset: bool = True):
|
|
193
|
-
for idctrl, ctrl in self._idctrl_dict.items():
|
|
194
|
-
try:
|
|
195
|
-
ctrl = cast(Control, ctrl).back(bset)
|
|
196
|
-
except AttributeError as _:
|
|
197
|
-
# po(f"{idctrl} doesn't support back")
|
|
198
|
-
print(f"{idctrl} doesn't support back")
|
|
199
|
-
self._backed = bset
|
|
200
|
-
|
|
201
|
-
def _beforego(self, **kwargs: object):
|
|
202
|
-
_ = super().process_message("beforego", **kwargs)
|
|
203
|
-
|
|
204
|
-
def _confirm(self, **kwargs: object) -> tuple[bool, str]:
|
|
205
|
-
return cast(tuple[bool, str], super().process_message("confirm", **kwargs))
|
|
206
|
-
|
|
207
|
-
def _cancel(self, **kwargs: object) -> tuple[bool, str]:
|
|
208
|
-
return cast(tuple[bool, str], super().process_message("cancel", **kwargs))
|
|
209
|
-
|
|
210
|
-
@override
|
|
211
|
-
def process_message(self, idmsg: str, **kwargs: object):
|
|
212
|
-
match idmsg:
|
|
213
|
-
case "beforego":
|
|
214
|
-
self._beforego(**kwargs)
|
|
215
|
-
case "confirm":
|
|
216
|
-
return self._confirm(**kwargs)
|
|
217
|
-
case "cancel":
|
|
218
|
-
return self._cancel(**kwargs)
|
|
219
|
-
case _:
|
|
220
|
-
# if self._owner is not None:
|
|
221
|
-
# return self._owner.process_message(idmsg, **kwargs)
|
|
222
|
-
return super().process_message(idmsg, **kwargs)
|
|
223
|
-
return True
|
|
224
|
-
|
|
225
174
|
@abc.abstractmethod
|
|
226
175
|
def destroy(self, **kwargs: object):
|
|
227
176
|
# self._eventhandler_dict.clear()
|
|
@@ -231,7 +180,7 @@ class Dialog(Container, metaclass=abc.ABCMeta):
|
|
|
231
180
|
pass
|
|
232
181
|
|
|
233
182
|
|
|
234
|
-
class WinBasic(
|
|
183
|
+
class WinBasic(Container, metaclass=abc.ABCMeta):
|
|
235
184
|
def __init__(self, xmlfile: str):
|
|
236
185
|
element_tree = et.parse(xmlfile)
|
|
237
186
|
self._wincfg: et.Element[str] = element_tree.getroot()
|
|
@@ -240,10 +189,32 @@ class WinBasic(Dialog, metaclass=abc.ABCMeta):
|
|
|
240
189
|
w, h = int(win_attr["Width"]), int(win_attr["Height"])
|
|
241
190
|
else:
|
|
242
191
|
w, h = 0, 0
|
|
243
|
-
|
|
192
|
+
super().__init__()
|
|
244
193
|
|
|
245
194
|
self._customctrl_dict: dict[str, et.Element] = {}
|
|
246
195
|
|
|
196
|
+
self._xx: int = 0
|
|
197
|
+
self._yy: int = 0
|
|
198
|
+
self._ww: int = w
|
|
199
|
+
self._hh: int = h
|
|
200
|
+
self._title: str = win_attr["Title"]
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def title(self):
|
|
204
|
+
return self._title
|
|
205
|
+
|
|
206
|
+
@title.setter
|
|
207
|
+
def title(self, val: str):
|
|
208
|
+
self._title = val
|
|
209
|
+
|
|
210
|
+
@property
|
|
211
|
+
def pos(self):
|
|
212
|
+
return self._xx, self._yy
|
|
213
|
+
|
|
214
|
+
@property
|
|
215
|
+
def size(self):
|
|
216
|
+
return self._ww, self._hh
|
|
217
|
+
|
|
247
218
|
@abc.abstractmethod
|
|
248
219
|
def create_window(self):
|
|
249
220
|
pass
|
|
@@ -258,7 +229,7 @@ class WinBasic(Dialog, metaclass=abc.ABCMeta):
|
|
|
258
229
|
|
|
259
230
|
@abc.abstractmethod
|
|
260
231
|
def create_control(self, parent: Widget, ctrl_cfg: et.Element,
|
|
261
|
-
level: int = 0, owner:
|
|
232
|
+
level: int = 0, owner: Container | None = None) -> tuple[str, Widget]:
|
|
262
233
|
pass
|
|
263
234
|
|
|
264
235
|
@abc.abstractmethod
|
|
@@ -266,7 +237,7 @@ class WinBasic(Dialog, metaclass=abc.ABCMeta):
|
|
|
266
237
|
pass
|
|
267
238
|
|
|
268
239
|
def create_controls(self, parent: Widget, ctrl_cfg: et.Element,
|
|
269
|
-
level: int = 0, owner:
|
|
240
|
+
level: int = 0, owner: Container | None = None) -> OrderedDict[str, Widget]:
|
|
270
241
|
idctrl_dict: OrderedDict[str, Widget] = OrderedDict()
|
|
271
242
|
tag = ctrl_cfg.tag
|
|
272
243
|
if tag == "CustomDialog":
|
|
@@ -293,7 +264,7 @@ class WinBasic(Dialog, metaclass=abc.ABCMeta):
|
|
|
293
264
|
ctrl.destroy()
|
|
294
265
|
except AttributeError:
|
|
295
266
|
# po(f"Warnning: {idctrl} doesn't have destroy")
|
|
296
|
-
print(f"
|
|
267
|
+
print(f"WinBasic warnning: {idctrl} doesn't have destroy")
|
|
297
268
|
del self._idctrl_dict[idctrl]
|
|
298
269
|
|
|
299
270
|
def get_control(self, idctrl: str):
|
|
@@ -325,3 +296,84 @@ class WinBasic(Dialog, metaclass=abc.ABCMeta):
|
|
|
325
296
|
self._idctrl_dict.clear()
|
|
326
297
|
|
|
327
298
|
super().destroy(**kwargs)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
class Dialog(Container, metaclass=abc.ABCMeta):
|
|
302
|
+
def __init__(self, title: str, width: int, height: int, app: WinBasic):
|
|
303
|
+
super().__init__()
|
|
304
|
+
self._app: WinBasic = app
|
|
305
|
+
|
|
306
|
+
self._xx: int = 0
|
|
307
|
+
self._yy: int = 0
|
|
308
|
+
self._ww: int = width
|
|
309
|
+
self._hh: int = height
|
|
310
|
+
self._title: str = title
|
|
311
|
+
|
|
312
|
+
@property
|
|
313
|
+
def title(self):
|
|
314
|
+
return self._title
|
|
315
|
+
|
|
316
|
+
@title.setter
|
|
317
|
+
def title(self, val: str):
|
|
318
|
+
self._title = val
|
|
319
|
+
|
|
320
|
+
@property
|
|
321
|
+
def pos(self):
|
|
322
|
+
return self._xx, self._yy
|
|
323
|
+
|
|
324
|
+
@property
|
|
325
|
+
def size(self):
|
|
326
|
+
return self._ww, self._hh
|
|
327
|
+
|
|
328
|
+
@property
|
|
329
|
+
def backed(self):
|
|
330
|
+
return self._backed
|
|
331
|
+
|
|
332
|
+
def _beforego(self, **kwargs: object):
|
|
333
|
+
_ = super().process_message("beforego", **kwargs)
|
|
334
|
+
|
|
335
|
+
def create_xml(self, tag: str, attr_dict: dict[str, str], root: et.Element | None = None) -> et.Element:
|
|
336
|
+
return self._app.create_xml(tag, attr_dict, root)
|
|
337
|
+
|
|
338
|
+
def create_controls(self, parent: Widget, ctrl_cfg: et.Element,
|
|
339
|
+
level: int = 0) -> OrderedDict[str, Widget]:
|
|
340
|
+
subidctrl_dict = self._app.create_controls(parent,ctrl_cfg, level, self)
|
|
341
|
+
self._idctrl_dict.update(subidctrl_dict)
|
|
342
|
+
return subidctrl_dict
|
|
343
|
+
|
|
344
|
+
def create_control(self, parent: Widget, ctrl_cfg: et.Element,
|
|
345
|
+
level: int = 0) -> tuple[str, Widget]:
|
|
346
|
+
id_ctrl, ctrl = self._app.create_control(parent, ctrl_cfg, level, self)
|
|
347
|
+
self._idctrl_dict[id_ctrl] = ctrl
|
|
348
|
+
return id_ctrl, ctrl
|
|
349
|
+
|
|
350
|
+
def assemble_control(self, ctrl: Widget, attr_dict: dict[str, str], prefix: str = ""):
|
|
351
|
+
return self._app.assemble_control(ctrl, attr_dict, prefix)
|
|
352
|
+
|
|
353
|
+
def get_control(self, idctrl: str) -> object:
|
|
354
|
+
return self._app.get_control(idctrl)
|
|
355
|
+
|
|
356
|
+
def delete_control(self, idctrl: str):
|
|
357
|
+
self._app.delete_control(idctrl)
|
|
358
|
+
del self._idctrl_dict[idctrl]
|
|
359
|
+
|
|
360
|
+
def _confirm(self, **kwargs: object) -> tuple[bool, str]:
|
|
361
|
+
return cast(tuple[bool, str], super().process_message("confirm", **kwargs))
|
|
362
|
+
|
|
363
|
+
def _cancel(self, **kwargs: object) -> tuple[bool, str]:
|
|
364
|
+
return cast(tuple[bool, str], super().process_message("cancel", **kwargs))
|
|
365
|
+
|
|
366
|
+
@override
|
|
367
|
+
def process_message(self, idmsg: str, **kwargs: object):
|
|
368
|
+
match idmsg:
|
|
369
|
+
case "beforego":
|
|
370
|
+
self._beforego(**kwargs)
|
|
371
|
+
case "confirm":
|
|
372
|
+
return self._confirm(**kwargs)
|
|
373
|
+
case "cancel":
|
|
374
|
+
return self._cancel(**kwargs)
|
|
375
|
+
case _:
|
|
376
|
+
# if self._owner is not None:
|
|
377
|
+
# return self._owner.process_message(idmsg, **kwargs)
|
|
378
|
+
return super().process_message(idmsg, **kwargs)
|
|
379
|
+
return True
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|