blob: bc939d88163366de3003591b30cb569f48494688 [file] [log] [blame]
Philipp Le84173f62022-04-19 22:27:12 +02001# SPDX-License-Identifier: MPL-2.0
2# Copyright (c) 2022 Philipp Le <philipp@philipple.de>.
3# This Source Code Form is subject to the terms of the Mozilla Public
4# License, v. 2.0. If a copy of the MPL was not distributed with this
5# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7import logging
8from tkinter import ttk, Tk, Toplevel, BOTH
9from typing import Type, List
10
11
12class Group:
13 NAME: str
14
15
16class BaseFrame(ttk.Frame):
17 pass
18
19
20class Window:
21 GROUP: Type[Group]
22 TITLE: str
23 FRAME: Type[BaseFrame]
24
25 @classmethod
26 def make_title(cls) -> str:
27 return f'{cls.GROUP.NAME} - {cls.TITLE}'
28
29 @classmethod
30 def make_frame(cls, root) -> ttk.Frame:
31 frm = cls.FRAME(root)
32 frm.pack(expand=True, fill=BOTH)
33 return frm
34
35 @classmethod
36 def make_window(cls, root) -> Toplevel:
37 win = Toplevel(root)
38 win.title(cls.make_title())
39 cls.make_frame(win)
40 return win
41
42 @classmethod
43 def main(cls):
44 logging.basicConfig(level=logging.INFO)
45
46 root = Tk()
47 root.title(cls.make_title())
48 cls.make_frame(root)
49 root.mainloop()
50
51
52def get_groups(win_cls: List[Type[Window]]) -> List[Type[Group]]:
53 grp_cls: List[Type[Group]] = []
54 for win in win_cls:
55 if win.GROUP not in grp_cls:
56 grp_cls.append(win.GROUP)
57 return list(sorted(grp_cls, key=lambda grp: grp.NAME))
58
59
60def get_win_of_group(win_cls: List[Type[Window]], grp: Type[Group]) -> List[Type[Window]]:
61 return list(filter(lambda win: win.GROUP == grp, win_cls))