-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgressDialog.py
More file actions
64 lines (51 loc) · 2.62 KB
/
ProgressDialog.py
File metadata and controls
64 lines (51 loc) · 2.62 KB
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
from MasyuDialog import *
import tkinter as tk
from threading import Thread
from PuzzleBoard import *
from CanvasManager import *
# This class is for a debugging modal dialog, which can be used
# to display the interim results produced during the solving process.
# While displayed, the solving process is suspended, until this
# dialog has been closed.
class ProgressDialog(MasyuDialog):
def __init__(self, parentWindow, puzzleBoard, cancelEvent, resumeEvent):
super().__init__(parentWindow)
self.__puzzleBoard = puzzleBoard
self.__cancelEvent = cancelEvent
self.__resumeEvent = resumeEvent
def cancelHandler(self):
self.__cancelButton['state'] = tk.DISABLED
self.__cancelEvent.set()
self.__toplevel.destroy()
def resumeHandler(self):
self.__resumeButton['state'] = tk.DISABLED
self.__resumeEvent.set()
self.__toplevel.destroy()
def showDialog(self):
self.__toplevel = tk.Toplevel()
self.__toplevel.protocol("WM_DELETE_WINDOW", self.cancelHandler)
puzzleBoardFrame = tk.Frame(master=self.__toplevel, relief=tk.RAISED, highlightthickness=0, borderwidth=10)
puzzleBoardFrame.grid(row=0, column=0)
# Create the Canvas in which the Puzzle Board will be drawn
self.__puzzleBoardCanvas = tk.Canvas(master=puzzleBoardFrame, height=300, width=300,
highlightthickness=0, relief=tk.FLAT, borderwidth=0)
self.__puzzleBoardCanvas.grid(row=0, column=0)
self.__canvasManager = CanvasManager(self.__puzzleBoardCanvas, True, True, True)
self.__canvasManager.registerPuzzleBoard(self.__puzzleBoard)
buttonFrame = tk.Frame(master=self.__toplevel, relief=tk.RAISED, borderwidth=0)
buttonFrame.grid(row=1, column=0)
self.__cancelButton = tk.Button(buttonFrame, text="Cancel", command=self.cancelHandler, width=10)
self.__cancelButton.grid(row=0, column=0, padx=(2, 35), pady=(15, 15), sticky="e")
self.__resumeButton = tk.Button(buttonFrame, text="Resume", command=self.resumeHandler, width=10)
self.__resumeButton.grid(row=0, column=1, padx=(2, 35), pady=(15, 15), sticky="e")
super().showDialog(self.__toplevel)
if __name__ == '__main__':
def showDialog():
pb = PuzzleBoard(size=(10,10))
progressDialog = ProgressDialog(mainWindow, pb, None, None)
progressDialog.showDialog()
mainWindow = tk.Tk()
mainWindow.title('Dialog Test')
showDialogButton = tk.Button(master=mainWindow, text="Show Dialog", command=showDialog)
showDialogButton.grid(row=0, column=0)
mainWindow.mainloop()