-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmediator.py
85 lines (63 loc) · 1.84 KB
/
mediator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# --------------------------------------------------------
# Licensed under the terms of the BSD 3-Clause License
# (see LICENSE for details).
# Copyright © 2018-2024, A.A Suvorov
# All rights reserved.
# --------------------------------------------------------
# https://github.com/smartlegionlab/
# --------------------------------------------------------
"""Mediator"""
class WindowBase:
def show(self):
raise NotImplementedError()
def hide(self):
raise NotImplementedError()
class MainWindow(WindowBase):
def show(self):
print('Show MainWindow')
def hide(self):
print('Hide MainWindow')
class SettingWindow(WindowBase):
def show(self):
print('Show SettingWindow')
def hide(self):
print('Hide SettingWindow')
class HelpWindow(WindowBase):
def show(self):
print('Show HelpWindow')
def hide(self):
print('Hide HelpWindow')
class WindowMediator:
def __init__(self):
self.windows = dict.fromkeys(['main', 'setting', 'help'])
def show(self, win):
for window in self.windows.values():
if window is not win:
window.hide()
win.show()
def set_main(self, win):
self.windows['main'] = win
def set_setting(self, win):
self.windows['setting'] = win
def set_help(self, win):
self.windows['help'] = win
def main():
main_win = MainWindow()
setting_win = SettingWindow()
help_win = HelpWindow()
med = WindowMediator()
med.set_main(main_win)
med.set_setting(setting_win)
med.set_help(help_win)
main_win.show()
# Show MainWindow
med.show(setting_win)
# Hide MainWindow
# Hide HelpWindow
# Show SettingWindow
med.show(help_win)
# Hide MainWindow
# Hide SettingWindow
# Show HelpWindow
if __name__ == '__main__':
main()