Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
317 changes: 138 additions & 179 deletions src/new_core.py
Original file line number Diff line number Diff line change
@@ -1,186 +1,145 @@
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import os
from datetime import datetime
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QWidget, QPushButton, QLabel,
QVBoxLayout, QHBoxLayout, QStackedWidget, QLineEdit, QTextEdit,
QFrame, QScrollArea,QComboBox,QRadioButton,QFileDialog,QMessageBox,QCheckBox
QApplication, QWidget, QLabel, QLineEdit, QPushButton,
QVBoxLayout, QHBoxLayout, QFileDialog, QComboBox, QRadioButton, QButtonGroup
)
from PyQt5.QtGui import QIcon,QFont,QPixmap,QMovie
from PyQt5.QtCore import Qt
import json
from PyQt5.QtCore import pyqtSignal
import new_ui
from styles import *
import subprocess
import os
from TTS_main import Test_begin
class Main_utils_page(QWidget):
from PyQt5.QtGui import QIcon


class IPATestUI(QWidget):
def __init__(self):
super().__init__()
self.sig_use = pyqtSignal()
self.page = self.main_page()

def main_page(self):
page = self.create_card()
main_layout = QHBoxLayout()
main_layout.setAlignment(Qt.AlignCenter)
main_layout.addWidget(page)
page.setLayout(main_layout)
return page

def create_card(self):
card = QWidget()
card.setStyleSheet("background-color: #272757; border-radius: 12px; padding: 2px;")
vbox = QVBoxLayout()
vbox.setAlignment(Qt.AlignTop)
vbox.setSpacing(15)

label = QLabel("Start A Task or Schedule One")
label.setStyleSheet(my_style)
label.setAlignment(Qt.AlignCenter)
vbox.addWidget(label)
# ---------- IP Address Input ----------
ip_path_edit = QLineEdit()
ip_path_edit.setPlaceholderText("IP Address")
ip_path_edit.setStyleSheet(my_style)
ip_path_edit.setText('169.254.80.')
vbox.addWidget(ip_path_edit)

# ---------- Excel File Input ----------
exe_path_edit = QLineEdit()
exe_path_edit.setPlaceholderText("Path to Excel")
exe_path_edit.setStyleSheet(my_style)
browse_btn = QPushButton("Browse")
browse_btn.setStyleSheet(my_style)
browse_btn.setFixedSize(100,40)
browse_btn.clicked.connect(lambda: exe_path_edit.setText(
QFileDialog.getOpenFileName(None, "Select Excel", "", "Excel Files (*.xlsx)")[0]
))

exe_hbox = QHBoxLayout()
exe_hbox.addWidget(exe_path_edit)
exe_hbox.addWidget(browse_btn)
vbox.addLayout(exe_hbox)

# ---------- Log Folder Input ----------
log_path_edit = QLineEdit()
log_path_edit.setPlaceholderText("Path to Log Folder")
log_path_edit.setStyleSheet(my_style)
log_browse_btn = QPushButton("Browse")
log_browse_btn.setStyleSheet(my_style)
log_browse_btn.setFixedSize(100,40)
log_browse_btn.clicked.connect(lambda: log_path_edit.setText(
QFileDialog.getExistingDirectory(self, 'Select Log Folder')
))

log_hbox = QHBoxLayout()
log_hbox.addWidget(log_path_edit)
log_hbox.addWidget(log_browse_btn)
vbox.addLayout(log_hbox)

# ---------- DLP Project File ----------
fp_path_edit = QLineEdit()
fp_path_edit.setPlaceholderText("Project file for DLT ECU Conf")
fp_path_edit.setStyleSheet(my_style)
fp_browse_btn = QPushButton("Browse")
fp_browse_btn.setStyleSheet(my_style)
fp_browse_btn.setFixedSize(100,40)
fp_browse_btn.clicked.connect(lambda: fp_path_edit.setText(
QFileDialog.getOpenFileName(None, "Select DLP File", "", "DLP Files (*.DLP)")[0]
))

