-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.pyw
96 lines (69 loc) · 2.77 KB
/
main.pyw
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
# author: a5892731
# date: 11.05.2022
# last update: 22.02.2023
# version: 2.0
#
# description:
# This is a simple template for programs with Graphic User Interface
'''
imports
-tkinter: pip install tk
-PIL: pip install pillow
'''
from tkinter import Tk
from threading import Thread, BoundedSemaphore
'''init states machine'''
from resources.state_machine.machine1.read_machine_loader import ReadUDPmachine
from resources.state_machine.machine2.program_machine_loader import ProgramMachine
from resources.state_machine.machine3.send_machine_loader import SendUDPmachine
'''init data buffer'''
from resources.state_machine.states_data_buffer import StatesDataBuffer
class ProgramRun:
from resources.gui._gui_variables import window_variables_init, set_variable_default_values
from resources.gui._main_window import build_main_window, update_window
'''>>> imports used in other files connected to this class'''
from resources.gui.windows._left_menu_label import _left_menu_bar, exit_program
from resources.gui.windows._home_label import _home_label
from resources.gui.windows._settings_label import _settings_label
'''<<< imports used in other files connected to this class'''
def __init__(self,):
self.window = Tk()
self.window_variables_init()
self.set_variable_default_values()
self.build_main_window()
self.semaphore = BoundedSemaphore(value = 2)
# Initialize all states for memory storage purposes
self.states_data = StatesDataBuffer()
self.main_loop()
def main_loop(self):
read_machine = ReadUDPmachine(states_data=self.states_data, gui_data=self)
program_machine = ProgramMachine(states_data=self.states_data, gui_data=self)
send_machine = SendUDPmachine(states_data=self.states_data, gui_data=self)
while True:
'''create threads'''
threads = []
self.update_window()
thread = Thread(
target=read_machine.on_event()
)
threads.append(thread)
thread = Thread(
target=program_machine.on_event()
)
threads.append(thread)
thread = Thread(
target=send_machine.on_event()
)
threads.append(thread)
'''start threads'''
for thread in threads:
thread.start()
'''wait for all threads to end'''
for thread in threads:
thread.join()
try:
self.window.winfo_exists() # if there is no window then exit program
except:
exit()
'''---------------------------------------START APP------------------------------------------------------------------'''
app = ProgramRun()