- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
Latest commit
80 lines (64 loc) · 2.31 KB
/
Copy pathmain.py
File metadata and controls
80 lines (64 loc) · 2.31 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# main.py
# imports
importos
importmath
importjson
importpickle
importrandom
importpygame
fromcollectionsimportdeque
# globals
fromuiimportUI
fromglobyimport*
# sub classes
frommazeimportMazeSolve
fromsortingimportSorting
fromgraphimportGraphSearch
fromgraph_toolsimport*
# pygame gui
importpygame_gui
frompygame_gui.elementsimportUILabel
frompygame_gui.elementsimportUIImage
frompygame_gui.elementsimportUIPanel
frompygame_gui.elementsimportUIWindow
frompygame_gui.elementsimportUIButton
frompygame_gui.elementsimportUITextBox
frompygame_gui.elementsimportUIDropDownMenu
frompygame_gui.windowsimportUIMessageWindow
frompygame_gui.elementsimportUISelectionList
frompygame_gui.elementsimportUITextEntryLine
frompygame_guiimportUIManager, PackageResource
frompygame_gui.elementsimportUIHorizontalSlider
frompygame_gui.elementsimportUIScreenSpaceHealthBar
classAlgorithmVisualizer:
def__init__(self):
self.running=True
self.ui=UI()
self.new_topic=None
self.current_topic=Options.topics[Options.start_topic]
self.topic_objects= {Options.topics[0]: Sorting(self.ui), Options.topics[1]: GraphSearch(self.ui), Options.topics[2]: MazeSolve(self.ui)}
defrun(self):
"""
This run function calls the run function of the topic classes. [ex: Sorting(self.ui).run()]
Whenever there is a change in the topic, the topic class returns to this function's while
loop and this function redirects it to the new topics topic-class and its run function.
"""
ifOptions.ui_only_mode:
whileself.running:
# process events
foreventinpygame.event.get():
ifevent.type==pygame.QUIT:
self.running=False
self.ui.manager.process_events(event)
# update-render
self.ui.update()
self.ui.render()
pygame.display.update()
else:
whileself.running:
self.ui.enable_start()
self.running=self.topic_objects[self.current_topic].run()
self.current_topic=self.ui.get_dropdown_topic()
if__name__=="__main__":
app=AlgorithmVisualizer()
app.run()