-
Notifications
You must be signed in to change notification settings - Fork 1
/
QTclPopupWindow.py
110 lines (92 loc) · 3.84 KB
/
QTclPopupWindow.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from QImpWindowBasics import *
class QTclPopupWindow(QTclWindowBasics, tk.Toplevel):
"""base class for all pop up windows
"""
def __init__(self, parent, title, is_modal=True):
self.parent = parent
self.root = parent.root
self.row = 0
super().__init__(parent, padx=5, pady=5)
self.root.grid_columnconfigure(0, weight=1)
self.root.grid_rowconfigure(0, weight=1)
self.root.resizable(True, True)
self.root.rowconfigure(0, weight=1)
self.root.columnconfigure(0, weight=1)
self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
parent.winfo_rooty()+50))
self.protocol("WM_DELETE_WINDOW", self.cancel)
self.make_gui(title)
self.focus_set()
self.loaded()
if is_modal:
self.grab_set()
self.wait_window(self)
def setwintitle(self, title):
"""Sets the title of your main window
"""
self.title(title)
def loaded(self):
raise TclWinBaseUsageException("Override me! Always override loaded method")
def make_gui(self, title):
raise TclWinBaseUsageException("Override me! Always override loaded method")
def add_std_buttons(self, okcol=None, cancelcol=None, dismisscol=None, yescol=None, nocol=None, row=None, padx=(5,5), pady=(5,5)):
if row == None:
raise Exception("Missing in row")
if okcol != None:
self.bind('<Return>', self.ok_event)
self.makebutton(erow=row, ecol=okcol,
width=5,
caption='OK',
cmd=self.ok_pressed,
sticky=tk.E,
padx=padx,
pady=pady)
if cancelcol != None:
self.bind('<Escape>', self.cancel_event)
self.makebutton(erow=row, ecol=cancelcol,
width=5,
caption='Cancel',
cmd=self.cancel_pressed,
sticky=tk.W,
padx=padx,
pady=pady)
if yescol != None:
self.bind('<Return>', self.ok_event)
self.makebutton(erow=row, ecol=yescol,
width=5,
caption='Yes',
cmd=self.ok_pressed,
sticky=tk.E,
padx=padx,
pady=pady)
if nocol != None:
self.bind('<Escape>', self.cancel_event)
self.makebutton(erow=row, ecol=nocol,
width=5,
caption='No',
cmd=self.cancel_pressed,
sticky=tk.W,
padx=padx,
pady=pady)
if dismisscol != None:
self.bind('<Escape>', self.cancel_event)
self.makebutton(erow=row, ecol=dismisscol,
width=7,
caption='Dismiss',
cmd=self.cancel_pressed,
padx=padx,
pady=pady)
def cancel(self, event=None):
# put focus back to the parent window
self.parent.focus_set()
self.destroy()
def ok_pressed(self):
self.dresult = "OK"
self.destroy()
def cancel_pressed(self):
self.dresult = "CANCEL"
self.destroy()
def ok_event(self, event):
self.ok_pressed()
def cancel_event(self, event):
self.cancel_pressed()