fp_hbox = QHBoxLayout()
fp_hbox.addWidget(fp_path_edit)
fp_hbox.addWidget(fp_browse_btn)
vbox.addLayout(fp_hbox)

# ---------- Time Input ----------
time_input = QLineEdit()
time_input.setStyleSheet(my_style)
time_input.setPlaceholderText("Schedule Time (HH:MM, e.g., 14:30) optional IN DEVLOPMENT")
vbox.addWidget(time_input)

# ---------- Buttons ----------
btn_hbox = QHBoxLayout()

test_btn = QPushButton("Start Test")
test_btn.setStyleSheet(my_style)
test_btn.setFixedSize(100,60)
test_btn.clicked.connect(lambda: Test_begin(
mcu_ip=ip_path_edit.text(),
input_excel=exe_path_edit.text(),
directory=log_path_edit.text(),
dlp_file=fp_path_edit.text(),
load=Give_load.isChecked(),
stack=tech_stack.currentText()
))

schedule_btn = QPushButton("Schedule")
schedule_btn.setStyleSheet(my_style)
schedule_btn.setFixedSize(100,60)
schedule_btn.clicked.connect(lambda: self.create_and_schedule_task(
exe_path_edit.text(),
"MyApp_Task",
time_input.text()
))
checkbox_layout = QVBoxLayout()
checkbox_label = QLabel("Give load to system?")
checkbox_label.setStyleSheet(my_style)
Give_load = QRadioButton("Yes (ACA ONLY)")
Give_no_load = QRadioButton("No")
Give_load.setStyleSheet("color: white;")
Give_no_load.setStyleSheet("color: white;")
checkbox_layout.addWidget(checkbox_label)
checkbox_layout.addWidget(Give_load)
checkbox_layout.addWidget(Give_no_load)
tech_stack = QComboBox()
tech_stack.addItem("BCA")
tech_stack.addItem("Cerance")
tech_stack.setStyleSheet(combo_sheet)
checkbox_layout.addWidget(tech_stack)
vbox.addLayout(checkbox_layout)
btn_hbox.addWidget(test_btn)
btn_hbox.addWidget(schedule_btn)
vbox.addLayout(btn_hbox)
# ---------- Final Card Layout ----------
card.setLayout(vbox)
return card

def printer(self):
print("god")
print(self.time_input.text())
print(self.exe_input.text())

def create_and_schedule_task(self, exe_path, task_name, time_str):
print(exe_path)
print(task_name)
print(time_str)
cwd = os.getcwd()+'/bats'
#we Create .bat file (i dont know how much safe is this one)
os.makedirs(cwd, exist_ok=True) # Create the directory if it doesn't exist
bat_path = os.path.join(cwd, f"{task_name}.bat")
# bat_path = os.path.join(cwd , f"{task_name}.bat")
with open(bat_path, 'w') as f:
f.write(f'start "" "{exe_path}"\n')

# Schedule task using schtasks , like running a command in linux (can bring improvements)
hour, minute = time_str.split(":")
# https://learn.microsoft.com/en-us/windows/win32/taskschd/schtasks for your reference
# this is definetley gonna break the system
command = [
"schtasks",
"/Create",
"/SC", "DAILY",
"/TN", task_name,
"/TR", f'"{bat_path}"',
"/ST", f"{hour}:{minute}",
"/F"
]

try:
subprocess.run(command, check=True)
QMessageBox.information(self, "Scheduled", f"Task '{task_name}' scheduled at {time_str}")
except subprocess.CalledProcessError as e:
QMessageBox.critical(self, "Error", f"Failed to schedule task:\n{str(e)}")
self.setWindowTitle("IPA Test Automation Runner")
self.setGeometry(200, 200, 520, 380)

self.ip = ""
self.excel_file = ""
self.config_file = ""
self.tech = "BCA"
self.system_load = False
self.iterations = 1

self.timenow = datetime.now()
self.rundirectoryname = "IPA_Testrun_" + self.timenow.strftime("%d_%m_%H_%M")
self.rundirectory = ""

self.initUI()

