-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_window.py
95 lines (82 loc) · 3.36 KB
/
main_window.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
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QFont, QIcon
from PyQt6.QtWidgets import QMainWindow, QPushButton, QApplication, QLabel
import threading
import logging
from save_send_network_tables import *
class MainWindow(QMainWindow):
connected_to_network_table = False
sending_climb_zeroes = False
nt = None
def __init__(self):
super().__init__()
self.button1 = QPushButton(self)
self.button2 = QPushButton(self)
self.label = QLabel(self)
self.set_up_window()
t1 = threading.Thread(target=self.establish_network_table_connection)
t1.start()
def set_up_window(self):
width = 700
height = 350
self.setFixedWidth(width)
self.setFixedHeight(height)
self.setWindowTitle("Climb Zeroes Manager")
self.setWindowIcon(QIcon("4829logo.png"))
self.button1.setText("Save")
self.button1.setFont(QFont("Ariel", 20))
self.button1.setGeometry(100, 100, 200, 100)
self.button1.clicked.connect(self.save_climb_zeroes)
self.button2.setText("Send")
self.button2.setFont(QFont("Ariel", 20))
self.button2.setGeometry(400, 100, 200, 100)
self.button2.clicked.connect(self.send_button_clicked)
self.label.setText("Awaiting Input")
self.label.setFont(QFont("Ariel", 20))
self.label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.label.setGeometry(150, 200, 400, 100)
def establish_network_table_connection(self):
cond = threading.Condition()
notified = [False]
def connectionListener(connected, info):
print(info, '; Connected=%s' % connected)
with cond:
notified[0] = True
cond.notify()
logging.basicConfig(level=logging.DEBUG)
NetworkTables.startClientTeam(4829)
NetworkTables.addConnectionListener(connectionListener, immediateNotify=True)
with cond:
print("Waiting")
if not notified[0]:
cond.wait()
self.connected_to_network_table = False
# This is reached once it is connected to the network table
self.connected_to_network_table = True
nt = NetworkTables.getTable("climbZerosTable")
self.nt = nt
print("Connected")
def save_climb_zeroes(self):
if self.nt is not None:
self.label.setText("Connected")
# This starts a thread that will run until climb values are saved
t2 = threading.Thread(target=receive_climb_values, args=[self.nt])
t2.start()
self.button1.setStyleSheet("background-color: green")
else:
self.label.setText("Cannot establish connection")
def send_button_clicked(self):
if self.nt is not None:
self.label.setText("Connected")
self.sending_climb_zeroes = not self.sending_climb_zeroes
if self.sending_climb_zeroes:
self.button2.setText("Stop Sending")
self.button1.setStyleSheet("")
self.button1.setDisabled(True)
t3 = threading.Thread(target=send_climb_values, args=[self.nt])
t3.start()
else:
self.button2.setText("Send")
self.button1.setEnabled(True)
else:
self.label.setText("Cannot establish connection")