diff --git a/CTC/CTC_UI.py b/CTC/CTC_UI.py index 0dc85afa..12ee389c 100644 --- a/CTC/CTC_UI.py +++ b/CTC/CTC_UI.py @@ -1,18 +1,104 @@ +#File to run the UI for the CTC Module +#Abby Magistro + import sys -from PyQt5 import QtWidgets +from PyQt5 import QtCore, QtWidgets from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5 import uic +from Schedule import * +from OccupiedBlocks import * #from UI_temp import MainWindow + + class UI(QtWidgets.QMainWindow): def __init__(self): super(UI, self).__init__() + #Loading base UI layout from .ui file uic.loadUi("CTC/CTC_UI.ui", self) - self.show() + + + #Connect Buttons to signals defining behavior + self.UploadButton.clicked.connect(self.open_files) + self.ManualModeButton.clicked.connect(self.selectManualMode_button) + self.AddTrainButton.clicked.connect(self.addTrain_button) + + #Changing Button Colors + self.AddTrainButton.setStyleSheet("background-color : rgb(38, 207, 4)") + self.UploadButton.setStyleSheet("background-color : rgb(38, 207, 4)") + + #Changing Background colors to section off UI + self.MaualDispatchBox.setStyleSheet("background-color : rgb(233, 247, 255);") + self.OccupiedBlocksBox.setStyleSheet("background-color : rgb(233, 247, 255);") + + #Manual Dispatch Formatting + self.ArrivalTimeEdit.setDisplayFormat("hh:mm") + self.DepartureTimeEdit.setDisplayFormat("hh:mm") + + #Add the clock + #self.Clock = QtCore.QTimer(self) + #self.Clock.timeout.connect(self.showTime(time)) + #self.Clock.display(ourClock.time) + + #Initializing Schedule + self.trainSchedule = Schedule() + self.ScheduleTable.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata)) + + #Initializing Occupied Blocks Table + self.occupiedBlocks = OccupiedBlocks() + self.OccupiedBlockTable.setModel(BlocksTableModel(self.occupiedBlocks.BlockData)) + + + + + + + #Define functionality for Upload File Button + def open_files(self): + # Open a file dialog to select a Excel File + file_dialog = QFileDialog() + file_path, _ = file_dialog.getOpenFileName(self, "Select Schedule File", "", "Excel Workbook (*.xlsx);;All Files (*)") + + """ + #TO DO LATER + if file_path: + # Implement your logic with the selected file path + print(f"Selected PLC File: {file_path}") + """ + + + #Define mutually exclisive auto/manual mode + def selectManualMode_button(self): + #When Manual Mode button is pressed + + #Disable AutoMode Button + self.AutoModeButton.setEnabled(False) + #And File Upload Button + self.UploadButton.setEnabled(False) + self.UploadButton.setStyleSheet("background-color : #ebfae8") + + #Disable Manual Mode button (because it's one use) + self.ManualModeButton.setEnabled(False) + self.ManualModeButton.setStyleSheet("background-color : blue; color: black;") + + #defining manual mode add train button functionality + def addTrain_button(self): + TrainID = self.TrainNameField.text() + Departure = self.DepartureSationSelect.currentText() + DepartureTime = self.DepartureTimeEdit.time() + DepartureTime = DepartureTime.toString("hh:mm") + Destination = self.DestinationSelect.currentText() + ArrivalTime = self.ArrivalTimeEdit.time() + ArrivalTime = ArrivalTime.toString("hh:mm") + + self.trainSchedule.addTrain(TrainID, Destination, ArrivalTime, Departure, DepartureTime) + self.ScheduleTable.setModel(ScheduleTableModel(self.trainSchedule.Scheduledata)) + test = QtWidgets.QApplication(sys.argv) window = UI() +window.show() test.exec_() \ No newline at end of file diff --git a/CTC/CTC_UI.ui b/CTC/CTC_UI.ui index 0a26e352..c43b0601 100644 --- a/CTC/CTC_UI.ui +++ b/CTC/CTC_UI.ui @@ -6,8 +6,8 @@ 0 0 - 1066 - 673 + 849 + 650 @@ -25,7 +25,7 @@ - + 0 @@ -46,39 +46,60 @@ 10 10 - 1041 - 591 + 821 + 581 - + - + - + Manual Dispatch - -1 + 9 19 - 521 - 131 + 491 + 153 - + - + - + + + Train Name + + + + + + + + + + Add Train to Schedule + + + + + + + + + Departure Station - + @@ -102,28 +123,31 @@ - + Departure Time + + + - + QLayout::SetFixedSize - + Destination - + @@ -147,36 +171,14 @@ - + Arrival Time - - - - - - - Train Name - - - - - - - TextLabel - - - - - - - Add Desitnation Button - - + @@ -185,22 +187,39 @@ - - - Schedule - + + + true + + + true + + + false + - + - - - Manual/Auto Switch - - + + + + + Manual Mode + + + + + + + Auto Mode + + + + @@ -219,45 +238,45 @@ - 28 - 255 - 25 + 240 + 240 + 240 - 154 + 255 255 - 153 + 255 - 91 - 255 - 89 + 247 + 247 + 247 - 14 - 127 - 12 + 120 + 120 + 120 - 18 - 170 - 16 + 160 + 160 + 160 @@ -300,9 +319,9 @@ - 28 - 255 - 25 + 240 + 240 + 240 @@ -318,9 +337,9 @@ - 141 - 255 - 140 + 247 + 247 + 247 @@ -356,45 +375,45 @@ - 28 - 255 - 25 + 240 + 240 + 240 - 154 + 255 255 - 153 + 255 - 91 - 255 - 89 + 247 + 247 + 247 - 14 - 127 - 12 + 120 + 120 + 120 - 18 - 170 - 16 + 160 + 160 + 160 @@ -437,9 +456,9 @@ - 28 - 255 - 25 + 240 + 240 + 240 @@ -455,9 +474,9 @@ - 141 - 255 - 140 + 247 + 247 + 247 @@ -484,63 +503,63 @@ - 14 - 127 - 12 + 120 + 120 + 120 - 28 - 255 - 25 + 240 + 240 + 240 - 154 + 255 255 - 153 + 255 - 91 - 255 - 89 + 247 + 247 + 247 - 14 - 127 - 12 + 120 + 120 + 120 - 18 - 170 - 16 + 160 + 160 + 160 - 14 - 127 - 12 + 120 + 120 + 120 @@ -556,27 +575,27 @@ - 14 - 127 - 12 + 120 + 120 + 120 - 28 - 255 - 25 + 240 + 240 + 240 - 28 - 255 - 25 + 240 + 240 + 240 @@ -592,9 +611,9 @@ - 28 - 255 - 25 + 240 + 240 + 240 @@ -625,10 +644,23 @@ - - + + Occupied Blocks + + + + 20 + 20 + 251 + 231 + + + + Qt::ScrollBarAlwaysOff + + diff --git a/CTC/Clock.py b/CTC/Clock.py new file mode 100644 index 00000000..69567497 --- /dev/null +++ b/CTC/Clock.py @@ -0,0 +1,28 @@ +import sys + +from PyQt5 import QtCore + +class Clock: + def __init__(self): + self.time = "" + + +def calculo(): + global time + time = time.addSecs(60) + + ourClock.time = time.toString("dd hh:mm:ss") + print(ourClock.time) + +app = QtCore.QCoreApplication(sys.argv) + +global ourClock +ourClock = Clock() + +timer0 = QtCore.QTimer() +time = QtCore.QTime(0, 0, 0) +timer0.setInterval(1000) +timer0.timeout.connect(calculo) +timer0.start() + +sys.exit(app.exec_()) \ No newline at end of file diff --git a/CTC/OccupiedBlocks.py b/CTC/OccupiedBlocks.py new file mode 100644 index 00000000..57b552be --- /dev/null +++ b/CTC/OccupiedBlocks.py @@ -0,0 +1,54 @@ +#File to aquire and hold block occupancy data +#Includes Class to manage that data +#Also includes a table model class for diplaying info on the CTC UI + +import sys +from PyQt5 import QtCore, QtWidgets +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * +from PyQt5.QtCore import * +from PyQt5 import uic + +class OccupiedBlocks(): + def __init__(self, Blocks = []): + #Dummy data for testing + Blocks = [['T1', 'B2'], ['T1', 'B1']] + + self.BlockData = Blocks + + def addBlockOccupancy(self, TrainName, BlockNum): + newBlockOccupancy = [TrainName, BlockNum] + self.BlockData.append(newBlockOccupancy) + + + + +#Table class to initialize a Pyqt5 table object that will display the list of block occupancies +class BlocksTableModel(QtCore.QAbstractTableModel): + def __init__(self, data): + super(BlocksTableModel, self).__init__() + self._data = data + + #Displays the data to the table + def data(self, index, role): + if role == Qt.DisplayRole: + return self._data[index.row()][index.column()] + + #Returns the row count of the table + def rowCount(self, index): + return len(self._data) + + #returns the column count of the table + def columnCount(self, index): + if(len(self._data) > 0): + return len(self._data[0]) + else: + return 0 + + #Adds the column header with the correct data + def headerData(self, section, orientation, role): + headers = ['Train', 'Block #'] + + if role == Qt.DisplayRole: + if orientation == Qt.Horizontal: + return str(headers[section]) \ No newline at end of file diff --git a/CTC/Schedule.py b/CTC/Schedule.py new file mode 100644 index 00000000..9732e0b8 --- /dev/null +++ b/CTC/Schedule.py @@ -0,0 +1,53 @@ +#File to aquire and hold schedule data +#Includes Schedule class +#Also includes a table model class for diplaying schedule on the CTC UI + +import sys +from PyQt5 import QtCore, QtWidgets +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * +from PyQt5.QtCore import * +from PyQt5 import uic + +#Schedule class, holds schedule data and defines methods for editing the schedule +class Schedule(): + def __init__(self, ScheduleData = []): + self.Scheduledata = ScheduleData + + def addTrain(self, TrainID, Destination, ArrivalTime, Departure, DepartureTime): + newTrain = [TrainID, Departure, DepartureTime, Destination, ArrivalTime] + self.Scheduledata.append(newTrain) + + + +#Table class to initialize a Pyqt5 table object that will display the schedule +class ScheduleTableModel(QtCore.QAbstractTableModel): + def __init__(self, data): + super(ScheduleTableModel, self).__init__() + self._data = data + + #Displays the data to the table + def data(self, index, role): + if role == Qt.DisplayRole: + return self._data[index.row()][index.column()] + + #Returns the row count of the table + def rowCount(self, index): + return len(self._data) + + + #returns the column count of the table + def columnCount(self, index): + if(len(self._data) > 0): + return len(self._data[0]) + else: + return 0 + + + #Adds the column header with the correct data + def headerData(self, section, orientation, role): + headers = ['Train ID', 'Departure Station', 'Departure Time', 'Destination', 'Arrival Time'] + + if role == Qt.DisplayRole: + if orientation == Qt.Horizontal: + return str(headers[section]) diff --git a/CTC/__pycache__/Clock.cpython-312.pyc b/CTC/__pycache__/Clock.cpython-312.pyc new file mode 100644 index 00000000..d7da7807 Binary files /dev/null and b/CTC/__pycache__/Clock.cpython-312.pyc differ diff --git a/CTC/__pycache__/OccupiedBlocks.cpython-312.pyc b/CTC/__pycache__/OccupiedBlocks.cpython-312.pyc new file mode 100644 index 00000000..3c6a4572 Binary files /dev/null and b/CTC/__pycache__/OccupiedBlocks.cpython-312.pyc differ diff --git a/CTC/__pycache__/Schedule.cpython-312.pyc b/CTC/__pycache__/Schedule.cpython-312.pyc new file mode 100644 index 00000000..350fca80 Binary files /dev/null and b/CTC/__pycache__/Schedule.cpython-312.pyc differ