-
Notifications
You must be signed in to change notification settings - Fork 1
/
PathVision.py
133 lines (97 loc) · 3.45 KB
/
PathVision.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import math
import random
import threading
import tkinter
import time
import sys
import networkx as nx
from settings import *
from modes.explorationMode import ExplorationMode
from modes.simulationMode import SimulationMode
class App(tkinter.Frame):
def __init__(self):
tkinter.Frame.__init__(self)
# Setup the master frame
self.master.title("PathVision")
self.grid(row=0,column=0,sticky="NESW",padx=OUT_PADDING,pady=OUT_PADDING)
self.master.rowconfigure(0,weight=1)
self.master.columnconfigure(0,weight=1)
self.setup_themes()
self.setup_menubar()
self.simulationMode = SimulationMode(self, self)
self.explorationMode = ExplorationMode(self, self)
# Setup window events
self.master.protocol("WM_DELETE_WINDOW", self.on_close)
self.bind("<Configure>", self.on_resize)
self.rowconfigure(0,weight=1)
self.columnconfigure(0,weight=1)
self.activate_simulation()
self.simulationMode.storageController._load("examples/quadratic.pv")
#self.explorationMode.storageController._load("test.alg")
tkinter.mainloop()
def setup_themes(self):
# Choose ttk themes
for theme in ["aqua","vista","xpnative","clam"]:
if theme in tkinter.ttk.Style().theme_names():
tkinter.ttk.Style().theme_use(theme)
break
def setup_menubar(self):
self._menubar = tkinter.Menu(self)
fileMenu = tkinter.Menu(self._menubar, tearoff=False)
fileMenu.add_command(label="Quit", command=self.on_close)
self._menubar.add_cascade(label="File", menu=fileMenu)
modeMenu = tkinter.Menu(self._menubar, tearoff=False)
modeMenu.add_radiobutton(label="Simulate", command=self.activate_simulation)
modeMenu.add_radiobutton(label="Explore", command=self.activate_exploration)
self._menubar.add_cascade(label="Mode", menu=modeMenu)
helpMenu = tkinter.Menu(self._menubar, tearoff=False)
self._menubar.add_cascade(label="Help", menu=helpMenu)
self.master.config(menu=self._menubar)
################
## App events ##
################
def activate_simulation(self):
self.explorationMode.grid_remove()
self.simulationMode.grid(row=0, column=0, sticky="NESW")
self.simulationMode.activate()
self.currentMode = self.simulationMode
def activate_exploration(self):
self.simulationMode.grid_remove()
self.explorationMode.grid(row=0, column=0, sticky="NESW")
self.explorationMode.activate()
self.currentMode = self.explorationMode
###################
## Window events ##
###################
def on_resize(self, e):
self.simulationMode.draw()
def on_close(self):
self.destroy()
quit()
if __name__ == '__main__':
App()
"""
"""
"""
def displayHelp(self):
window = tkinter.Toplevel(self)
window.wm_title("PathVision help")
helpText = HelpText(window)
helpText.pack(side="top", fill="both", expand=True, padx=5, pady=5)
"""
"""
import tkinter
class HelpText(tkinter.Text):
def __init__(self, parent):
tkinter.Text.__init__(self, parent, bg="#ddd", wrap=tkinter.WORD)
controlStr = "Controls\n\n"
controlStr += "Add node: left click on empty space\n\n"
controlStr += "Remove node: right click on node\n\n"
controlStr += "Add edge: left click on destination followed by the source\n\n"
controlStr += "Remove edge: right click on edge\n\n"
controlStr += "Change edge value: left click on edge and type\n\n"
controlStr += "Change destination: double left click on new destination node\n\n"
controlStr += "Toggle node label: middle click on node"
self.insert(tkinter.INSERT, controlStr)
self.configure(state=tkinter.DISABLED)
"""