-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
80 lines (64 loc) · 2.31 KB
/
main.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
# main.py
# imports
import os
import math
import json
import pickle
import random
import pygame
from collections import deque
# globals
from ui import UI
from globy import *
# sub classes
from maze import MazeSolve
from sorting import Sorting
from graph import GraphSearch
from graph_tools import *
# pygame gui
import pygame_gui
from pygame_gui.elements import UILabel
from pygame_gui.elements import UIImage
from pygame_gui.elements import UIPanel
from pygame_gui.elements import UIWindow
from pygame_gui.elements import UIButton
from pygame_gui.elements import UITextBox
from pygame_gui.elements import UIDropDownMenu
from pygame_gui.windows import UIMessageWindow
from pygame_gui.elements import UISelectionList
from pygame_gui.elements import UITextEntryLine
from pygame_gui import UIManager, PackageResource
from pygame_gui.elements import UIHorizontalSlider
from pygame_gui.elements import UIScreenSpaceHealthBar
class AlgorithmVisualizer:
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)}
def run(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.
"""
if Options.ui_only_mode:
while self.running:
# process events
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
self.ui.manager.process_events(event)
# update-render
self.ui.update()
self.ui.render()
pygame.display.update()
else:
while self.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()