This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
66 lines (57 loc) · 1.73 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
# ---------------------------
# - Ryan Williamson -
# - Advanced Higher Project -
# ---------------------------
# Imports
import GUI
import microbit
import tkinter
import threading
import importlib
import sys
#Variables
fileloadclose = True
simulationclose = True
#Functions
"""This function destroys the File Load GUI window"""
def CloseFileLoad():
global fileloadclose
fileloadclose = False
root.destroy()
"""This function destroys the Simulation GUI window"""
def CloseSimulationWindow():
global simulationclose
simulationclose = False
root.destroy()
"""This function runs the code in the file chosen by the user"""
def importFunction():
# If file has not been run before run it
# If the file has been run rerun it
if 'run' not in sys.modules:
import run
else:
import run
run = importlib.reload(run)
#Main code
# First window - displayed on start
root = tkinter.Tk()
MainWindow = GUI.FileLoadGUI(root)
root.protocol("WM_DELETE_WINDOW", CloseFileLoad)
root.mainloop()
# Second window - displayed when first window closed
if (fileloadclose):
while simulationclose:
# Initial Simulation setup
microbit.reset_simulation = False
microbit.panic_mode = False
root = tkinter.Tk()
SimulationWindow = GUI.SimulationGUI(root)
root.protocol("WM_DELETE_WINDOW", CloseSimulationWindow)
microbit._initTime()
# This allows the GUI to update on a regular schedule
root.after(0, SimulationWindow.UpdateMicrobit, root)
# This allows the code to be simulated to be run independantly
runthread = threading.Thread(target=importFunction)
runthread.daemon = True
runthread.start()
root.mainloop()