def initUI(self):
layout = QVBoxLayout()
layout.setSpacing(8)

# IP Address
ip_label = QLabel("IP Address:")
self.ip_entry = QLineEdit()
layout.addWidget(ip_label)
layout.addWidget(self.ip_entry)

# Excel File
excel_label = QLabel("Excel File:")
excel_layout = QHBoxLayout()
self.excel_entry = QLineEdit()
excel_button = QPushButton("Browse")
excel_button.clicked.connect(self.browse_excel)
excel_layout.addWidget(self.excel_entry)
excel_layout.addWidget(excel_button)
layout.addWidget(excel_label)
layout.addLayout(excel_layout)

# Config File
config_label = QLabel("Configuration File:")
config_layout = QHBoxLayout()
self.config_entry = QLineEdit()
config_button = QPushButton("Browse")
config_button.clicked.connect(self.browse_config)
config_layout.addWidget(self.config_entry)
config_layout.addWidget(config_button)
layout.addWidget(config_label)
layout.addLayout(config_layout)

# Tech Stack dropdown
tech_label = QLabel("Tech Stack:")
self.tech_combo = QComboBox()
self.tech_combo.addItems(["BCA", "Cerence"])
tech_layout = QHBoxLayout()
tech_layout.addWidget(tech_label)
tech_layout.addWidget(self.tech_combo)
layout.addLayout(tech_layout)

# System Load radio
sysload_label = QLabel("Give System Load?")
sysload_layout = QHBoxLayout()
self.radio_yes = QRadioButton("Yes")
self.radio_no = QRadioButton("No")
self.radio_no.setChecked(True)
sysload_group = QButtonGroup(self)
sysload_group.addButton(self.radio_yes)
sysload_group.addButton(self.radio_no)
sysload_layout.addWidget(self.radio_yes)
sysload_layout.addWidget(self.radio_no)
layout.addWidget(sysload_label)
layout.addLayout(sysload_layout)

# Iterations dropdown
iter_layout = QHBoxLayout()
iter_label = QLabel("Iteration Count:")
self.iter_combo = QComboBox()
self.iter_combo.addItems([str(i) for i in range(1, 6)])
iter_layout.addWidget(iter_label)
iter_layout.addWidget(self.iter_combo)
layout.addLayout(iter_layout)

# Start Button
start_button = QPushButton("Start Test")
start_button.clicked.connect(self.start_test)
layout.addWidget(start_button)

# Status labels
self.status_total = QLabel("Total / Played: 0 / 0")
self.status_current = QLabel("Current Utterance: None")
layout.addWidget(self.status_total)
layout.addWidget(self.status_current)

self.setLayout(layout)

def browse_excel(self):
file_name, _ = QFileDialog.getOpenFileName(self, "Select Excel File", "", "Excel Files (*.xlsx *.xls)")
if file_name:
self.excel_entry.setText(file_name)
self.excel_file = file_name

def browse_config(self):
file_name, _ = QFileDialog.getOpenFileName(self, "Select Configuration File", "", "All Files (*)")
if file_name:
self.config_entry.setText(file_name)
self.config_file = file_name

def update_status(self, total_played_text=None, current_utterance_text=None, error=False):
if total_played_text is not None:
self.status_total.setText(total_played_text)
if current_utterance_text is not None:
self.status_current.setText(current_utterance_text)

def start_test(self):
self.ip = self.ip_entry.text().strip()
self.excel_file = self.excel_entry.text().strip()
self.config_file = self.config_entry.text().strip()
self.tech = self.tech_combo.currentText()
self.system_load = self.radio_yes.isChecked()
self.iterations = int(self.iter_combo.currentText())

print(f"IP: {self.ip}")
print(f"Excel: {self.excel_file}")
print(f"Config: {self.config_file}")
print(f"Tech Stack: {self.tech}")
print(f"System Load: {self.system_load}")
print(f"Iterations: {self.iterations}")


if __name__ == "__main__":
app = QApplication(sys.argv)
win = IPATestUI()
win.show()
sys.exit(app.exec_())
Loading