From a43d864bbca91fc11ad72c280ab5297e390ea50d Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 23 Feb 2023 10:36:31 +0100 Subject: [PATCH 01/48] Cleanup code --- CompuRacer_Core/src/command_processor.py | 6 +- .../src/{maingui.py => connectgui.py} | 8 +- CompuRacer_Core/src/gui.py | 159 +++++++++++------- 3 files changed, 109 insertions(+), 64 deletions(-) rename CompuRacer_Core/src/{maingui.py => connectgui.py} (63%) diff --git a/CompuRacer_Core/src/command_processor.py b/CompuRacer_Core/src/command_processor.py index b9932f3..6591298 100644 --- a/CompuRacer_Core/src/command_processor.py +++ b/CompuRacer_Core/src/command_processor.py @@ -16,9 +16,9 @@ import src.utils as utils -from src.maingui import MainGUI +from src.connectgui import ConnectGUI -from PyQt5.QtCore import QThread, QObject, pyqtSignal +from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtWidgets import QApplication __version__ = "v1" @@ -140,7 +140,7 @@ def gui_interpreter(self, state): self.print_formatted("Starting GUI " + __version__ + "..", utils.QType.INFORMATION) app = QApplication([]) - MainGUI.show_requests_gui(self.racer, app, state, self) + ConnectGUI.show_requests_gui(self.racer, app, state, self) def command_interpreter(self): self.welcome_function(self.welcome_function_class) diff --git a/CompuRacer_Core/src/maingui.py b/CompuRacer_Core/src/connectgui.py similarity index 63% rename from CompuRacer_Core/src/maingui.py rename to CompuRacer_Core/src/connectgui.py index 0b12967..d5b69c1 100644 --- a/CompuRacer_Core/src/maingui.py +++ b/CompuRacer_Core/src/connectgui.py @@ -1,10 +1,10 @@ import os import sys -from src.gui import RequestsGUI +from src.gui import MainGUI -class MainGUI: +class ConnectGUI: def __init__(self, racer): super().__init__() self.racer = racer @@ -12,7 +12,7 @@ def __init__(self, racer): self.show_requests_gui(racer) def show_requests_gui(racer, app, state, cmdprocessor): - requests_gui = RequestsGUI(racer, state, cmdprocessor) + main_gui = MainGUI(racer, state, cmdprocessor) - requests_gui.show() + main_gui.show() sys.exit(app.exec_()) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index b139db3..eb490de 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -1,13 +1,12 @@ import json import os -import sys +from typing import List, Any from PyQt5.QtCore import Qt, QTimer -from PyQt5.QtWidgets import QPushButton, QSystemTrayIcon, QMenu, QAction, QMainWindow, QVBoxLayout, QLabel, QTableWidget, QTableWidgetItem, QTabWidget, QWidget, QMessageBox, QLineEdit, QHBoxLayout, QApplication -from PyQt5.QtGui import QIcon +from PyQt5.QtWidgets import QPushButton, QMainWindow, QVBoxLayout, QLabel, QTableWidget, QTableWidgetItem, QTabWidget, QWidget, QMessageBox, QLineEdit, QHBoxLayout, QApplication -def load_json_batches(directory) -> [str]: +def load_json_batches(directory) -> List[Any]: file_names = [] for filename in os.listdir(directory): if filename.endswith(".json"): @@ -15,13 +14,15 @@ def load_json_batches(directory) -> [str]: data = json.load(file) if "name" in data: file_names.append(data["name"]) + return file_names -class RequestsGUI(QMainWindow): - def __init__(self, racer, state, cmdprocessor): +class MainGUI(QMainWindow): + def __init__(self, racer, state, cmdprocessor) -> None: super().__init__() + self.general_window = None self.batch_window = None self.current_batch = None self.data_requests = None @@ -37,6 +38,8 @@ def __init__(self, racer, state, cmdprocessor): self.init_ui() + return None + def init_ui(self) -> None: self.showFullScreen() self.setWindowTitle("CompuRacer GUI") @@ -51,6 +54,7 @@ def init_ui(self) -> None: vbox_general = QVBoxLayout() vbox_logs = QVBoxLayout() + # --- Create and load in GUI --- # self.create_request_widget(vbox_general, general_tab) self.create_batch_widget(vbox_general, general_tab) self.create_logs_widget(vbox_logs, logs_tab) @@ -62,6 +66,7 @@ def init_ui(self) -> None: def create_request_widget(self, vbox, requests_tab) -> None: vbox.addWidget(QLabel("Requests Information")) + # --- Creating Table --- # self.table_widget = QTableWidget(len(self.data_requests["requests"]), 6) self.table_widget.setColumnWidth(0, 30) self.table_widget.setColumnWidth(1, 400) @@ -82,22 +87,22 @@ def create_batch_widget(self, vbox, batches_tab) -> None: directory = "state/batches" file_names = load_json_batches(directory) + # --- Creating table --- # self.table_widget = QTableWidget(len(file_names), 6) self.table_widget.setColumnWidth(0, 400) self.table_widget.setHorizontalHeaderLabels(["Name", "Allow Redirects", "Sync Last Byte", "Send Timeout", "Set Current Batch", "Open Batch"]) vbox.addWidget(self.table_widget) - # clear the table widget before loading new batches + # --- Clearing content before creating new --- # self.table_widget.clearContents() self.table_widget.setRowCount(0) - current_batch = self.data_requests["current_batch"] - # --- Add new batch --- # add_batch_field = QLineEdit() add_batch_field_button = QPushButton("Add Batch", self) add_batch_field_button.clicked.connect(lambda _, input_field=add_batch_field: self.create_new_batch(input_field)) + # --- Create add batch button and field --- # hbox = QHBoxLayout() hbox.addWidget(add_batch_field) hbox.addWidget(add_batch_field_button) @@ -108,8 +113,11 @@ def create_batch_widget(self, vbox, batches_tab) -> None: quit_button.clicked.connect(QApplication.quit) vbox.addWidget(quit_button) + # --- Load in all batches --- # + current_batch = self.data_requests["current_batch"] self.load_batches(file_names, directory, vbox, current_batch) + # --- JSON Parsing Timer --- # self.update_json_timer = QTimer() self.update_json_timer.timeout.connect(self.reload_json) self.update_json_timer.start(5000) @@ -196,6 +204,7 @@ def load_table(): self.remove_empty_rows() load_table() + return load_table def load_logs(self) -> None: @@ -207,18 +216,19 @@ def load_logs(self) -> None: self.remove_empty_rows() return None - def add_request_to_batch(self, request_id): + def add_request_to_batch(self, request_id) -> None: self.showNotification("RequestID " + request_id + " has been added to active Batch!") - self.racer.comm_curr_add(self.state, request_id) - def get_json_data(self, directory, name): + return None + + def get_json_data(self, directory, name) -> dict: with open(os.path.join(directory, name + ".json"), "r") as file: data = json.load(file) return data - def check_current_batch(self, name, row, current_button, window_button, current_batch): + def check_current_batch(self, name, row, current_button, window_button, current_batch) -> None: if name == current_batch: for col in range(self.table_widget.columnCount()): item = self.table_widget.item(row, col) @@ -233,6 +243,8 @@ def check_current_batch(self, name, row, current_button, window_button, current_ current_button.setEnabled(False) window_button.setEnabled(False) + return None + def remove_empty_rows(self) -> None: for row in range(self.table_widget.rowCount() - 1, -1, -1): empty = True @@ -249,42 +261,49 @@ def remove_empty_rows(self) -> None: def load_json_requests(self) -> None: with open('state/state.json', 'r') as f: self.data_requests = json.load(f) + return None def save_data(self) -> None: self.racer.comm_general_save(True) + return None - def reload_json(self): + def reload_json(self) -> None: if self.isActiveWindow(): self.save_data() self.update_json_timer.stop() self.hide() - self.general_window = RequestsGUI(self.racer, self.state, self.command_processor) # Create a new window + self.general_window = MainGUI(self.racer, self.state, self.command_processor) self.general_window.show() self.deleteLater() + return None + def set_current_batch(self, batch_name) -> None: self.racer.set_curr_batch_by_name(batch_name) self.current_batch = batch_name self.showNotification("Set current batch to " + batch_name) + return None - def new_batch_window(self, batch_name): + def new_batch_window(self, batch_name) -> None: self.save_data() self.update_json_timer.stop() self.batch_window = BatchWindow(batch_name, self.racer, self.state, self.command_processor) self.batch_window.show() self.hide() - def create_new_batch(self, batch_name): - batch_name = batch_name.text() + return None + def create_new_batch(self, batch_name) -> None: + batch_name = batch_name.text() self.racer.gui_create_new_batch(batch_name) - self.showNotification("Added New Batch " + batch_name + ". Add a request to your batch so you can open your batch") - def showNotification(self, notiText): + return None + + def showNotification(self, notiText) -> None: messageBox = QMessageBox() messageBox.setIcon(QMessageBox.Information) messageBox.setText(notiText) @@ -298,79 +317,95 @@ def showNotification(self, notiText): messageBox.exec() + return None + + +def load_json(filepath) -> dict: + with open(filepath, 'r') as file: + data = json.load(file) + + return data + class BatchWindow(QMainWindow): - def __init__(self, batch_name, racer, state, command_processor): + def __init__(self, batch_name, racer, state, command_processor) -> None: super().__init__() self.showFullScreen() + self.setWindowTitle("Batch: " + batch_name) + self.update_json_timer = None self.general_window = None self.table_widget = None - self.batch_requests = [] self.racer = racer self.batch_name = batch_name self.state = state self.command_processor = command_processor - self.setWindowTitle("Batch: " + batch_name) + self.batch_requests = [] self.init_ui() - def init_ui(self): + def init_ui(self) -> None: vbox = QVBoxLayout() batch_tab = QWidget() batch_tab.setLayout(vbox) - batch_tab.layout().addWidget(self.table_widget) tabs = QTabWidget() - tabs.addTab(batch_tab, "Batch") vbox.addStretch() - vbox.addWidget(QPushButton("Send Batch", self, clicked=self.send_batch), alignment=Qt.AlignBottom) - vbox.addWidget(QPushButton("Go Back", self, clicked=self.go_back), alignment=Qt.AlignBottom) - vbox.addWidget(QPushButton("Quit", self, clicked=QApplication.quit)) - + self.add_button_widget(vbox) self.setCentralWidget(tabs) - self.create_requests_widget(vbox) + vbox.insertWidget(0, self.table_widget) self.update_json_timer = QTimer() self.update_json_timer.timeout.connect(lambda: self.reload_json()) self.update_json_timer.start(10000) - def send_batch(self): - self.save_data() - self.update_json_timer.stop() - self.racer.gui_send_batches() + return None - def create_requests_widget(self, vbox): - self.table_widget = QTableWidget() + def create_requests_widget(self, vbox) -> None: vbox.addWidget(QLabel("")) + + self.table_widget = QTableWidget() self.table_widget.setColumnCount(4) self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Host"]) - - self.add_request_table() - - def add_request_table(self) -> None: - items = self.load_json("state/batches/" + self.batch_name + ".json")["items"] - requests = self.load_json("state/state.json")["requests"] - - self.table_widget = QTableWidget(len(items), 4, self) - self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host"]) self.table_widget.setColumnWidth(0, 50) self.table_widget.setColumnWidth(1, 50) self.table_widget.setColumnWidth(2, 300) self.table_widget.setColumnWidth(3, 100) - self.table_widget.verticalHeader().hide() + self.add_request_table() + + return None + + def add_button_widget(self, vbox) -> None: + send_batch_button = QPushButton("Send Batch") + go_back_button = QPushButton("Go Back") + quit_button = QPushButton("Quit") + + send_batch_button.clicked.connect(self.send_batch) + go_back_button.clicked.connect(self.go_back) + quit_button.clicked.connect(QApplication.quit) + vbox.addWidget(send_batch_button, alignment=Qt.AlignBottom) + vbox.addWidget(go_back_button, alignment=Qt.AlignBottom) + vbox.addWidget(quit_button, alignment=Qt.AlignBottom) + + return None + + def add_request_table(self) -> None: + items = load_json("state/batches/" + self.batch_name + ".json")["items"] + requests = load_json("state/state.json")["requests"] + + # --- Load in all data --- # for i, item in enumerate(items): request_id = item["key"][0] request = requests[request_id] @@ -384,13 +419,17 @@ def add_request_table(self) -> None: self.table_widget.setItem(i, 2, QTableWidgetItem(url)) self.table_widget.setItem(i, 3, QTableWidgetItem(host)) - def load_json(self, filepath): - with open(filepath, 'r') as file: - data = json.load(file) - return data + return None + + def send_batch(self) -> None: + self.save_data() + self.update_json_timer.stop() + self.racer.gui_send_batches() + + return None def go_back(self) -> None: - self.general_window = RequestsGUI(self.racer, self.state, self.command_processor) + self.general_window = MainGUI(self.racer, self.state, self.command_processor) self.general_window.show() self.hide() @@ -398,21 +437,25 @@ def go_back(self) -> None: def save_data(self) -> None: self.racer.comm_general_save(True) + return None - def reload_json(self): + def reload_json(self) -> None: if self.isActiveWindow(): self.save_data() self.update_json_timer.stop() self.hide() - self.general_window = BatchWindow(self.batch_name, self.racer, self.state, self.command_processor) # Create a new window + self.general_window = BatchWindow(self.batch_name, self.racer, self.state, self.command_processor) self.general_window.show() self.deleteLater() - def showNotification(self, notiText): + return None + + @staticmethod + def showNotification(notifyText) -> None: messageBox = QMessageBox() messageBox.setIcon(QMessageBox.Information) - messageBox.setText(notiText) + messageBox.setText(notifyText) messageBox.setGeometry(0, 0, 500, 50) @@ -421,4 +464,6 @@ def showNotification(self, notiText): timer.timeout.connect(messageBox.close) timer.start(5000) - messageBox.exec() \ No newline at end of file + messageBox.exec() + + return None From ce6647f67f5d860f98a3ddfc740bbaccdf0310d8 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 23 Feb 2023 13:15:24 +0100 Subject: [PATCH 02/48] Added opening request --- CompuRacer_Core/src/gui.py | 195 +++++++++++++++++++++++++++++++++---- 1 file changed, 178 insertions(+), 17 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index eb490de..c9e2058 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -3,7 +3,8 @@ from typing import List, Any from PyQt5.QtCore import Qt, QTimer -from PyQt5.QtWidgets import QPushButton, QMainWindow, QVBoxLayout, QLabel, QTableWidget, QTableWidgetItem, QTabWidget, QWidget, QMessageBox, QLineEdit, QHBoxLayout, QApplication +from PyQt5.QtWidgets import QPushButton, QMainWindow, QVBoxLayout, QLabel, QTableWidget, QTableWidgetItem, QTabWidget, QWidget, QMessageBox, QLineEdit, QHBoxLayout, QApplication, QHeaderView, QTableView +from PyQt5.QtGui import QStandardItem, QStandardItemModel def load_json_batches(directory) -> List[Any]: @@ -19,27 +20,28 @@ def load_json_batches(directory) -> List[Any]: class MainGUI(QMainWindow): - def __init__(self, racer, state, cmdprocessor) -> None: + def __init__(self, racer, state, command_processor) -> None: super().__init__() + self.request_window = None + self.update_json_timer = None self.general_window = None self.batch_window = None self.current_batch = None self.data_requests = None self.table_widget = None - self.command_processor = cmdprocessor + self.command_processor = command_processor self.racer = racer self.state = state self.batch_buttons = [] + self.request_buttons = [] self.load_json_requests() self.init_ui() - return None - def init_ui(self) -> None: self.showFullScreen() self.setWindowTitle("CompuRacer GUI") @@ -67,15 +69,15 @@ def create_request_widget(self, vbox, requests_tab) -> None: vbox.addWidget(QLabel("Requests Information")) # --- Creating Table --- # - self.table_widget = QTableWidget(len(self.data_requests["requests"]), 6) + self.table_widget = QTableWidget(len(self.data_requests["requests"]), 7) self.table_widget.setColumnWidth(0, 30) self.table_widget.setColumnWidth(1, 400) self.table_widget.setColumnWidth(3, 200) self.table_widget.setColumnWidth(4, 100) - self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch"]) + self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open"]) vbox.addWidget(self.table_widget) - self.load_requests(vbox) + self.load_requests() requests_tab.setLayout(vbox) @@ -115,7 +117,7 @@ def create_batch_widget(self, vbox, batches_tab) -> None: # --- Load in all batches --- # current_batch = self.data_requests["current_batch"] - self.load_batches(file_names, directory, vbox, current_batch) + self.load_batches(file_names, directory, current_batch) # --- JSON Parsing Timer --- # self.update_json_timer = QTimer() @@ -135,7 +137,9 @@ def create_logs_widget(self, vbox, logs_tab) -> None: self.table_widget.setHorizontalHeaderLabels(["Commands"]) vbox.addWidget(self.table_widget) - vbox.addWidget(QPushButton("Save", self, clicked=self.save_data)) + save_button = QPushButton("Save") + save_button.clicked.connect(self.save_data) + vbox.addWidget(save_button) self.load_logs() @@ -143,36 +147,44 @@ def create_logs_widget(self, vbox, logs_tab) -> None: return None - def load_requests(self, vbox) -> None: + def load_requests(self) -> None: for idx, request in enumerate(self.data_requests["requests"]): # --- Insert row number {forloopnumber} --- # row = self.table_widget.rowCount() self.table_widget.insertRow(row) - # --- Create Button --- # + # --- Create Buttons --- # add_request_button = QPushButton("Add", self) + window_button = QPushButton("Open", self) + add_request_button.clicked.connect(lambda _, request_id=str(request): self.add_request_to_batch(request_id)) + window_button.clicked.connect(lambda _, request_id=request: self.new_request_window(request_id)) + + self.request_buttons.append((add_request_button, window_button)) # --- Insert data into row --- # self.table_widget.setItem(row, 0, QTableWidgetItem(str(request))) self.table_widget.setItem(row, 1, QTableWidgetItem(str(self.data_requests["requests"][request]["url"]))) self.table_widget.setItem(row, 2, QTableWidgetItem(str(self.data_requests["requests"][request]["method"]))) self.table_widget.setItem(row, 3, QTableWidgetItem(str(self.data_requests["requests"][request]["timestamp"]))) + headers = self.data_requests["requests"][request].get("headers", {}) host = headers.get("Host", "") self.table_widget.setItem(row, 4, QTableWidgetItem(str(host))) + self.table_widget.setCellWidget(row, 5, add_request_button) + self.table_widget.setCellWidget(row, 6, window_button) self.remove_empty_rows() return None - def load_batches(self, file_names, directory, vbox, current_batch) -> callable([]): + def load_batches(self, file_names, directory, current_batch) -> callable([]): self.batch_buttons.clear() def load_table(): for idx, name in enumerate(file_names): - # --- Create commandbuttons --- # + # --- Create command-buttons --- # current_button = QPushButton("Set Current", self) window_button = QPushButton("Open", self) @@ -222,7 +234,8 @@ def add_request_to_batch(self, request_id) -> None: return None - def get_json_data(self, directory, name) -> dict: + @staticmethod + def get_json_data(directory, name) -> dict: with open(os.path.join(directory, name + ".json"), "r") as file: data = json.load(file) @@ -296,6 +309,15 @@ def new_batch_window(self, batch_name) -> None: return None + def new_request_window(self, request_id) -> None: + self.save_data() + self.update_json_timer.stop() + self.request_window = RequestWindow(request_id, self.racer, self.state, self.command_processor) + self.request_window.show() + self.hide() + + return None + def create_new_batch(self, batch_name) -> None: batch_name = batch_name.text() self.racer.gui_create_new_batch(batch_name) @@ -303,10 +325,11 @@ def create_new_batch(self, batch_name) -> None: return None - def showNotification(self, notiText) -> None: + @staticmethod + def showNotification(notifyText) -> None: messageBox = QMessageBox() messageBox.setIcon(QMessageBox.Information) - messageBox.setText(notiText) + messageBox.setText(notifyText) messageBox.setGeometry(0, 0, 500, 50) @@ -467,3 +490,141 @@ def showNotification(notifyText) -> None: messageBox.exec() return None + + +class RequestWindow(QMainWindow): + def __init__(self, request_id, racer, state, command_processor): + super().__init__() + + self.request_id = request_id + self.racer = racer + self.state = state + self.command_processor = command_processor + + self.general_window = None + self.update_json_timer = None + + self.table_widget = QWidget() + + self.init_ui() + + def init_ui(self): + vbox = QVBoxLayout() + + request_tab = QWidget() + request_tab.setLayout(vbox) + request_tab.layout().addWidget(self.table_widget) + + tabs = QTabWidget() + tabs.addTab(request_tab, "Request") + + vbox.addStretch() + + self.add_button_widget(vbox) + self.setCentralWidget(tabs) + self.load_request() + + vbox.insertWidget(0, self.table_widget) + + self.update_json_timer = QTimer() + self.update_json_timer.timeout.connect(self.reload_json) + self.update_json_timer.start(10000) + + def load_request(self) -> None: + requests_data = load_json("state/state.json")["requests"] + request_data = requests_data.get(str(self.request_id)) + + if not request_data: + return + + # --- Ready the data --- # + body = request_data.get("body", "") + headers = request_data.get("headers", {}) + method = request_data.get("method", "") + timestamp = request_data.get("timestamp", "") + url = request_data.get("url", "") + request_id = request_data.get("id", "") + + # --- Create model and add headers --- # + model = QStandardItemModel() + model.setHorizontalHeaderLabels(["Field", "Value"]) + + # --- Insert data into rows --- # + model.appendRow([QStandardItem("Request ID"), QStandardItem(str(request_id))]) + model.appendRow([QStandardItem("URL"), QStandardItem(url)]) + model.appendRow([QStandardItem("Method"), QStandardItem(method)]) + model.appendRow([QStandardItem("Timestamp"), QStandardItem(str(timestamp))]) + model.appendRow([QStandardItem("Body"), QStandardItem(body)]) + for key, value in headers.items(): + model.appendRow([QStandardItem(key), QStandardItem(value)]) + + table_view = QTableView() + table_view.setModel(model) + + table_view.horizontalHeader().setStretchLastSection(True) + table_view.verticalHeader().setVisible(False) + table_view.setShowGrid(True) + table_view.setEditTriggers(QTableView.NoEditTriggers) + + # Set grid color to background color + table_view.setStyleSheet( + "QTableView::item {border-bottom: 1px solid black;} QTableView {background-color: white;}") + table_view.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) + table_view.setColumnWidth(0, 300) + + self.table_widget = table_view + self.layout().addWidget(self.table_widget) + + return None + + def add_button_widget(self, vbox) -> None: + quit_button = QPushButton("Quit") + go_back_button = QPushButton("Go Back") + + quit_button.clicked.connect(QApplication.quit) + go_back_button.clicked.connect(self.go_back) + + vbox.addWidget(quit_button, alignment=Qt.AlignBottom) + vbox.addWidget(go_back_button, alignment=Qt.AlignBottom) + + return None + + def go_back(self) -> None: + self.general_window = MainGUI(self.racer, self.state, self.command_processor) + self.general_window.show() + self.deleteLater() + + return None + + def save_data(self) -> None: + self.racer.comm_general_save(True) + + return None + + def reload_json(self) -> None: + if self.isActiveWindow(): + self.save_data() + self.update_json_timer.stop() + self.hide() + self.general_window = RequestWindow(self.request_id, self.racer, self.state, self.command_processor) + self.general_window.show() + self.deleteLater() + + return None + + @staticmethod + def showNotification(notifyText) -> None: + messageBox = QMessageBox() + messageBox.setIcon(QMessageBox.Information) + messageBox.setText(notifyText) + + messageBox.setGeometry(0, 0, 500, 50) + + timer = QTimer() + timer.setSingleShot(True) + timer.timeout.connect(messageBox.close) + timer.start(5000) + + messageBox.exec() + + return None From b9f4b97f66c8ea175c19b811ccb8aa226d3ce7e3 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 23 Feb 2023 14:18:21 +0100 Subject: [PATCH 03/48] Added remove request --- CompuRacer_Core/src/command_processor.py | 2 +- CompuRacer_Core/src/compu_racer_core.py | 23 +++++++++++++++ CompuRacer_Core/src/gui.py | 37 +++++++++++++++--------- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/CompuRacer_Core/src/command_processor.py b/CompuRacer_Core/src/command_processor.py index 6591298..7242b81 100644 --- a/CompuRacer_Core/src/command_processor.py +++ b/CompuRacer_Core/src/command_processor.py @@ -21,7 +21,7 @@ from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtWidgets import QApplication -__version__ = "v1" +__version__ = "v1.1.0" class GuiThread(QThread): start_gui_signal = pyqtSignal() diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index 623543a..2a30e0f 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -1111,6 +1111,29 @@ def request_used_in(self, request_id): used_in.append(batch_name) return used_in + def gui_remove_request(self, request_id): + self.rem_request_gui(request_id, False) + + def rem_request_gui(self, request_id, ask_confirmation=False): + if request_id not in self.state['requests']: + self.print_formatted(f"Cannot remove request:\n\t" + f"The request with id '{request_id}' is not in the total request list!", + utils.QType.ERROR) + return -1 + used_in = self.request_used_in(self, request_id) + if used_in: + for batch_name in used_in: + self.state['batches'][batch_name].remove(request_id) + ask_confirmation = False + + if not ask_confirmation or self.command_processor.accept_yes_no( + f"Are you sure you want to remove the request with id '{request_id}'?", + utils.QType.WARNING): + self.__change_state('requests', sub_search=request_id, do_delete=True) + self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) + else: + self.print_formatted(f"Removal of request cancelled.", utils.QType.INFORMATION) + @staticmethod # do not add requests to this list in any other way def rem_request(self, request_id, ask_confirmation=False): with self.requests_list_lock: diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index c9e2058..202d675 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -69,12 +69,12 @@ def create_request_widget(self, vbox, requests_tab) -> None: vbox.addWidget(QLabel("Requests Information")) # --- Creating Table --- # - self.table_widget = QTableWidget(len(self.data_requests["requests"]), 7) + self.table_widget = QTableWidget(len(self.data_requests["requests"]), 8) self.table_widget.setColumnWidth(0, 30) self.table_widget.setColumnWidth(1, 400) self.table_widget.setColumnWidth(3, 200) self.table_widget.setColumnWidth(4, 100) - self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open"]) + self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open", "Remove"]) vbox.addWidget(self.table_widget) self.load_requests() @@ -147,6 +147,22 @@ def create_logs_widget(self, vbox, logs_tab) -> None: return None + def create_requests_button_widget(self, request, row) -> None: + add_request_button = QPushButton("Add", self) + window_button = QPushButton("Open", self) + remove_button = QPushButton("Remove", self) + + add_request_button.clicked.connect(lambda _, request_id=str(request): self.add_request_to_batch(request_id)) + window_button.clicked.connect(lambda _, request_id=request: self.new_request_window(request_id)) + remove_button.clicked.connect(lambda _, request_id=request: self.remove_request(request_id)) + + self.request_buttons.append((add_request_button, window_button, remove_button)) + + self.table_widget.setCellWidget(row, 5, add_request_button) + self.table_widget.setCellWidget(row, 6, window_button) + self.table_widget.setCellWidget(row, 7, remove_button) + return None + def load_requests(self) -> None: for idx, request in enumerate(self.data_requests["requests"]): # --- Insert row number {forloopnumber} --- # @@ -154,13 +170,7 @@ def load_requests(self) -> None: self.table_widget.insertRow(row) # --- Create Buttons --- # - add_request_button = QPushButton("Add", self) - window_button = QPushButton("Open", self) - - add_request_button.clicked.connect(lambda _, request_id=str(request): self.add_request_to_batch(request_id)) - window_button.clicked.connect(lambda _, request_id=request: self.new_request_window(request_id)) - - self.request_buttons.append((add_request_button, window_button)) + self.create_requests_button_widget(request, row) # --- Insert data into row --- # self.table_widget.setItem(row, 0, QTableWidgetItem(str(request))) @@ -172,9 +182,6 @@ def load_requests(self) -> None: host = headers.get("Host", "") self.table_widget.setItem(row, 4, QTableWidgetItem(str(host))) - self.table_widget.setCellWidget(row, 5, add_request_button) - self.table_widget.setCellWidget(row, 6, window_button) - self.remove_empty_rows() return None @@ -228,14 +235,16 @@ def load_logs(self) -> None: self.remove_empty_rows() return None + def remove_request(self, request_id): + self.racer.gui_remove_request(request_id) + def add_request_to_batch(self, request_id) -> None: self.showNotification("RequestID " + request_id + " has been added to active Batch!") self.racer.comm_curr_add(self.state, request_id) return None - @staticmethod - def get_json_data(directory, name) -> dict: + def get_json_data(self, directory, name) -> dict: with open(os.path.join(directory, name + ".json"), "r") as file: data = json.load(file) From 42b2b79eff73b4d041226f82e20e74b345e7c650 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Fri, 24 Feb 2023 13:52:16 +0100 Subject: [PATCH 04/48] work in progress --- CompuRacer_Core/src/compu_racer_core.py | 31 ++++--------------- CompuRacer_Core/src/gui.py | 40 ++++++++++++++----------- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index 2a30e0f..3b3adc6 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -1112,27 +1112,8 @@ def request_used_in(self, request_id): return used_in def gui_remove_request(self, request_id): - self.rem_request_gui(request_id, False) - - def rem_request_gui(self, request_id, ask_confirmation=False): - if request_id not in self.state['requests']: - self.print_formatted(f"Cannot remove request:\n\t" - f"The request with id '{request_id}' is not in the total request list!", - utils.QType.ERROR) - return -1 - used_in = self.request_used_in(self, request_id) - if used_in: - for batch_name in used_in: - self.state['batches'][batch_name].remove(request_id) - ask_confirmation = False - - if not ask_confirmation or self.command_processor.accept_yes_no( - f"Are you sure you want to remove the request with id '{request_id}'?", - utils.QType.WARNING): - self.__change_state('requests', sub_search=request_id, do_delete=True) - self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) - else: - self.print_formatted(f"Removal of request cancelled.", utils.QType.INFORMATION) + curr_batch = self.state['batches'][self.state['current_batch']] + curr_batch.remove(request_id, None) @staticmethod # do not add requests to this list in any other way def rem_request(self, request_id, ask_confirmation=False): @@ -1155,10 +1136,10 @@ def rem_request(self, request_id, ask_confirmation=False): utils.QType.ERROR) return -1 # remove request from the batches - if not self.command_processor.accept_yes_no(f"The request with id '{request_id}' is used by batches: " - f"{used_in}, continue?\n\tIt will be removed from these batches and their results are cleared!!", - utils.QType.WARNING): - return -1 + # if not self.command_processor.accept_yes_no(f"The request with id '{request_id}' is used by batches: " + # f"{used_in}, continue?\n\tIt will be removed from these batches and their results are cleared!!", + # utils.QType.WARNING): + # return -1 # remove request from the batches for batch_name in used_in: self.state['batches'][batch_name].remove(request_id) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 202d675..13a4bb8 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -150,17 +150,14 @@ def create_logs_widget(self, vbox, logs_tab) -> None: def create_requests_button_widget(self, request, row) -> None: add_request_button = QPushButton("Add", self) window_button = QPushButton("Open", self) - remove_button = QPushButton("Remove", self) add_request_button.clicked.connect(lambda _, request_id=str(request): self.add_request_to_batch(request_id)) window_button.clicked.connect(lambda _, request_id=request: self.new_request_window(request_id)) - remove_button.clicked.connect(lambda _, request_id=request: self.remove_request(request_id)) - self.request_buttons.append((add_request_button, window_button, remove_button)) + self.request_buttons.append((add_request_button, window_button)) self.table_widget.setCellWidget(row, 5, add_request_button) self.table_widget.setCellWidget(row, 6, window_button) - self.table_widget.setCellWidget(row, 7, remove_button) return None def load_requests(self) -> None: @@ -235,9 +232,6 @@ def load_logs(self) -> None: self.remove_empty_rows() return None - def remove_request(self, request_id): - self.racer.gui_remove_request(request_id) - def add_request_to_batch(self, request_id) -> None: self.showNotification("RequestID " + request_id + " has been added to active Batch!") self.racer.comm_curr_add(self.state, request_id) @@ -352,13 +346,6 @@ def showNotification(notifyText) -> None: return None -def load_json(filepath) -> dict: - with open(filepath, 'r') as file: - data = json.load(file) - - return data - - class BatchWindow(QMainWindow): def __init__(self, batch_name, racer, state, command_processor) -> None: super().__init__() @@ -407,8 +394,8 @@ def create_requests_widget(self, vbox) -> None: vbox.addWidget(QLabel("")) self.table_widget = QTableWidget() - self.table_widget.setColumnCount(4) - self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Host"]) + self.table_widget.setColumnCount(5) + self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Host", "Remove"]) self.table_widget.setColumnWidth(0, 50) self.table_widget.setColumnWidth(1, 50) self.table_widget.setColumnWidth(2, 300) @@ -418,6 +405,12 @@ def create_requests_widget(self, vbox) -> None: return None + def load_json(self, filepath): + with open(filepath, 'r') as file: + data = json.load(file) + + return data + def add_button_widget(self, vbox) -> None: send_batch_button = QPushButton("Send Batch") go_back_button = QPushButton("Go Back") @@ -434,8 +427,8 @@ def add_button_widget(self, vbox) -> None: return None def add_request_table(self) -> None: - items = load_json("state/batches/" + self.batch_name + ".json")["items"] - requests = load_json("state/state.json")["requests"] + items = self.load_json("state/batches/" + self.batch_name + ".json")["items"] + requests = self.load_json("state/state.json")["requests"] # --- Load in all data --- # for i, item in enumerate(items): @@ -451,8 +444,19 @@ def add_request_table(self) -> None: self.table_widget.setItem(i, 2, QTableWidgetItem(url)) self.table_widget.setItem(i, 3, QTableWidgetItem(host)) + remove_item = QTableWidgetItem() + remove_item.setFlags(Qt.ItemIsEnabled) + self.table_widget.setItem(i, 4, remove_item) + + remove_button = QPushButton("Remove") + remove_button.clicked.connect(lambda _, request_id=request_id: self.remove_request(request_id)) + self.table_widget.setCellWidget(i, 4, remove_button) + return None + def remove_request(self, request_id): + self.racer.gui_remove_request(request_id) + def send_batch(self) -> None: self.save_data() self.update_json_timer.stop() From 0dbe748ec5b5fb5722250ab87f8151fa2c1d1d72 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Tue, 28 Mar 2023 10:22:32 +0200 Subject: [PATCH 05/48] Removed Notifications --- CompuRacer_Core/src/gui.py | 54 -------------------------------------- 1 file changed, 54 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 13a4bb8..59ff5d4 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -233,7 +233,6 @@ def load_logs(self) -> None: return None def add_request_to_batch(self, request_id) -> None: - self.showNotification("RequestID " + request_id + " has been added to active Batch!") self.racer.comm_curr_add(self.state, request_id) return None @@ -299,7 +298,6 @@ def reload_json(self) -> None: def set_current_batch(self, batch_name) -> None: self.racer.set_curr_batch_by_name(batch_name) self.current_batch = batch_name - self.showNotification("Set current batch to " + batch_name) return None @@ -324,24 +322,6 @@ def new_request_window(self, request_id) -> None: def create_new_batch(self, batch_name) -> None: batch_name = batch_name.text() self.racer.gui_create_new_batch(batch_name) - self.showNotification("Added New Batch " + batch_name + ". Add a request to your batch so you can open your batch") - - return None - - @staticmethod - def showNotification(notifyText) -> None: - messageBox = QMessageBox() - messageBox.setIcon(QMessageBox.Information) - messageBox.setText(notifyText) - - messageBox.setGeometry(0, 0, 500, 50) - - timer = QTimer() - timer.setSingleShot(True) - timer.timeout.connect(messageBox.close) - timer.start(5000) - - messageBox.exec() return None @@ -487,23 +467,6 @@ def reload_json(self) -> None: return None - @staticmethod - def showNotification(notifyText) -> None: - messageBox = QMessageBox() - messageBox.setIcon(QMessageBox.Information) - messageBox.setText(notifyText) - - messageBox.setGeometry(0, 0, 500, 50) - - timer = QTimer() - timer.setSingleShot(True) - timer.timeout.connect(messageBox.close) - timer.start(5000) - - messageBox.exec() - - return None - class RequestWindow(QMainWindow): def __init__(self, request_id, racer, state, command_processor): @@ -624,20 +587,3 @@ def reload_json(self) -> None: self.deleteLater() return None - - @staticmethod - def showNotification(notifyText) -> None: - messageBox = QMessageBox() - messageBox.setIcon(QMessageBox.Information) - messageBox.setText(notifyText) - - messageBox.setGeometry(0, 0, 500, 50) - - timer = QTimer() - timer.setSingleShot(True) - timer.timeout.connect(messageBox.close) - timer.start(5000) - - messageBox.exec() - - return None From 689ce8ea3e882c2c202e1e425e81116d9db0dbf4 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:25:48 +0200 Subject: [PATCH 06/48] deleted comment --- CompuRacer_Core/src/compu_racer_core.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index 3b3adc6..b5f4188 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -1135,12 +1135,6 @@ def rem_request(self, request_id, ask_confirmation=False): f"{used_in}. It must be removed individually.", utils.QType.ERROR) return -1 - # remove request from the batches - # if not self.command_processor.accept_yes_no(f"The request with id '{request_id}' is used by batches: " - # f"{used_in}, continue?\n\tIt will be removed from these batches and their results are cleared!!", - # utils.QType.WARNING): - # return -1 - # remove request from the batches for batch_name in used_in: self.state['batches'][batch_name].remove(request_id) ask_confirmation = False From 3cbffc351d7e65bf1b01d3a43b5b1204476eeb57 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:26:04 +0200 Subject: [PATCH 07/48] added new unstatic command --- CompuRacer_Core/src/compu_racer_core.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index b5f4188..1264d5b 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -1979,6 +1979,31 @@ def comm_curr_remove(self, request_id=None, wait_time=None): else: self.print_formatted(f"Removal of current batch requests cancelled.", utils.QType.INFORMATION) + def gui_comm_curr_remove(self, request_id=None, wait_time=None): + """ + Removes requests from the current batch + :param self: reference to the CompuRacer + :param request_id: the request to remove, or if None, all requests + :param wait_time: the wait_time of the request to remove, or if None, all regardless of wait_time + :return: 0 on success and -1 on error + """ + if not self.state['current_batch']: + self.print_formatted( + f"Cannot remove a request from current batch: There is no current batch! First, select a current batch.", + utils.QType.ERROR) + return -1 + curr_batch = self.state['batches'][self.state['current_batch']] + if curr_batch.is_empty(): + self.print_formatted(f"Cannot remove a request from current batch: The current batch is empty!", + utils.QType.ERROR) + return -1 + if request_id is None: + # remove all items from the batch + question = "Are you sure you want to remove all requests from the current batch?" + self.print_formatted("Dit is een andere test voor request nummer : " + request_id) + + curr_batch.remove(request_id, wait_time) + # ------------------------------------------------------------------------------------------------- # # ------------------------------------- Main helper functions ------------------------------------- # # ------------------------------------------------------------------------------------------------- # From 2eca9140d1a11e8b75a3aaed503d1d2ab3baecc3 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:26:27 +0200 Subject: [PATCH 08/48] fixed request widget bug --- CompuRacer_Core/src/gui.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 59ff5d4..e2bdf6f 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -370,21 +370,14 @@ def init_ui(self) -> None: return None - def create_requests_widget(self, vbox) -> None: - vbox.addWidget(QLabel("")) - + def create_requests_widget(self, vbox): self.table_widget = QTableWidget() + vbox.addWidget(QLabel("")) self.table_widget.setColumnCount(5) self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Host", "Remove"]) - self.table_widget.setColumnWidth(0, 50) - self.table_widget.setColumnWidth(1, 50) - self.table_widget.setColumnWidth(2, 300) - self.table_widget.setColumnWidth(3, 100) self.add_request_table() - return None - def load_json(self, filepath): with open(filepath, 'r') as file: data = json.load(file) From f93011e0350f53551d97d83cc510160ffa6f2bd7 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:26:52 +0200 Subject: [PATCH 09/48] Added abiity to remove requests --- CompuRacer_Core/src/gui.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index e2bdf6f..8fbd548 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -150,14 +150,18 @@ def create_logs_widget(self, vbox, logs_tab) -> None: def create_requests_button_widget(self, request, row) -> None: add_request_button = QPushButton("Add", self) window_button = QPushButton("Open", self) + remove_button = QPushButton("Remove", self) add_request_button.clicked.connect(lambda _, request_id=str(request): self.add_request_to_batch(request_id)) window_button.clicked.connect(lambda _, request_id=request: self.new_request_window(request_id)) + remove_button.clicked.connect(lambda _, request_id=str(request): self.remove_request(request_id)) - self.request_buttons.append((add_request_button, window_button)) + self.request_buttons.append((add_request_button, window_button, remove_button)) self.table_widget.setCellWidget(row, 5, add_request_button) self.table_widget.setCellWidget(row, 6, window_button) + self.table_widget.setCellWidget(row, 7, remove_button) + return None def load_requests(self) -> None: @@ -301,6 +305,11 @@ def set_current_batch(self, batch_name) -> None: return None + def remove_request(self, request_id) -> None: + self.racer.gui_comm_curr_remove(request_id) + + return None + def new_batch_window(self, batch_name) -> None: self.save_data() self.update_json_timer.stop() From e2ac2546cbc074f230173d20fd41aca39e3d6986 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:27:31 +0200 Subject: [PATCH 10/48] Changed ability to remove requests --- CompuRacer_Core/src/gui.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 8fbd548..2a7b1ee 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -412,7 +412,18 @@ def add_request_table(self) -> None: items = self.load_json("state/batches/" + self.batch_name + ".json")["items"] requests = self.load_json("state/state.json")["requests"] - # --- Load in all data --- # + self.table_widget = QTableWidget(len(items), 5, self) + self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host", "Remove"]) + self.table_widget.setColumnWidth(0, 50) + self.table_widget.setColumnWidth(1, 50) + self.table_widget.setColumnWidth(2, 300) + self.table_widget.setColumnWidth(3, 100) + self.table_widget.setColumnWidth(4, 100) + + remove_button = QPushButton("Remove", self) + + self.table_widget.verticalHeader().hide() + for i, item in enumerate(items): request_id = item["key"][0] request = requests[request_id] @@ -458,6 +469,11 @@ def save_data(self) -> None: return None + def remove_request(self, request_id) -> None: + self.racer.gui_comm_curr_remove(request_id) + + return None + def reload_json(self) -> None: if self.isActiveWindow(): self.save_data() From 9bf8587e26365bf1f87ecd4fdfa5e4db880c9e99 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:27:41 +0200 Subject: [PATCH 11/48] cleanup --- CompuRacer_Core/src/gui.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 2a7b1ee..ca5e266 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -436,19 +436,12 @@ def add_request_table(self) -> None: self.table_widget.setItem(i, 1, QTableWidgetItem(method)) self.table_widget.setItem(i, 2, QTableWidgetItem(url)) self.table_widget.setItem(i, 3, QTableWidgetItem(host)) - - remove_item = QTableWidgetItem() - remove_item.setFlags(Qt.ItemIsEnabled) - self.table_widget.setItem(i, 4, remove_item) - - remove_button = QPushButton("Remove") - remove_button.clicked.connect(lambda _, request_id=request_id: self.remove_request(request_id)) self.table_widget.setCellWidget(i, 4, remove_button) - return None + remove_button.clicked.connect(lambda _, request_id=str(request_id): self.remove_request(request_id)) + self.racer.print_formatted("Dit is een test voor request : " + request_id) - def remove_request(self, request_id): - self.racer.gui_remove_request(request_id) + return None def send_batch(self) -> None: self.save_data() From 470a2818928ffb96b979409fa3bb5b2a4c77c9e1 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:27:51 +0200 Subject: [PATCH 12/48] Bug fixes --- CompuRacer_Core/src/gui.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index ca5e266..5a086a1 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -247,20 +247,20 @@ def get_json_data(self, directory, name) -> dict: return data - def check_current_batch(self, name, row, current_button, window_button, current_batch) -> None: + def check_current_batch(self, name, row, button1, button2, current_batch) -> None: if name == current_batch: for col in range(self.table_widget.columnCount()): item = self.table_widget.item(row, col) if item is not None: item.setBackground(Qt.gray) - current_button.setEnabled(False) - window_button.setEnabled(True) + button1.setEnabled(False) + button2.setEnabled(True) else: - window_button.setEnabled(False) + button2.setEnabled(False) if name == "Imm": - current_button.setEnabled(False) - window_button.setEnabled(False) + button1.setEnabled(False) + button2.setEnabled(False) return None @@ -518,7 +518,7 @@ def init_ui(self): self.update_json_timer.start(10000) def load_request(self) -> None: - requests_data = load_json("state/state.json")["requests"] + requests_data = self.load_json("state/state.json")["requests"] request_data = requests_data.get(str(self.request_id)) if not request_data: @@ -576,6 +576,12 @@ def add_button_widget(self, vbox) -> None: return None + def load_json(self, filepath): + with open(filepath, 'r') as file: + data = json.load(file) + + return data + def go_back(self) -> None: self.general_window = MainGUI(self.racer, self.state, self.command_processor) self.general_window.show() From cfb963ae17abe095537236adff99cd04b9daf8e6 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 5 Apr 2023 14:48:51 +0200 Subject: [PATCH 13/48] Update v1.1.0 --- CompuRacer_Core/src/compu_racer_core.py | 127 ++++-------------------- CompuRacer_Core/src/gui.py | 12 +-- 2 files changed, 27 insertions(+), 112 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index 1264d5b..17f1b11 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -261,6 +261,16 @@ def comm_general_save(self, do_print=True): elif do_print: self.print_formatted("Done.", string_type=utils.QType.INFORMATION) + def gui_storing_json(self): + """ + Stores the current CompuRacer state via the GUI + """ + state_to_save = copy.deepcopy(self.state) + state_to_save['batches'] = {} + self.__store_json(self.CLIENT_CONFIG, state_to_save, self.CLIENT_BACKUP) + + self.print_formatted("Done storing.", string_type=utils.QType.INFORMATION) + def comm_general_shutdown(self, args=None): """ Shuts down the CompuRacer normally @@ -523,7 +533,7 @@ def add_commands_batches(self): arg_spec_opt=[("Index of the batch", int, "* the current batch *"), ("Print result summary", bool, True)] ) - self.command_processor.add_command(["add bs", "add batch"], self.comm_batches_create_new_static, + self.command_processor.add_command(["add bs", "add batch"], self.comm_batches_create_new, "Creates a new batch by name and sets it as current batch (must be unique)", self, arg_spec=[("Name of the batch", str)], @@ -624,7 +634,7 @@ def add_commands_current_batch(self): "Sets the current batch send timout (default 20 seconds).", self, arg_spec_opt=[("send timeout >= 1", int, 20)] ) - self.command_processor.add_command(["add"], self.comm_curr_add_static, + self.command_processor.add_command(["add"], self.comm_curr_add, "Adds a request to the current batch by ID, wait_time, parallel and sequential duplicates", self, arg_spec=[("Request ID", str)], @@ -1059,15 +1069,9 @@ def add_request(self, a_request, used_from_interface=False, print_information=Tr self.rem_batch_by_name(self, self.immediate_batch_name, True) if self.immediate_batch_name not in self.state['batches']: # create new immediate batch - if self.cli_check: - return self.comm_batches_create_new_static(self, self.immediate_batch_name, False, - not used_from_interface, - allow_redirects, sync_last_byte, send_timeout) - else: - return self.comm_batches_create_new(self, self.immediate_batch_name, False, - not used_from_interface, - allow_redirects, sync_last_byte, send_timeout) - + return self.comm_batches_create_new_st(self, self.immediate_batch_name, False, + not used_from_interface, + allow_redirects, sync_last_byte, send_timeout) immediate_batch = self.state['batches'][self.immediate_batch_name] try: immediate_batch.add(req_id, 0, par, seq, False) @@ -1111,10 +1115,6 @@ def request_used_in(self, request_id): used_in.append(batch_name) return used_in - def gui_remove_request(self, request_id): - curr_batch = self.state['batches'][self.state['current_batch']] - curr_batch.remove(request_id, None) - @staticmethod # do not add requests to this list in any other way def rem_request(self, request_id, ask_confirmation=False): with self.requests_list_lock: @@ -1161,9 +1161,6 @@ def get_batch_result_formatting(): re.compile(r"'status_code': 4.."): utils.QType.RED, re.compile(r"'status_code': 5.."): utils.QType.BLUE} - def gui_send_batches(self): - self.comm_batches_send(self) - @staticmethod def comm_batches_send(self, index=None, print_results=True, immediate_allowed=False): name = self.batch_index_to_name(self, index) @@ -1219,10 +1216,7 @@ def comm_batches_set_current(self, index, immediate_allowed=False): name = self.batch_index_to_name(self, index) if name == -1: return -1 - if self.cli_check: - return self.set_curr_batch_by_name_static(self, name, immediate_allowed) - else: - return self.set_curr_batch_by_name(self, name, immediate_allowed) + return self.set_curr_batch_by_name(self, name, immediate_allowed) @staticmethod def add_prefix(self, name): @@ -1232,7 +1226,7 @@ def add_prefix(self, name): return self.state['project_name'] + name @staticmethod - def comm_batches_create_new_static(self, name, set_current_batch=True, immediate_allowed=False, + def comm_batches_create_new(self, name, set_current_batch=True, immediate_allowed=False, allow_redirects=False, sync_last_byte=False, send_timeout=20): if name != self.immediate_batch_name: name = self.add_prefix(self, name) @@ -1247,10 +1241,7 @@ def comm_batches_create_new_static(self, name, set_current_batch=True, immediate self.print_formatted(f"Created a new batch:", utils.QType.INFORMATION) self.print_formatted(new_batch.get_summary(), utils.QType.BLUE) if set_current_batch: - return self.set_curr_batch_by_name_static(self, name) - - def gui_create_new_batch(self, name): - self.comm_batches_create_new_static(self, name) + return self.set_curr_batch_by_name(self, name) @staticmethod def comm_batches_get_project(self): @@ -1472,14 +1463,6 @@ def batch_index_to_name(self, index, indices=None): return indices[index] @staticmethod - def set_curr_batch_by_name_static(self, name, immediate_allowed=False): - if not immediate_allowed and name == self.immediate_batch_name: - self.print_formatted(f"Not allowed to set immediate batch as current batch from interface!", - utils.QType.ERROR) - return -1 - self.__change_state('current_batch', name) - self.print_formatted(f"Set current batch to batch with name '{name}'.", utils.QType.INFORMATION) - def set_curr_batch_by_name(self, name, immediate_allowed=False): if not immediate_allowed and name == self.immediate_batch_name: self.print_formatted(f"Not allowed to set immediate batch as current batch from interface!", @@ -1796,7 +1779,7 @@ def comm_curr_compare_groups(self, group_nr_1, group_nr_2, request_id=None): # NOTE: it does not overwrite an item with the same id & wait_time. @staticmethod - def comm_curr_add_static(self, request_id, wait_time=0, dup_par=1, dup_seq=1): + def comm_curr_add(self, request_id, wait_time=0, dup_par=1, dup_seq=1): """ Adds the request with this wait time and the parallel and sequential values to the current batch :param self: reference to the CompuRacer @@ -1827,37 +1810,6 @@ def comm_curr_add_static(self, request_id, wait_time=0, dup_par=1, dup_seq=1): f"{curr_batch.get_info(request_id, wait_time)}", utils.QType.INFORMATION) - def comm_curr_add(self, state, request_id, wait_time=0, dup_par=1, dup_seq=1): - """ - Adds the request with this wait time and the parallel and sequential values to the current batch - :param self: reference to the CompuRacer - :param request_id: the id of the request - :param wait_time: the wait time of the request before sending it - :param dup_par: the parallel duplication - :param dup_seq: the parallel sequential - :return: 0 on success and -1 on error - :return: - """ - if request_id not in state['requests']: - self.print_formatted( - f"Cannot add a request to current batch: The request with id '{request_id}' is not in the request list!", - utils.QType.ERROR) - return -1 - if not state['current_batch']: - self.print_formatted( - f"Cannot add a request to current batch: There is no current batch! First, select a current batch.", - utils.QType.ERROR) - return -1 - curr_batch = self.state['batches'][self.state['current_batch']] - try: - curr_batch.add(request_id, wait_time, dup_par, dup_seq, False) - except Exception as e: - self.print_formatted(f"Cannot add a request to current batch:\n\t{e}", utils.QType.ERROR) - return -1 - self.print_formatted(f"The request was added to the current batch:\n" - f"{curr_batch.get_info(request_id, wait_time)}", - utils.QType.INFORMATION) - # NOTE: it does not overwrite an item with the same id & wait_time. @staticmethod def comm_curr_update(self, request_id, wait_time=0, dup_par=1, dup_seq=1): @@ -1963,46 +1915,9 @@ def comm_curr_remove(self, request_id=None, wait_time=None): self.print_formatted(f"Cannot remove a request from current batch: The current batch is empty!", utils.QType.ERROR) return -1 - if request_id is None: - # remove all items from the batch - question = "Are you sure you want to remove all requests from the current batch?" - elif wait_time is None: - # remove all items with a certain ID from the batch - question = f"Are you sure you want to remove all requests with id '{request_id}' from the current batch?" - else: - # remove a specific item with a certain ID and wait_time from the batch - question = f"Are you sure you want to remove the request with id '{request_id}' and wait_time '{wait_time}' from the current batch?" - if self.command_processor.accept_yes_no(question, utils.QType.WARNING): - num_removed = curr_batch.remove(request_id, wait_time) - self.print_formatted(f"All matching requests are removed from the current batch.\nNumber: {num_removed}", + num_removed = curr_batch.remove(request_id, wait_time) + self.print_formatted(f"All matching requests are removed from the current batch.\nNumber: {num_removed}", utils.QType.INFORMATION) - else: - self.print_formatted(f"Removal of current batch requests cancelled.", utils.QType.INFORMATION) - - def gui_comm_curr_remove(self, request_id=None, wait_time=None): - """ - Removes requests from the current batch - :param self: reference to the CompuRacer - :param request_id: the request to remove, or if None, all requests - :param wait_time: the wait_time of the request to remove, or if None, all regardless of wait_time - :return: 0 on success and -1 on error - """ - if not self.state['current_batch']: - self.print_formatted( - f"Cannot remove a request from current batch: There is no current batch! First, select a current batch.", - utils.QType.ERROR) - return -1 - curr_batch = self.state['batches'][self.state['current_batch']] - if curr_batch.is_empty(): - self.print_formatted(f"Cannot remove a request from current batch: The current batch is empty!", - utils.QType.ERROR) - return -1 - if request_id is None: - # remove all items from the batch - question = "Are you sure you want to remove all requests from the current batch?" - self.print_formatted("Dit is een andere test voor request nummer : " + request_id) - - curr_batch.remove(request_id, wait_time) # ------------------------------------------------------------------------------------------------- # # ------------------------------------- Main helper functions ------------------------------------- # diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 5a086a1..ec076ac 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -237,7 +237,7 @@ def load_logs(self) -> None: return None def add_request_to_batch(self, request_id) -> None: - self.racer.comm_curr_add(self.state, request_id) + self.racer.comm_curr_add(self.racer, request_id) return None @@ -300,13 +300,13 @@ def reload_json(self) -> None: return None def set_current_batch(self, batch_name) -> None: - self.racer.set_curr_batch_by_name(batch_name) + self.racer.set_curr_batch_by_name(self.racer, batch_name) self.current_batch = batch_name return None def remove_request(self, request_id) -> None: - self.racer.gui_comm_curr_remove(request_id) + self.racer.comm_requests_remove(self.racer, request_id, None, False) return None @@ -330,7 +330,7 @@ def new_request_window(self, request_id) -> None: def create_new_batch(self, batch_name) -> None: batch_name = batch_name.text() - self.racer.gui_create_new_batch(batch_name) + self.racer.comm_batches_create_new(self.racer, batch_name) return None @@ -446,7 +446,7 @@ def add_request_table(self) -> None: def send_batch(self) -> None: self.save_data() self.update_json_timer.stop() - self.racer.gui_send_batches() + self.racer.comm_batches_send(self.racer) return None @@ -463,7 +463,7 @@ def save_data(self) -> None: return None def remove_request(self, request_id) -> None: - self.racer.gui_comm_curr_remove(request_id) + self.racer.comm_curr_remove(self.racer, request_id) return None From 4d1cbe6b6648ee99cc0146a1bdcc2422c51e1e55 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 5 Apr 2023 14:56:53 +0200 Subject: [PATCH 14/48] Fine tuning removing requests --- CompuRacer_Core/src/compu_racer_core.py | 26 +++++++++---------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index 17f1b11..a4b6736 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -883,7 +883,7 @@ def comm_requests_comp(self, request_id_1, request_id_2, print_matches=False): self.colorprint_comp_results(self, comp) @staticmethod # do not add requests to this list in any other way - def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_confirmation=True): + def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_confirmation=False): with self.requests_list_lock: if not self.state['requests']: self.print_formatted(f"There is no request to delete: The total request list is empty!", @@ -906,15 +906,12 @@ def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_ return elif request_id_last is not None: # remove a range of requests - if not ask_confirmation or self.command_processor.accept_yes_no( - f"Are you sure you want to remove requests with id between and including {request_id_first} and {request_id_last}?", - utils.QType.WARNING): - for i, request_id in enumerate(copy.deepcopy(list(self.state['requests'].keys()))): - if request_id_first <= request_id <= request_id_last: - if self.rem_request(self, request_id, False) == -1: - failed_requests.append(request_id) - else: - success_requests.append(request_id) + for i, request_id in enumerate(copy.deepcopy(list(self.state['requests'].keys()))): + if request_id_first <= request_id <= request_id_last: + if self.rem_request(self, request_id, False) == -1: + failed_requests.append(request_id) + else: + success_requests.append(request_id) else: self.print_formatted(f"Removal of range of requests cancelled.", utils.QType.INFORMATION) return @@ -1139,13 +1136,8 @@ def rem_request(self, request_id, ask_confirmation=False): self.state['batches'][batch_name].remove(request_id) ask_confirmation = False - if not ask_confirmation or self.command_processor.accept_yes_no( - f"Are you sure you want to remove the request with id '{request_id}'?", - utils.QType.WARNING): - self.__change_state('requests', sub_search=request_id, do_delete=True) - self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) - else: - self.print_formatted(f"Removal of request cancelled.", utils.QType.INFORMATION) + self.__change_state('requests', sub_search=request_id, do_delete=True) + self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) # --------------------------------------------------------------------------------------------------- # # ------------------------------------- Batch command functions ------------------------------------- # From d3867b325a5629c86618bb5d98275167ce0f870b Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 6 Apr 2023 13:34:42 +0200 Subject: [PATCH 15/48] Request updating --- CompuRacer_Core/src/compu_racer_core.py | 10 --- CompuRacer_Core/src/gui.py | 86 ++++++++++++++----------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index a4b6736..15c87b0 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -261,16 +261,6 @@ def comm_general_save(self, do_print=True): elif do_print: self.print_formatted("Done.", string_type=utils.QType.INFORMATION) - def gui_storing_json(self): - """ - Stores the current CompuRacer state via the GUI - """ - state_to_save = copy.deepcopy(self.state) - state_to_save['batches'] = {} - self.__store_json(self.CLIENT_CONFIG, state_to_save, self.CLIENT_BACKUP) - - self.print_formatted("Done storing.", string_type=utils.QType.INFORMATION) - def comm_general_shutdown(self, args=None): """ Shuts down the CompuRacer normally diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index ec076ac..74f4222 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -30,6 +30,7 @@ def __init__(self, racer, state, command_processor) -> None: self.current_batch = None self.data_requests = None self.table_widget = None + self.table_widget_requests = None self.command_processor = command_processor self.racer = racer @@ -69,17 +70,16 @@ def create_request_widget(self, vbox, requests_tab) -> None: vbox.addWidget(QLabel("Requests Information")) # --- Creating Table --- # - self.table_widget = QTableWidget(len(self.data_requests["requests"]), 8) - self.table_widget.setColumnWidth(0, 30) - self.table_widget.setColumnWidth(1, 400) - self.table_widget.setColumnWidth(3, 200) - self.table_widget.setColumnWidth(4, 100) - self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open", "Remove"]) - vbox.addWidget(self.table_widget) + self.table_widget_requests = QTableWidget() + self.table_widget_requests.setColumnCount(8) + self.table_widget_requests.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open", "Remove"]) + vbox.addWidget(self.table_widget_requests) self.load_requests() + self.update_json() requests_tab.setLayout(vbox) + self.table_widget_requests.show() return None @@ -120,14 +120,22 @@ def create_batch_widget(self, vbox, batches_tab) -> None: self.load_batches(file_names, directory, current_batch) # --- JSON Parsing Timer --- # - self.update_json_timer = QTimer() - self.update_json_timer.timeout.connect(self.reload_json) - self.update_json_timer.start(5000) + self.update_json() batches_tab.setLayout(vbox) return None + def update_json(self): + self.save_data() + self.load_requests() + + print("python1") + + self.update_json_timer = QTimer() + self.update_json_timer.timeout.connect(lambda: self.update_json()) + self.update_json_timer.start(5000) + def create_logs_widget(self, vbox, logs_tab) -> None: vbox.addWidget(QLabel("Logs")) @@ -158,34 +166,38 @@ def create_requests_button_widget(self, request, row) -> None: self.request_buttons.append((add_request_button, window_button, remove_button)) - self.table_widget.setCellWidget(row, 5, add_request_button) - self.table_widget.setCellWidget(row, 6, window_button) - self.table_widget.setCellWidget(row, 7, remove_button) + self.table_widget_requests.setCellWidget(row, 5, add_request_button) + self.table_widget_requests.setCellWidget(row, 6, window_button) + self.table_widget_requests.setCellWidget(row, 7, remove_button) return None - def load_requests(self) -> None: - for idx, request in enumerate(self.data_requests["requests"]): - # --- Insert row number {forloopnumber} --- # - row = self.table_widget.rowCount() - self.table_widget.insertRow(row) - - # --- Create Buttons --- # - self.create_requests_button_widget(request, row) - - # --- Insert data into row --- # - self.table_widget.setItem(row, 0, QTableWidgetItem(str(request))) - self.table_widget.setItem(row, 1, QTableWidgetItem(str(self.data_requests["requests"][request]["url"]))) - self.table_widget.setItem(row, 2, QTableWidgetItem(str(self.data_requests["requests"][request]["method"]))) - self.table_widget.setItem(row, 3, QTableWidgetItem(str(self.data_requests["requests"][request]["timestamp"]))) - - headers = self.data_requests["requests"][request].get("headers", {}) - host = headers.get("Host", "") - self.table_widget.setItem(row, 4, QTableWidgetItem(str(host))) - - self.remove_empty_rows() + def load_requests(self): + self.load_json_requests() + for request_id, request_data in self.data_requests["requests"].items(): + existing_row = None + for row in range(self.table_widget_requests.rowCount()): + if self.table_widget_requests.item(row, 0).text() == request_id: + existing_row = row + break - return None + if existing_row is not None: + self.table_widget_requests.setItem(existing_row, 1, QTableWidgetItem(str(request_data["url"]))) + self.table_widget_requests.setItem(existing_row, 2, QTableWidgetItem(str(request_data["method"]))) + self.table_widget_requests.setItem(existing_row, 3, QTableWidgetItem(str(request_data["timestamp"]))) + headers = request_data.get("headers", {}) + host = headers.get("Host", "") + self.table_widget_requests.setItem(existing_row, 4, QTableWidgetItem(str(host))) + else: + row = self.table_widget_requests.rowCount() + self.table_widget_requests.insertRow(row) + self.table_widget_requests.setItem(row, 0, QTableWidgetItem(str(request_id))) + self.table_widget_requests.setItem(row, 1, QTableWidgetItem(str(request_data["url"]))) + self.table_widget_requests.setItem(row, 2, QTableWidgetItem(str(request_data["method"]))) + self.table_widget_requests.setItem(row, 3, QTableWidgetItem(str(request_data["timestamp"]))) + headers = request_data.get("headers", {}) + host = headers.get("Host", "") + self.table_widget_requests.setItem(row, 4, QTableWidgetItem(str(host))) def load_batches(self, file_names, directory, current_batch) -> callable([]): self.batch_buttons.clear() @@ -277,14 +289,12 @@ def remove_empty_rows(self) -> None: return None - def load_json_requests(self) -> None: + def load_json_requests(self): with open('state/state.json', 'r') as f: self.data_requests = json.load(f) - return None - def save_data(self) -> None: - self.racer.comm_general_save(True) + self.racer.comm_general_save() return None From 0f124cce1ad21f071be3724a00c408922230d385 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 6 Apr 2023 13:40:34 +0200 Subject: [PATCH 16/48] Delete row on updating requests --- CompuRacer_Core/src/gui.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 74f4222..5a025a6 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -174,6 +174,15 @@ def create_requests_button_widget(self, request, row) -> None: def load_requests(self): self.load_json_requests() + rows_to_delete = [] + for row in range(self.table_widget_requests.rowCount()): + request_id = self.table_widget_requests.item(row, 0).text() + if request_id not in self.data_requests["requests"]: + rows_to_delete.append(row) + + for row in reversed(rows_to_delete): + self.table_widget_requests.removeRow(row) + for request_id, request_data in self.data_requests["requests"].items(): existing_row = None for row in range(self.table_widget_requests.rowCount()): @@ -199,6 +208,8 @@ def load_requests(self): host = headers.get("Host", "") self.table_widget_requests.setItem(row, 4, QTableWidgetItem(str(host))) + self.create_requests_button_widget(request_id, row) + def load_batches(self, file_names, directory, current_batch) -> callable([]): self.batch_buttons.clear() From dab905e9649398cbd3da32528525e1d057b71e13 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Fri, 7 Apr 2023 11:22:25 +0200 Subject: [PATCH 17/48] Update reloading batches --- CompuRacer_Core/src/gui.py | 133 ++++++++++++------------------------- 1 file changed, 42 insertions(+), 91 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 5a025a6..0d3a9f9 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -31,6 +31,9 @@ def __init__(self, racer, state, command_processor) -> None: self.data_requests = None self.table_widget = None self.table_widget_requests = None + self.table_widget_batches = None + self.file_names = None + self.directory = None self.command_processor = command_processor self.racer = racer @@ -47,6 +50,9 @@ def init_ui(self) -> None: self.showFullScreen() self.setWindowTitle("CompuRacer GUI") + self.directory = "state/batches" + self.file_names = load_json_batches(self.directory) + tabs = QTabWidget() general_tab = QWidget() logs_tab = QWidget() @@ -62,6 +68,8 @@ def init_ui(self) -> None: self.create_batch_widget(vbox_general, general_tab) self.create_logs_widget(vbox_logs, logs_tab) + self.update_json() + self.setCentralWidget(tabs) return None @@ -75,29 +83,22 @@ def create_request_widget(self, vbox, requests_tab) -> None: self.table_widget_requests.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open", "Remove"]) vbox.addWidget(self.table_widget_requests) - self.load_requests() - self.update_json() - requests_tab.setLayout(vbox) self.table_widget_requests.show() + self.load_requests() + return None def create_batch_widget(self, vbox, batches_tab) -> None: vbox.addWidget(QLabel("Batches Information")) - directory = "state/batches" - file_names = load_json_batches(directory) - # --- Creating table --- # - self.table_widget = QTableWidget(len(file_names), 6) - self.table_widget.setColumnWidth(0, 400) - self.table_widget.setHorizontalHeaderLabels(["Name", "Allow Redirects", "Sync Last Byte", "Send Timeout", "Set Current Batch", "Open Batch"]) - vbox.addWidget(self.table_widget) - - # --- Clearing content before creating new --- # - self.table_widget.clearContents() - self.table_widget.setRowCount(0) + self.table_widget_batches = QTableWidget() + self.table_widget_batches.setColumnCount(6) + self.table_widget_batches.setColumnWidth(0, 400) + self.table_widget_batches.setHorizontalHeaderLabels(["Name", "Allow Redirects", "Sync Last Byte", "Send Timeout", "Set Current Batch", "Open Batch"]) + vbox.addWidget(self.table_widget_batches) # --- Add new batch --- # add_batch_field = QLineEdit() @@ -115,12 +116,7 @@ def create_batch_widget(self, vbox, batches_tab) -> None: quit_button.clicked.connect(QApplication.quit) vbox.addWidget(quit_button) - # --- Load in all batches --- # - current_batch = self.data_requests["current_batch"] - self.load_batches(file_names, directory, current_batch) - - # --- JSON Parsing Timer --- # - self.update_json() + self.load_batches() batches_tab.setLayout(vbox) @@ -129,6 +125,7 @@ def create_batch_widget(self, vbox, batches_tab) -> None: def update_json(self): self.save_data() self.load_requests() + self.load_batches() print("python1") @@ -174,7 +171,9 @@ def create_requests_button_widget(self, request, row) -> None: def load_requests(self): self.load_json_requests() + rows_to_delete = [] + for row in range(self.table_widget_requests.rowCount()): request_id = self.table_widget_requests.item(row, 0).text() if request_id not in self.data_requests["requests"]: @@ -210,11 +209,20 @@ def load_requests(self): self.create_requests_button_widget(request_id, row) - def load_batches(self, file_names, directory, current_batch) -> callable([]): + def load_batches(self) -> callable([]): + self.directory = "state/batches" + self.file_names = load_json_batches(self.directory) + self.batch_buttons.clear() + current_batch = self.data_requests["current_batch"] + + # remove existing rows + for row in reversed(range(self.table_widget_batches.rowCount())): + self.table_widget_batches.removeRow(row) + def load_table(): - for idx, name in enumerate(file_names): + for idx, name in enumerate(self.file_names): # --- Create command-buttons --- # current_button = QPushButton("Set Current", self) window_button = QPushButton("Open", self) @@ -225,27 +233,25 @@ def load_table(): self.batch_buttons.append((current_button, window_button)) # --- Insert row number {forloopnumber} --- # - row = self.table_widget.rowCount() - self.table_widget.insertRow(row) - self.table_widget.setItem(row, 0, QTableWidgetItem(str(name))) - self.table_widget.setCellWidget(row, 4, current_button) - self.table_widget.setCellWidget(row, 5, window_button) + row = self.table_widget_batches.rowCount() + self.table_widget_batches.insertRow(row) + self.table_widget_batches.setItem(row, 0, QTableWidgetItem(str(name))) + self.table_widget_batches.setCellWidget(row, 4, current_button) + self.table_widget_batches.setCellWidget(row, 5, window_button) self.check_current_batch(name, row, current_button, window_button, current_batch) - data = self.get_json_data(directory, name) + data = self.get_json_data(name) for col, col_name in enumerate(["Allow Redirects", "Sync Last Byte", "Send Timeout"]): value = data.get(col_name.lower().replace(" ", "_")) - self.table_widget.setItem(row, col + 1, QTableWidgetItem(str(value))) + self.table_widget_batches.setItem(row, col + 1, QTableWidgetItem(str(value))) if name == current_batch: - item = self.table_widget.item(row, col + 1) + item = self.table_widget_batches.item(row, col + 1) if item is not None: item.setBackground(Qt.gray) - self.remove_empty_rows() - load_table() return load_table @@ -256,7 +262,6 @@ def load_logs(self) -> None: self.table_widget.insertRow(row) self.table_widget.setItem(row, 0, QTableWidgetItem(str(command))) - self.remove_empty_rows() return None def add_request_to_batch(self, request_id) -> None: @@ -264,16 +269,16 @@ def add_request_to_batch(self, request_id) -> None: return None - def get_json_data(self, directory, name) -> dict: - with open(os.path.join(directory, name + ".json"), "r") as file: + def get_json_data(self, name) -> dict: + with open(os.path.join(self.directory, name + ".json"), "r") as file: data = json.load(file) return data def check_current_batch(self, name, row, button1, button2, current_batch) -> None: if name == current_batch: - for col in range(self.table_widget.columnCount()): - item = self.table_widget.item(row, col) + for col in range(self.table_widget_batches.columnCount()): + item = self.table_widget_batches.item(row, col) if item is not None: item.setBackground(Qt.gray) button1.setEnabled(False) @@ -287,19 +292,6 @@ def check_current_batch(self, name, row, button1, button2, current_batch) -> Non return None - def remove_empty_rows(self) -> None: - for row in range(self.table_widget.rowCount() - 1, -1, -1): - empty = True - for col in range(self.table_widget.columnCount()): - item = self.table_widget.item(row, col) - if item is not None and not item.text().strip() == "": - empty = False - break - if empty: - self.table_widget.removeRow(row) - - return None - def load_json_requests(self): with open('state/state.json', 'r') as f: self.data_requests = json.load(f) @@ -309,17 +301,6 @@ def save_data(self) -> None: return None - def reload_json(self) -> None: - if self.isActiveWindow(): - self.save_data() - self.update_json_timer.stop() - self.hide() - self.general_window = MainGUI(self.racer, self.state, self.command_processor) - self.general_window.show() - self.deleteLater() - - return None - def set_current_batch(self, batch_name) -> None: self.racer.set_curr_batch_by_name(self.racer, batch_name) self.current_batch = batch_name @@ -394,10 +375,6 @@ def init_ui(self) -> None: vbox.insertWidget(0, self.table_widget) - self.update_json_timer = QTimer() - self.update_json_timer.timeout.connect(lambda: self.reload_json()) - self.update_json_timer.start(10000) - return None def create_requests_widget(self, vbox): @@ -488,17 +465,6 @@ def remove_request(self, request_id) -> None: return None - def reload_json(self) -> None: - if self.isActiveWindow(): - self.save_data() - self.update_json_timer.stop() - self.hide() - self.general_window = BatchWindow(self.batch_name, self.racer, self.state, self.command_processor) - self.general_window.show() - self.deleteLater() - - return None - class RequestWindow(QMainWindow): def __init__(self, request_id, racer, state, command_processor): @@ -534,10 +500,6 @@ def init_ui(self): vbox.insertWidget(0, self.table_widget) - self.update_json_timer = QTimer() - self.update_json_timer.timeout.connect(self.reload_json) - self.update_json_timer.start(10000) - def load_request(self) -> None: requests_data = self.load_json("state/state.json")["requests"] request_data = requests_data.get(str(self.request_id)) @@ -614,14 +576,3 @@ def save_data(self) -> None: self.racer.comm_general_save(True) return None - - def reload_json(self) -> None: - if self.isActiveWindow(): - self.save_data() - self.update_json_timer.stop() - self.hide() - self.general_window = RequestWindow(self.request_id, self.racer, self.state, self.command_processor) - self.general_window.show() - self.deleteLater() - - return None From fdaa18ad7b3a9f51a2e8223f23bda4e066782ad9 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Tue, 11 Apr 2023 15:32:37 +0200 Subject: [PATCH 18/48] Update code --- CompuRacer_Core/src/compu_racer_core.py | 35 +++++++++++++++--------- CompuRacer_Core/src/gui.py | 36 ++++++++++++++++--------- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index 15c87b0..ee1390a 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -873,7 +873,7 @@ def comm_requests_comp(self, request_id_1, request_id_2, print_matches=False): self.colorprint_comp_results(self, comp) @staticmethod # do not add requests to this list in any other way - def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_confirmation=False): + def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_confirmation=True): with self.requests_list_lock: if not self.state['requests']: self.print_formatted(f"There is no request to delete: The total request list is empty!", @@ -895,16 +895,19 @@ def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_ self.print_formatted(f"Removal of all requests cancelled.", utils.QType.INFORMATION) return elif request_id_last is not None: - # remove a range of requests - for i, request_id in enumerate(copy.deepcopy(list(self.state['requests'].keys()))): - if request_id_first <= request_id <= request_id_last: - if self.rem_request(self, request_id, False) == -1: - failed_requests.append(request_id) - else: - success_requests.append(request_id) - else: - self.print_formatted(f"Removal of range of requests cancelled.", utils.QType.INFORMATION) - return + if not ask_confirmation or self.command_processor.accept_yes_no( + f"Are you sure you want to remove requests with id between and including {request_id_first} and {request_id_last}?", + utils.QType.WARNING): + # remove a range of requests + for i, request_id in enumerate(copy.deepcopy(list(self.state['requests'].keys()))): + if request_id_first <= request_id <= request_id_last: + if self.rem_request(self, request_id, False) == -1: + failed_requests.append(request_id) + else: + success_requests.append(request_id) + else: + self.print_formatted(f"Removal of range of requests cancelled.", utils.QType.INFORMATION) + return else: # remove one request if self.rem_request(self, request_id_first, True) == -1: @@ -1056,7 +1059,7 @@ def add_request(self, a_request, used_from_interface=False, print_information=Tr self.rem_batch_by_name(self, self.immediate_batch_name, True) if self.immediate_batch_name not in self.state['batches']: # create new immediate batch - return self.comm_batches_create_new_st(self, self.immediate_batch_name, False, + return self.comm_batches_create_new(self, self.immediate_batch_name, False, not used_from_interface, allow_redirects, sync_last_byte, send_timeout) immediate_batch = self.state['batches'][self.immediate_batch_name] @@ -1103,7 +1106,7 @@ def request_used_in(self, request_id): return used_in @staticmethod # do not add requests to this list in any other way - def rem_request(self, request_id, ask_confirmation=False): + def rem_request(self, request_id, ask_confirmation=True): with self.requests_list_lock: if request_id not in self.state['requests']: self.print_formatted(f"Cannot remove request:\n\t" @@ -1122,6 +1125,12 @@ def rem_request(self, request_id, ask_confirmation=False): f"{used_in}. It must be removed individually.", utils.QType.ERROR) return -1 + # remove request from the batches + if ask_confirmation: + if not self.command_processor.accept_yes_no(f"The request with id '{request_id}' is used by batches: " + f"{used_in}, continue?\n\tIt will be removed from these batches and their results are cleared!!", + utils.QType.WARNING): + return -1 for batch_name in used_in: self.state['batches'][batch_name].remove(request_id) ask_confirmation = False diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 0d3a9f9..0b29612 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -15,7 +15,6 @@ def load_json_batches(directory) -> List[Any]: data = json.load(file) if "name" in data: file_names.append(data["name"]) - return file_names @@ -68,8 +67,6 @@ def init_ui(self) -> None: self.create_batch_widget(vbox_general, general_tab) self.create_logs_widget(vbox_logs, logs_tab) - self.update_json() - self.setCentralWidget(tabs) return None @@ -80,6 +77,9 @@ def create_request_widget(self, vbox, requests_tab) -> None: # --- Creating Table --- # self.table_widget_requests = QTableWidget() self.table_widget_requests.setColumnCount(8) + self.table_widget_requests.setColumnWidth(0, 20) + self.table_widget_requests.setColumnWidth(1, 500) + self.table_widget_requests.setColumnWidth(3, 200) self.table_widget_requests.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open", "Remove"]) vbox.addWidget(self.table_widget_requests) @@ -122,16 +122,12 @@ def create_batch_widget(self, vbox, batches_tab) -> None: return None - def update_json(self): + def update_json(self) -> None: self.save_data() self.load_requests() self.load_batches() - print("python1") - - self.update_json_timer = QTimer() - self.update_json_timer.timeout.connect(lambda: self.update_json()) - self.update_json_timer.start(5000) + return None def create_logs_widget(self, vbox, logs_tab) -> None: vbox.addWidget(QLabel("Logs")) @@ -169,7 +165,7 @@ def create_requests_button_widget(self, request, row) -> None: return None - def load_requests(self): + def load_requests(self) -> None: self.load_json_requests() rows_to_delete = [] @@ -209,6 +205,8 @@ def load_requests(self): self.create_requests_button_widget(request_id, row) + return None + def load_batches(self) -> callable([]): self.directory = "state/batches" self.file_names = load_json_batches(self.directory) @@ -267,6 +265,8 @@ def load_logs(self) -> None: def add_request_to_batch(self, request_id) -> None: self.racer.comm_curr_add(self.racer, request_id) + self.update_json() + return None def get_json_data(self, name) -> dict: @@ -292,10 +292,12 @@ def check_current_batch(self, name, row, button1, button2, current_batch) -> Non return None - def load_json_requests(self): + def load_json_requests(self) -> None: with open('state/state.json', 'r') as f: self.data_requests = json.load(f) + return None + def save_data(self) -> None: self.racer.comm_general_save() @@ -305,11 +307,15 @@ def set_current_batch(self, batch_name) -> None: self.racer.set_curr_batch_by_name(self.racer, batch_name) self.current_batch = batch_name + self.update_json() + return None def remove_request(self, request_id) -> None: self.racer.comm_requests_remove(self.racer, request_id, None, False) + self.update_json() + return None def new_batch_window(self, batch_name) -> None: @@ -334,6 +340,8 @@ def create_new_batch(self, batch_name) -> None: batch_name = batch_name.text() self.racer.comm_batches_create_new(self.racer, batch_name) + self.update_json() + return None @@ -377,7 +385,7 @@ def init_ui(self) -> None: return None - def create_requests_widget(self, vbox): + def create_requests_widget(self, vbox) -> None: self.table_widget = QTableWidget() vbox.addWidget(QLabel("")) self.table_widget.setColumnCount(5) @@ -385,7 +393,9 @@ def create_requests_widget(self, vbox): self.add_request_table() - def load_json(self, filepath): + return None + + def load_json(self, filepath) -> List[Any]: with open(filepath, 'r') as file: data = json.load(file) From aaa98c43e3897cfeabcfd6c09a98cc167d4e2eee Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 12 Apr 2023 11:11:31 +0200 Subject: [PATCH 19/48] Update feedback --- CompuRacer_Core/src/compu_racer_core.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index ee1390a..c1a4463 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -910,7 +910,7 @@ def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_ return else: # remove one request - if self.rem_request(self, request_id_first, True) == -1: + if self.rem_request(self, request_id_first, False) == -1: failed_requests.append(request_id_first) else: success_requests.append(request_id_first) @@ -1134,6 +1134,13 @@ def rem_request(self, request_id, ask_confirmation=True): for batch_name in used_in: self.state['batches'][batch_name].remove(request_id) ask_confirmation = False + if not ask_confirmation or self.command_processor.accept_yes_no( + f"Are you sure you want to remove the request with id '{request_id}'?", + utils.QType.WARNING): + self.__change_state('requests', sub_search=request_id, do_delete=True) + self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) + else: + self.print_formatted(f"Removal of request cancelled.", utils.QType.INFORMATION) self.__change_state('requests', sub_search=request_id, do_delete=True) self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) @@ -1906,9 +1913,23 @@ def comm_curr_remove(self, request_id=None, wait_time=None): self.print_formatted(f"Cannot remove a request from current batch: The current batch is empty!", utils.QType.ERROR) return -1 + if self.cli_check: + if request_id is None: + # remove all items from the batch + question = "Are you sure you want to remove all requests from the current batch?" + elif wait_time is None: + # remove all items with a certain ID from the batch + question = f"Are you sure you want to remove all requests with id '{request_id}' from the current batch?" + else: + # remove a specific item with a certain ID and wait_time from the batch + question = f"Are you sure you want to remove the request with id '{request_id}' and wait_time '{wait_time}' from the current batch?" + if self.command_processor.accept_yes_no(question, utils.QType.WARNING): + num_removed = curr_batch.remove(request_id, wait_time) + self.print_formatted(f"All matching requests are removed from the current batch.\nNumber: {num_removed}", + utils.QType.INFORMATION) num_removed = curr_batch.remove(request_id, wait_time) self.print_formatted(f"All matching requests are removed from the current batch.\nNumber: {num_removed}", - utils.QType.INFORMATION) + utils.QType.INFORMATION) # ------------------------------------------------------------------------------------------------- # # ------------------------------------- Main helper functions ------------------------------------- # From abe6a5c02621760f721ee3db0fb39f436f24e54f Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 12 Apr 2023 11:30:31 +0200 Subject: [PATCH 20/48] Remove request changed --- CompuRacer_Core/src/compu_racer_core.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index c1a4463..ade5591 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -910,7 +910,7 @@ def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_ return else: # remove one request - if self.rem_request(self, request_id_first, False) == -1: + if self.rem_request(self, request_id_first, True) == -1: failed_requests.append(request_id_first) else: success_requests.append(request_id_first) @@ -1120,28 +1120,14 @@ def rem_request(self, request_id, ask_confirmation=True): f"The request with id '{request_id}' is (also) used by the immediate batch!", utils.QType.ERROR) return -1 - if not ask_confirmation: + if self.cli_check: self.print_formatted(f"The request with id '{request_id}' is used by batches: " f"{used_in}. It must be removed individually.", utils.QType.ERROR) return -1 - # remove request from the batches - if ask_confirmation: - if not self.command_processor.accept_yes_no(f"The request with id '{request_id}' is used by batches: " - f"{used_in}, continue?\n\tIt will be removed from these batches and their results are cleared!!", - utils.QType.WARNING): - return -1 for batch_name in used_in: self.state['batches'][batch_name].remove(request_id) ask_confirmation = False - if not ask_confirmation or self.command_processor.accept_yes_no( - f"Are you sure you want to remove the request with id '{request_id}'?", - utils.QType.WARNING): - self.__change_state('requests', sub_search=request_id, do_delete=True) - self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) - else: - self.print_formatted(f"Removal of request cancelled.", utils.QType.INFORMATION) - self.__change_state('requests', sub_search=request_id, do_delete=True) self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) From 77c323a1561ff8afe1cc573c172c3d27359492ee Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Mon, 17 Apr 2023 10:14:44 +0200 Subject: [PATCH 21/48] Deleted timer (timer does not exist) --- CompuRacer_Core/src/gui.py | 1 - 1 file changed, 1 deletion(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 0b29612..ed09dcf 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -320,7 +320,6 @@ def remove_request(self, request_id) -> None: def new_batch_window(self, batch_name) -> None: self.save_data() - self.update_json_timer.stop() self.batch_window = BatchWindow(batch_name, self.racer, self.state, self.command_processor) self.batch_window.show() self.hide() From 76de20d8d49df52bdbe158a823fe3ebd7be25858 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Mon, 17 Apr 2023 12:58:27 +0200 Subject: [PATCH 22/48] Work in progress --- CompuRacer_Core/src/gui.py | 96 +++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 21 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index ed09dcf..78d701a 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -378,28 +378,60 @@ def init_ui(self) -> None: self.add_button_widget(vbox) self.setCentralWidget(tabs) - self.create_requests_widget(vbox) + self.add_request_table(vbox) + self.add_propperty_widget(vbox) vbox.insertWidget(0, self.table_widget) return None - def create_requests_widget(self, vbox) -> None: - self.table_widget = QTableWidget() - vbox.addWidget(QLabel("")) - self.table_widget.setColumnCount(5) - self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Host", "Remove"]) - - self.add_request_table() - - return None - def load_json(self, filepath) -> List[Any]: with open(filepath, 'r') as file: data = json.load(file) return data + def update_json(self) -> None: + self.save_data() + self.load_requests() + + return None + + def add_propperty_widget(self, vbox) -> None: + allow_redirects = self.load_json("state/batches/" + self.batch_name + ".json")["allow_redirects"] + sync_last_byte = self.load_json("state/batches/" + self.batch_name + ".json")["sync_last_byte"] + send_tiemout = self.load_json("state/batches/" + self.batch_name + ".json")["send_timeout"] + + change_allow_redirects_field = QLineEdit() + change_allow_redirects_button = QPushButton("Change Allow_Redirects", self) + change_allow_redirects_button.clicked.connect(lambda _, input_field=change_allow_redirects_field: self.change_allow_redirects(input_field)) + + change_sync_last_byte_field = QLineEdit() + change_sync_last_byte_button = QPushButton("Change Sync_Last_Byte", self) + change_sync_last_byte_button.clicked.connect(lambda _, input_field=change_sync_last_byte_field: self.change_sync_last_byte(input_field)) + + change_send_timeout_field = QLineEdit() + change_send_timeout_button = QPushButton("Change Send_Timeout", self) + change_send_timeout_button.clicked.connect(lambda _, input_field=change_send_timeout_field: self.change_send_timeout(input_field)) + + hbox = QHBoxLayout() + hbox.addWidget(change_allow_redirects_field) + hbox.addWidget(change_allow_redirects_button) + + hbox.addWidget(change_sync_last_byte_field) + hbox.addWidget(change_sync_last_byte_button) + + hbox.addWidget(change_send_timeout_field) + hbox.addWidget(change_send_timeout_button) + + vbox.addLayout(hbox) + + return None + + def add_propperties(self, vbox) -> None: + + return None + def add_button_widget(self, vbox) -> None: send_batch_button = QPushButton("Send Batch") go_back_button = QPushButton("Go Back") @@ -415,21 +447,44 @@ def add_button_widget(self, vbox) -> None: return None - def add_request_table(self) -> None: - items = self.load_json("state/batches/" + self.batch_name + ".json")["items"] - requests = self.load_json("state/state.json")["requests"] - - self.table_widget = QTableWidget(len(items), 5, self) + def add_request_table(self, vbox) -> None: + self.table_widget = QTableWidget() + self.table_widget.setColumnCount(5) self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host", "Remove"]) self.table_widget.setColumnWidth(0, 50) self.table_widget.setColumnWidth(1, 50) - self.table_widget.setColumnWidth(2, 300) + self.table_widget.setColumnWidth(2, 600) self.table_widget.setColumnWidth(3, 100) self.table_widget.setColumnWidth(4, 100) + vbox.addWidget(self.table_widget) + + self.load_requests() + + return None + + def change_allow_redirects(self, value): + value.text() + + return None + + def change_sync_last_byte(self, value): + value.text() + + return None + + def change_send_timeout(self, value): + value.text() + + return None + + def load_requests(self) -> None: + items = self.load_json("state/batches/" + self.batch_name + ".json")["items"] + requests = self.load_json("state/state.json")["requests"] remove_button = QPushButton("Remove", self) - self.table_widget.verticalHeader().hide() + # set the number of rows in the table widget + self.table_widget.setRowCount(len(items)) for i, item in enumerate(items): request_id = item["key"][0] @@ -446,9 +501,6 @@ def add_request_table(self) -> None: self.table_widget.setCellWidget(i, 4, remove_button) remove_button.clicked.connect(lambda _, request_id=str(request_id): self.remove_request(request_id)) - self.racer.print_formatted("Dit is een test voor request : " + request_id) - - return None def send_batch(self) -> None: self.save_data() @@ -472,6 +524,8 @@ def save_data(self) -> None: def remove_request(self, request_id) -> None: self.racer.comm_curr_remove(self.racer, request_id) + self.update_json() + return None From 512fddaff3794ec75b78194d65ef668dc8c6d9af Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 20 Apr 2023 12:52:51 +0200 Subject: [PATCH 23/48] Fixed change propperties of batch --- CompuRacer_Core/src/gui.py | 94 ++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 24 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 78d701a..9aac01f 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -348,6 +348,7 @@ class BatchWindow(QMainWindow): def __init__(self, batch_name, racer, state, command_processor) -> None: super().__init__() + self.table_widget_propperty = None self.showFullScreen() self.setWindowTitle("Batch: " + batch_name) @@ -376,13 +377,17 @@ def init_ui(self) -> None: vbox.addStretch() + self.add_batch_propperty_widget(vbox) + self.add_button_widget(vbox) self.setCentralWidget(tabs) self.add_request_table(vbox) - self.add_propperty_widget(vbox) vbox.insertWidget(0, self.table_widget) + # Add batch_tab to tabs widget + tabs.addTab(batch_tab, "Batch") + return None def load_json(self, filepath) -> List[Any]: @@ -394,31 +399,34 @@ def load_json(self, filepath) -> List[Any]: def update_json(self) -> None: self.save_data() self.load_requests() + self.load_propperties() return None - def add_propperty_widget(self, vbox) -> None: - allow_redirects = self.load_json("state/batches/" + self.batch_name + ".json")["allow_redirects"] - sync_last_byte = self.load_json("state/batches/" + self.batch_name + ".json")["sync_last_byte"] - send_tiemout = self.load_json("state/batches/" + self.batch_name + ".json")["send_timeout"] + def add_batch_propperty_widget(self, vbox) -> None: + self.table_widget_propperty = QTableWidget() + self.table_widget_propperty.setColumnCount(3) + self.table_widget_propperty.setHorizontalHeaderLabels(["Allow Redirects", "Sync Last Byte", "Send Timeout"]) + vbox.addWidget(self.table_widget_propperty) - change_allow_redirects_field = QLineEdit() - change_allow_redirects_button = QPushButton("Change Allow_Redirects", self) - change_allow_redirects_button.clicked.connect(lambda _, input_field=change_allow_redirects_field: self.change_allow_redirects(input_field)) + self.add_propperty_widget(vbox) + self.load_propperties() - change_sync_last_byte_field = QLineEdit() - change_sync_last_byte_button = QPushButton("Change Sync_Last_Byte", self) - change_sync_last_byte_button.clicked.connect(lambda _, input_field=change_sync_last_byte_field: self.change_sync_last_byte(input_field)) + return None + + def add_propperty_widget(self, vbox) -> None: + change_allow_redirects_button = QPushButton("Change Allow Redirects", self) + change_allow_redirects_button.clicked.connect(lambda _: self.change_allow_redirects()) + + change_sync_last_byte_button = QPushButton("Change Sync Last Byte", self) + change_sync_last_byte_button.clicked.connect(lambda _: self.change_sync_last_byte()) change_send_timeout_field = QLineEdit() - change_send_timeout_button = QPushButton("Change Send_Timeout", self) + change_send_timeout_button = QPushButton("Change Send Timeout", self) change_send_timeout_button.clicked.connect(lambda _, input_field=change_send_timeout_field: self.change_send_timeout(input_field)) hbox = QHBoxLayout() - hbox.addWidget(change_allow_redirects_field) hbox.addWidget(change_allow_redirects_button) - - hbox.addWidget(change_sync_last_byte_field) hbox.addWidget(change_sync_last_byte_button) hbox.addWidget(change_send_timeout_field) @@ -428,7 +436,21 @@ def add_propperty_widget(self, vbox) -> None: return None - def add_propperties(self, vbox) -> None: + def load_propperties(self) -> None: + properties = self.load_json("state/batches/" + self.batch_name + ".json") + allow_redirects = properties["allow_redirects"] + sync_last_byte = properties["sync_last_byte"] + send_timeout = properties["send_timeout"] + + print(allow_redirects) + print(sync_last_byte) + print(send_timeout) + + self.table_widget_propperty.setRowCount(1) + + self.table_widget_propperty.setItem(0, 0, QTableWidgetItem("test")) + self.table_widget_propperty.setItem(0, 1, QTableWidgetItem(str(sync_last_byte))) + self.table_widget_propperty.setItem(0, 2, QTableWidgetItem(str(send_timeout))) return None @@ -449,8 +471,8 @@ def add_button_widget(self, vbox) -> None: def add_request_table(self, vbox) -> None: self.table_widget = QTableWidget() - self.table_widget.setColumnCount(5) - self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host", "Remove"]) + self.table_widget.setColumnCount(8) + self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host", "Delay Time", "Num Parallel", "Num Sequential", "Remove"]) self.table_widget.setColumnWidth(0, 50) self.table_widget.setColumnWidth(1, 50) self.table_widget.setColumnWidth(2, 600) @@ -463,18 +485,35 @@ def add_request_table(self, vbox) -> None: return None - def change_allow_redirects(self, value): - value.text() + def change_allow_redirects(self) -> None: + allow_redirects = self.load_json("state/batches/" + self.batch_name + ".json")["allow_redirects"] + + if allow_redirects is True: + self.racer.comm_curr_change_redirects(self.racer, False) + else: + self.racer.comm_curr_change_redirects(self.racer, True) + + self.update_json() return None - def change_sync_last_byte(self, value): - value.text() + def change_sync_last_byte(self): + sync_last_byte = self.load_json("state/batches/" + self.batch_name + ".json")["sync_last_byte"] + + if sync_last_byte is True: + self.racer.comm_curr_change_sync(self.racer, False) + else: + self.racer.comm_curr_change_sync(self.racer, True) + + self.update_json() return None def change_send_timeout(self, value): - value.text() + send_timeout = int(value.text()) + + self.racer.comm_curr_change_timeout(self.racer, send_timeout) + self.update_json() return None @@ -488,6 +527,10 @@ def load_requests(self) -> None: for i, item in enumerate(items): request_id = item["key"][0] + delay_time = item["key"][1] + num_parallel = item["value"][0] + num_sequential = item["value"][1] + request = requests[request_id] method = request["method"] @@ -498,7 +541,10 @@ def load_requests(self) -> None: self.table_widget.setItem(i, 1, QTableWidgetItem(method)) self.table_widget.setItem(i, 2, QTableWidgetItem(url)) self.table_widget.setItem(i, 3, QTableWidgetItem(host)) - self.table_widget.setCellWidget(i, 4, remove_button) + self.table_widget.setItem(i, 4, QTableWidgetItem(str(delay_time))) + self.table_widget.setItem(i, 5, QTableWidgetItem(str(num_parallel))) + self.table_widget.setItem(i, 6, QTableWidgetItem(str(num_sequential))) + self.table_widget.setCellWidget(i, 7, remove_button) remove_button.clicked.connect(lambda _, request_id=str(request_id): self.remove_request(request_id)) From 24ae1b2da737c84d1d3f639c8397f56f462497da Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 20 Apr 2023 13:36:52 +0200 Subject: [PATCH 24/48] merge conflicts --- CompuRacer_Core/src/gui.py | 346 +++++++++++++++++++++++++++++-------- 1 file changed, 276 insertions(+), 70 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 13de1a2..c9e2058 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -1,13 +1,13 @@ import json import os -import sys +from typing import List, Any from PyQt5.QtCore import Qt, QTimer -from PyQt5.QtWidgets import QPushButton, QSystemTrayIcon, QMenu, QAction, QMainWindow, QVBoxLayout, QLabel, QTableWidget, QTableWidgetItem, QTabWidget, QWidget, QMessageBox, QLineEdit, QHBoxLayout, QApplication -from PyQt5.QtGui import QIcon +from PyQt5.QtWidgets import QPushButton, QMainWindow, QVBoxLayout, QLabel, QTableWidget, QTableWidgetItem, QTabWidget, QWidget, QMessageBox, QLineEdit, QHBoxLayout, QApplication, QHeaderView, QTableView +from PyQt5.QtGui import QStandardItem, QStandardItemModel -def load_json_batches_names(directory) -> [str]: +def load_json_batches(directory) -> List[Any]: file_names = [] for filename in os.listdir(directory): if filename.endswith(".json"): @@ -15,23 +15,28 @@ def load_json_batches_names(directory) -> [str]: data = json.load(file) if "name" in data: file_names.append(data["name"]) + return file_names -class RequestsGUI(QMainWindow): - def __init__(self, racer, state, cmdprocessor): +class MainGUI(QMainWindow): + def __init__(self, racer, state, command_processor) -> None: super().__init__() + self.request_window = None + self.update_json_timer = None + self.general_window = None self.batch_window = None self.current_batch = None self.data_requests = None self.table_widget = None - self.command_processor = cmdprocessor + self.command_processor = command_processor self.racer = racer self.state = state self.batch_buttons = [] + self.request_buttons = [] self.load_json_requests() @@ -51,6 +56,7 @@ def init_ui(self) -> None: vbox_general = QVBoxLayout() vbox_logs = QVBoxLayout() + # --- Create and load in GUI --- # self.create_request_widget(vbox_general, general_tab) self.create_batch_widget(vbox_general, general_tab) self.create_logs_widget(vbox_logs, logs_tab) @@ -62,15 +68,16 @@ def init_ui(self) -> None: def create_request_widget(self, vbox, requests_tab) -> None: vbox.addWidget(QLabel("Requests Information")) - self.table_widget = QTableWidget(len(self.data_requests["requests"]), 6) + # --- Creating Table --- # + self.table_widget = QTableWidget(len(self.data_requests["requests"]), 7) self.table_widget.setColumnWidth(0, 30) self.table_widget.setColumnWidth(1, 400) self.table_widget.setColumnWidth(3, 200) self.table_widget.setColumnWidth(4, 100) - self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch"]) + self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open"]) vbox.addWidget(self.table_widget) - self.load_requests(vbox) + self.load_requests() requests_tab.setLayout(vbox) @@ -80,24 +87,24 @@ def create_batch_widget(self, vbox, batches_tab) -> None: vbox.addWidget(QLabel("Batches Information")) directory = "state/batches" - file_names = load_json_batches_names(directory) + file_names = load_json_batches(directory) + # --- Creating table --- # self.table_widget = QTableWidget(len(file_names), 6) self.table_widget.setColumnWidth(0, 400) self.table_widget.setHorizontalHeaderLabels(["Name", "Allow Redirects", "Sync Last Byte", "Send Timeout", "Set Current Batch", "Open Batch"]) vbox.addWidget(self.table_widget) - # clear the table widget before loading new batches + # --- Clearing content before creating new --- # self.table_widget.clearContents() self.table_widget.setRowCount(0) - current_batch = self.data_requests["current_batch"] - # --- Add new batch --- # add_batch_field = QLineEdit() add_batch_field_button = QPushButton("Add Batch", self) add_batch_field_button.clicked.connect(lambda _, input_field=add_batch_field: self.create_new_batch(input_field)) + # --- Create add batch button and field --- # hbox = QHBoxLayout() hbox.addWidget(add_batch_field) hbox.addWidget(add_batch_field_button) @@ -108,8 +115,11 @@ def create_batch_widget(self, vbox, batches_tab) -> None: quit_button.clicked.connect(QApplication.quit) vbox.addWidget(quit_button) - self.load_batches(file_names, directory, vbox, current_batch) + # --- Load in all batches --- # + current_batch = self.data_requests["current_batch"] + self.load_batches(file_names, directory, current_batch) + # --- JSON Parsing Timer --- # self.update_json_timer = QTimer() self.update_json_timer.timeout.connect(self.reload_json) self.update_json_timer.start(5000) @@ -127,7 +137,9 @@ def create_logs_widget(self, vbox, logs_tab) -> None: self.table_widget.setHorizontalHeaderLabels(["Commands"]) vbox.addWidget(self.table_widget) - vbox.addWidget(QPushButton("Save", self, clicked=self.save_data)) + save_button = QPushButton("Save") + save_button.clicked.connect(self.save_data) + vbox.addWidget(save_button) self.load_logs() @@ -135,36 +147,44 @@ def create_logs_widget(self, vbox, logs_tab) -> None: return None - def load_requests(self, vbox) -> None: + def load_requests(self) -> None: for idx, request in enumerate(self.data_requests["requests"]): # --- Insert row number {forloopnumber} --- # row = self.table_widget.rowCount() self.table_widget.insertRow(row) - # --- Create Button --- # + # --- Create Buttons --- # add_request_button = QPushButton("Add", self) + window_button = QPushButton("Open", self) + add_request_button.clicked.connect(lambda _, request_id=str(request): self.add_request_to_batch(request_id)) + window_button.clicked.connect(lambda _, request_id=request: self.new_request_window(request_id)) + + self.request_buttons.append((add_request_button, window_button)) # --- Insert data into row --- # self.table_widget.setItem(row, 0, QTableWidgetItem(str(request))) self.table_widget.setItem(row, 1, QTableWidgetItem(str(self.data_requests["requests"][request]["url"]))) self.table_widget.setItem(row, 2, QTableWidgetItem(str(self.data_requests["requests"][request]["method"]))) self.table_widget.setItem(row, 3, QTableWidgetItem(str(self.data_requests["requests"][request]["timestamp"]))) + headers = self.data_requests["requests"][request].get("headers", {}) host = headers.get("Host", "") self.table_widget.setItem(row, 4, QTableWidgetItem(str(host))) + self.table_widget.setCellWidget(row, 5, add_request_button) + self.table_widget.setCellWidget(row, 6, window_button) self.remove_empty_rows() return None - def load_batches(self, file_names, directory, vbox, current_batch) -> callable([]): + def load_batches(self, file_names, directory, current_batch) -> callable([]): self.batch_buttons.clear() def load_table(): for idx, name in enumerate(file_names): - # --- Create commandbuttons --- # + # --- Create command-buttons --- # current_button = QPushButton("Set Current", self) window_button = QPushButton("Open", self) @@ -196,6 +216,7 @@ def load_table(): self.remove_empty_rows() load_table() + return load_table def load_logs(self) -> None: @@ -207,18 +228,20 @@ def load_logs(self) -> None: self.remove_empty_rows() return None - def add_request_to_batch(self, request_id): + def add_request_to_batch(self, request_id) -> None: self.showNotification("RequestID " + request_id + " has been added to active Batch!") + self.racer.comm_curr_add(self.state, request_id) - self.racer.comm_curr_add(self.racer, request_id) + return None - def get_json_data(self, directory, name): + @staticmethod + def get_json_data(directory, name) -> dict: with open(os.path.join(directory, name + ".json"), "r") as file: data = json.load(file) return data - def check_current_batch(self, name, row, current_button, window_button, current_batch): + def check_current_batch(self, name, row, current_button, window_button, current_batch) -> None: if name == current_batch: for col in range(self.table_widget.columnCount()): item = self.table_widget.item(row, col) @@ -233,6 +256,8 @@ def check_current_batch(self, name, row, current_button, window_button, current_ current_button.setEnabled(False) window_button.setEnabled(False) + return None + def remove_empty_rows(self) -> None: for row in range(self.table_widget.rowCount() - 1, -1, -1): empty = True @@ -249,45 +274,62 @@ def remove_empty_rows(self) -> None: def load_json_requests(self) -> None: with open('state/state.json', 'r') as f: self.data_requests = json.load(f) + return None def save_data(self) -> None: self.racer.comm_general_save(True) + return None - def reload_json(self): + def reload_json(self) -> None: if self.isActiveWindow(): self.save_data() self.update_json_timer.stop() self.hide() - self.general_window = RequestsGUI(self.racer, self.state, self.command_processor) # Create a new window + self.general_window = MainGUI(self.racer, self.state, self.command_processor) self.general_window.show() self.deleteLater() + return None + def set_current_batch(self, batch_name) -> None: - self.racer.set_curr_batch_by_name(self.racer, batch_name) + self.racer.set_curr_batch_by_name(batch_name) self.current_batch = batch_name self.showNotification("Set current batch to " + batch_name) + return None - def new_batch_window(self, batch_name): + def new_batch_window(self, batch_name) -> None: self.save_data() self.update_json_timer.stop() self.batch_window = BatchWindow(batch_name, self.racer, self.state, self.command_processor) self.batch_window.show() self.hide() - def create_new_batch(self, batch_name): - batch_name = batch_name.text() + return None + + def new_request_window(self, request_id) -> None: + self.save_data() + self.update_json_timer.stop() + self.request_window = RequestWindow(request_id, self.racer, self.state, self.command_processor) + self.request_window.show() + self.hide() - self.racer.comm_batches_create_new(self.racer, batch_name) + return None + def create_new_batch(self, batch_name) -> None: + batch_name = batch_name.text() + self.racer.gui_create_new_batch(batch_name) self.showNotification("Added New Batch " + batch_name + ". Add a request to your batch so you can open your batch") - def showNotification(self, notiText): + return None + + @staticmethod + def showNotification(notifyText) -> None: messageBox = QMessageBox() messageBox.setIcon(QMessageBox.Information) - messageBox.setText(notiText) + messageBox.setText(notifyText) messageBox.setGeometry(0, 0, 500, 50) @@ -298,79 +340,95 @@ def showNotification(self, notiText): messageBox.exec() + return None + + +def load_json(filepath) -> dict: + with open(filepath, 'r') as file: + data = json.load(file) + + return data + class BatchWindow(QMainWindow): - def __init__(self, batch_name, racer, state, command_processor): + def __init__(self, batch_name, racer, state, command_processor) -> None: super().__init__() self.showFullScreen() + self.setWindowTitle("Batch: " + batch_name) + self.update_json_timer = None self.general_window = None self.table_widget = None - self.batch_requests = [] self.racer = racer self.batch_name = batch_name self.state = state self.command_processor = command_processor - self.setWindowTitle("Batch: " + batch_name) + self.batch_requests = [] self.init_ui() - def init_ui(self): + def init_ui(self) -> None: vbox = QVBoxLayout() batch_tab = QWidget() batch_tab.setLayout(vbox) - batch_tab.layout().addWidget(self.table_widget) tabs = QTabWidget() - tabs.addTab(batch_tab, "Batch") vbox.addStretch() - vbox.addWidget(QPushButton("Send Batch", self, clicked=self.send_batch), alignment=Qt.AlignBottom) - vbox.addWidget(QPushButton("Go Back", self, clicked=self.go_back), alignment=Qt.AlignBottom) - vbox.addWidget(QPushButton("Quit", self, clicked=QApplication.quit)) - + self.add_button_widget(vbox) self.setCentralWidget(tabs) - self.create_requests_widget(vbox) + vbox.insertWidget(0, self.table_widget) self.update_json_timer = QTimer() self.update_json_timer.timeout.connect(lambda: self.reload_json()) self.update_json_timer.start(10000) - def send_batch(self): - self.save_data() - self.update_json_timer.stop() - self.racer.gui_send_batches() + return None - def create_requests_widget(self, vbox): - self.table_widget = QTableWidget() + def create_requests_widget(self, vbox) -> None: vbox.addWidget(QLabel("")) + + self.table_widget = QTableWidget() self.table_widget.setColumnCount(4) self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Host"]) - - self.add_request_table() - - def add_request_table(self) -> None: - items = self.load_json("state/batches/" + self.batch_name + ".json")["items"] - requests = self.load_json("state/state.json")["requests"] - - self.table_widget = QTableWidget(len(items), 4, self) - self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host"]) self.table_widget.setColumnWidth(0, 50) self.table_widget.setColumnWidth(1, 50) self.table_widget.setColumnWidth(2, 300) self.table_widget.setColumnWidth(3, 100) - self.table_widget.verticalHeader().hide() + self.add_request_table() + + return None + + def add_button_widget(self, vbox) -> None: + send_batch_button = QPushButton("Send Batch") + go_back_button = QPushButton("Go Back") + quit_button = QPushButton("Quit") + + send_batch_button.clicked.connect(self.send_batch) + go_back_button.clicked.connect(self.go_back) + quit_button.clicked.connect(QApplication.quit) + + vbox.addWidget(send_batch_button, alignment=Qt.AlignBottom) + vbox.addWidget(go_back_button, alignment=Qt.AlignBottom) + vbox.addWidget(quit_button, alignment=Qt.AlignBottom) + + return None + + def add_request_table(self) -> None: + items = load_json("state/batches/" + self.batch_name + ".json")["items"] + requests = load_json("state/state.json")["requests"] + # --- Load in all data --- # for i, item in enumerate(items): request_id = item["key"][0] request = requests[request_id] @@ -384,13 +442,17 @@ def add_request_table(self) -> None: self.table_widget.setItem(i, 2, QTableWidgetItem(url)) self.table_widget.setItem(i, 3, QTableWidgetItem(host)) - def load_json(self, filepath): - with open(filepath, 'r') as file: - data = json.load(file) - return data + return None + + def send_batch(self) -> None: + self.save_data() + self.update_json_timer.stop() + self.racer.gui_send_batches() + + return None def go_back(self) -> None: - self.general_window = RequestsGUI(self.racer, self.state, self.command_processor) + self.general_window = MainGUI(self.racer, self.state, self.command_processor) self.general_window.show() self.hide() @@ -398,21 +460,163 @@ def go_back(self) -> None: def save_data(self) -> None: self.racer.comm_general_save(True) + + return None + + def reload_json(self) -> None: + if self.isActiveWindow(): + self.save_data() + self.update_json_timer.stop() + self.hide() + self.general_window = BatchWindow(self.batch_name, self.racer, self.state, self.command_processor) + self.general_window.show() + self.deleteLater() + + return None + + @staticmethod + def showNotification(notifyText) -> None: + messageBox = QMessageBox() + messageBox.setIcon(QMessageBox.Information) + messageBox.setText(notifyText) + + messageBox.setGeometry(0, 0, 500, 50) + + timer = QTimer() + timer.setSingleShot(True) + timer.timeout.connect(messageBox.close) + timer.start(5000) + + messageBox.exec() + + return None + + +class RequestWindow(QMainWindow): + def __init__(self, request_id, racer, state, command_processor): + super().__init__() + + self.request_id = request_id + self.racer = racer + self.state = state + self.command_processor = command_processor + + self.general_window = None + self.update_json_timer = None + + self.table_widget = QWidget() + + self.init_ui() + + def init_ui(self): + vbox = QVBoxLayout() + + request_tab = QWidget() + request_tab.setLayout(vbox) + request_tab.layout().addWidget(self.table_widget) + + tabs = QTabWidget() + tabs.addTab(request_tab, "Request") + + vbox.addStretch() + + self.add_button_widget(vbox) + self.setCentralWidget(tabs) + self.load_request() + + vbox.insertWidget(0, self.table_widget) + + self.update_json_timer = QTimer() + self.update_json_timer.timeout.connect(self.reload_json) + self.update_json_timer.start(10000) + + def load_request(self) -> None: + requests_data = load_json("state/state.json")["requests"] + request_data = requests_data.get(str(self.request_id)) + + if not request_data: + return + + # --- Ready the data --- # + body = request_data.get("body", "") + headers = request_data.get("headers", {}) + method = request_data.get("method", "") + timestamp = request_data.get("timestamp", "") + url = request_data.get("url", "") + request_id = request_data.get("id", "") + + # --- Create model and add headers --- # + model = QStandardItemModel() + model.setHorizontalHeaderLabels(["Field", "Value"]) + + # --- Insert data into rows --- # + model.appendRow([QStandardItem("Request ID"), QStandardItem(str(request_id))]) + model.appendRow([QStandardItem("URL"), QStandardItem(url)]) + model.appendRow([QStandardItem("Method"), QStandardItem(method)]) + model.appendRow([QStandardItem("Timestamp"), QStandardItem(str(timestamp))]) + model.appendRow([QStandardItem("Body"), QStandardItem(body)]) + for key, value in headers.items(): + model.appendRow([QStandardItem(key), QStandardItem(value)]) + + table_view = QTableView() + table_view.setModel(model) + + table_view.horizontalHeader().setStretchLastSection(True) + table_view.verticalHeader().setVisible(False) + table_view.setShowGrid(True) + table_view.setEditTriggers(QTableView.NoEditTriggers) + + # Set grid color to background color + table_view.setStyleSheet( + "QTableView::item {border-bottom: 1px solid black;} QTableView {background-color: white;}") + table_view.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) + table_view.setColumnWidth(0, 300) + + self.table_widget = table_view + self.layout().addWidget(self.table_widget) + + return None + + def add_button_widget(self, vbox) -> None: + quit_button = QPushButton("Quit") + go_back_button = QPushButton("Go Back") + + quit_button.clicked.connect(QApplication.quit) + go_back_button.clicked.connect(self.go_back) + + vbox.addWidget(quit_button, alignment=Qt.AlignBottom) + vbox.addWidget(go_back_button, alignment=Qt.AlignBottom) + + return None + + def go_back(self) -> None: + self.general_window = MainGUI(self.racer, self.state, self.command_processor) + self.general_window.show() + self.deleteLater() + return None - def reload_json(self): + def save_data(self) -> None: + self.racer.comm_general_save(True) + + return None + + def reload_json(self) -> None: if self.isActiveWindow(): self.save_data() self.update_json_timer.stop() self.hide() - self.general_window = BatchWindow(self.batch_name, self.racer, self.state, self.command_processor) # Create a new window + self.general_window = RequestWindow(self.request_id, self.racer, self.state, self.command_processor) self.general_window.show() self.deleteLater() - def showNotification(self, notiText): + return None + + @staticmethod + def showNotification(notifyText) -> None: messageBox = QMessageBox() messageBox.setIcon(QMessageBox.Information) - messageBox.setText(notiText) + messageBox.setText(notifyText) messageBox.setGeometry(0, 0, 500, 50) @@ -421,4 +625,6 @@ def showNotification(self, notiText): timer.timeout.connect(messageBox.close) timer.start(5000) - messageBox.exec() \ No newline at end of file + messageBox.exec() + + return None From 075dd1c9af0e0e4cc56ab655ed9f9265373ff492 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 23 Feb 2023 14:18:21 +0100 Subject: [PATCH 25/48] Added remove request --- CompuRacer_Core/src/command_processor.py | 2 +- CompuRacer_Core/src/compu_racer_core.py | 23 +++++++++++++++ CompuRacer_Core/src/gui.py | 37 +++++++++++++++--------- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/CompuRacer_Core/src/command_processor.py b/CompuRacer_Core/src/command_processor.py index abf391b..73594d8 100644 --- a/CompuRacer_Core/src/command_processor.py +++ b/CompuRacer_Core/src/command_processor.py @@ -21,7 +21,7 @@ from PyQt5.QtCore import QThread, QObject, pyqtSignal from PyQt5.QtWidgets import QApplication -__version__ = "v1" +__version__ = "v1.1.0" class GuiThread(QThread): start_gui_signal = pyqtSignal() diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index cfe0174..5c556c6 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -1106,6 +1106,29 @@ def request_used_in(self, request_id): used_in.append(batch_name) return used_in + def gui_remove_request(self, request_id): + self.rem_request_gui(request_id, False) + + def rem_request_gui(self, request_id, ask_confirmation=False): + if request_id not in self.state['requests']: + self.print_formatted(f"Cannot remove request:\n\t" + f"The request with id '{request_id}' is not in the total request list!", + utils.QType.ERROR) + return -1 + used_in = self.request_used_in(self, request_id) + if used_in: + for batch_name in used_in: + self.state['batches'][batch_name].remove(request_id) + ask_confirmation = False + + if not ask_confirmation or self.command_processor.accept_yes_no( + f"Are you sure you want to remove the request with id '{request_id}'?", + utils.QType.WARNING): + self.__change_state('requests', sub_search=request_id, do_delete=True) + self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) + else: + self.print_formatted(f"Removal of request cancelled.", utils.QType.INFORMATION) + @staticmethod # do not add requests to this list in any other way def rem_request(self, request_id, ask_confirmation=False): with self.requests_list_lock: diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index c9e2058..202d675 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -69,12 +69,12 @@ def create_request_widget(self, vbox, requests_tab) -> None: vbox.addWidget(QLabel("Requests Information")) # --- Creating Table --- # - self.table_widget = QTableWidget(len(self.data_requests["requests"]), 7) + self.table_widget = QTableWidget(len(self.data_requests["requests"]), 8) self.table_widget.setColumnWidth(0, 30) self.table_widget.setColumnWidth(1, 400) self.table_widget.setColumnWidth(3, 200) self.table_widget.setColumnWidth(4, 100) - self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open"]) + self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open", "Remove"]) vbox.addWidget(self.table_widget) self.load_requests() @@ -147,6 +147,22 @@ def create_logs_widget(self, vbox, logs_tab) -> None: return None + def create_requests_button_widget(self, request, row) -> None: + add_request_button = QPushButton("Add", self) + window_button = QPushButton("Open", self) + remove_button = QPushButton("Remove", self) + + add_request_button.clicked.connect(lambda _, request_id=str(request): self.add_request_to_batch(request_id)) + window_button.clicked.connect(lambda _, request_id=request: self.new_request_window(request_id)) + remove_button.clicked.connect(lambda _, request_id=request: self.remove_request(request_id)) + + self.request_buttons.append((add_request_button, window_button, remove_button)) + + self.table_widget.setCellWidget(row, 5, add_request_button) + self.table_widget.setCellWidget(row, 6, window_button) + self.table_widget.setCellWidget(row, 7, remove_button) + return None + def load_requests(self) -> None: for idx, request in enumerate(self.data_requests["requests"]): # --- Insert row number {forloopnumber} --- # @@ -154,13 +170,7 @@ def load_requests(self) -> None: self.table_widget.insertRow(row) # --- Create Buttons --- # - add_request_button = QPushButton("Add", self) - window_button = QPushButton("Open", self) - - add_request_button.clicked.connect(lambda _, request_id=str(request): self.add_request_to_batch(request_id)) - window_button.clicked.connect(lambda _, request_id=request: self.new_request_window(request_id)) - - self.request_buttons.append((add_request_button, window_button)) + self.create_requests_button_widget(request, row) # --- Insert data into row --- # self.table_widget.setItem(row, 0, QTableWidgetItem(str(request))) @@ -172,9 +182,6 @@ def load_requests(self) -> None: host = headers.get("Host", "") self.table_widget.setItem(row, 4, QTableWidgetItem(str(host))) - self.table_widget.setCellWidget(row, 5, add_request_button) - self.table_widget.setCellWidget(row, 6, window_button) - self.remove_empty_rows() return None @@ -228,14 +235,16 @@ def load_logs(self) -> None: self.remove_empty_rows() return None + def remove_request(self, request_id): + self.racer.gui_remove_request(request_id) + def add_request_to_batch(self, request_id) -> None: self.showNotification("RequestID " + request_id + " has been added to active Batch!") self.racer.comm_curr_add(self.state, request_id) return None - @staticmethod - def get_json_data(directory, name) -> dict: + def get_json_data(self, directory, name) -> dict: with open(os.path.join(directory, name + ".json"), "r") as file: data = json.load(file) From 4dc27581e6b35397b306b4b1f2dc6a0bda5ece69 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Fri, 24 Feb 2023 13:52:16 +0100 Subject: [PATCH 26/48] work in progress --- CompuRacer_Core/src/compu_racer_core.py | 31 ++++--------------- CompuRacer_Core/src/gui.py | 40 ++++++++++++++----------- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index 5c556c6..e018487 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -1107,27 +1107,8 @@ def request_used_in(self, request_id): return used_in def gui_remove_request(self, request_id): - self.rem_request_gui(request_id, False) - - def rem_request_gui(self, request_id, ask_confirmation=False): - if request_id not in self.state['requests']: - self.print_formatted(f"Cannot remove request:\n\t" - f"The request with id '{request_id}' is not in the total request list!", - utils.QType.ERROR) - return -1 - used_in = self.request_used_in(self, request_id) - if used_in: - for batch_name in used_in: - self.state['batches'][batch_name].remove(request_id) - ask_confirmation = False - - if not ask_confirmation or self.command_processor.accept_yes_no( - f"Are you sure you want to remove the request with id '{request_id}'?", - utils.QType.WARNING): - self.__change_state('requests', sub_search=request_id, do_delete=True) - self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) - else: - self.print_formatted(f"Removal of request cancelled.", utils.QType.INFORMATION) + curr_batch = self.state['batches'][self.state['current_batch']] + curr_batch.remove(request_id, None) @staticmethod # do not add requests to this list in any other way def rem_request(self, request_id, ask_confirmation=False): @@ -1150,10 +1131,10 @@ def rem_request(self, request_id, ask_confirmation=False): utils.QType.ERROR) return -1 # remove request from the batches - if not self.command_processor.accept_yes_no(f"The request with id '{request_id}' is used by batches: " - f"{used_in}, continue?\n\tIt will be removed from these batches and their results are cleared!!", - utils.QType.WARNING): - return -1 + # if not self.command_processor.accept_yes_no(f"The request with id '{request_id}' is used by batches: " + # f"{used_in}, continue?\n\tIt will be removed from these batches and their results are cleared!!", + # utils.QType.WARNING): + # return -1 # remove request from the batches for batch_name in used_in: self.state['batches'][batch_name].remove(request_id) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 202d675..13a4bb8 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -150,17 +150,14 @@ def create_logs_widget(self, vbox, logs_tab) -> None: def create_requests_button_widget(self, request, row) -> None: add_request_button = QPushButton("Add", self) window_button = QPushButton("Open", self) - remove_button = QPushButton("Remove", self) add_request_button.clicked.connect(lambda _, request_id=str(request): self.add_request_to_batch(request_id)) window_button.clicked.connect(lambda _, request_id=request: self.new_request_window(request_id)) - remove_button.clicked.connect(lambda _, request_id=request: self.remove_request(request_id)) - self.request_buttons.append((add_request_button, window_button, remove_button)) + self.request_buttons.append((add_request_button, window_button)) self.table_widget.setCellWidget(row, 5, add_request_button) self.table_widget.setCellWidget(row, 6, window_button) - self.table_widget.setCellWidget(row, 7, remove_button) return None def load_requests(self) -> None: @@ -235,9 +232,6 @@ def load_logs(self) -> None: self.remove_empty_rows() return None - def remove_request(self, request_id): - self.racer.gui_remove_request(request_id) - def add_request_to_batch(self, request_id) -> None: self.showNotification("RequestID " + request_id + " has been added to active Batch!") self.racer.comm_curr_add(self.state, request_id) @@ -352,13 +346,6 @@ def showNotification(notifyText) -> None: return None -def load_json(filepath) -> dict: - with open(filepath, 'r') as file: - data = json.load(file) - - return data - - class BatchWindow(QMainWindow): def __init__(self, batch_name, racer, state, command_processor) -> None: super().__init__() @@ -407,8 +394,8 @@ def create_requests_widget(self, vbox) -> None: vbox.addWidget(QLabel("")) self.table_widget = QTableWidget() - self.table_widget.setColumnCount(4) - self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Host"]) + self.table_widget.setColumnCount(5) + self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Host", "Remove"]) self.table_widget.setColumnWidth(0, 50) self.table_widget.setColumnWidth(1, 50) self.table_widget.setColumnWidth(2, 300) @@ -418,6 +405,12 @@ def create_requests_widget(self, vbox) -> None: return None + def load_json(self, filepath): + with open(filepath, 'r') as file: + data = json.load(file) + + return data + def add_button_widget(self, vbox) -> None: send_batch_button = QPushButton("Send Batch") go_back_button = QPushButton("Go Back") @@ -434,8 +427,8 @@ def add_button_widget(self, vbox) -> None: return None def add_request_table(self) -> None: - items = load_json("state/batches/" + self.batch_name + ".json")["items"] - requests = load_json("state/state.json")["requests"] + items = self.load_json("state/batches/" + self.batch_name + ".json")["items"] + requests = self.load_json("state/state.json")["requests"] # --- Load in all data --- # for i, item in enumerate(items): @@ -451,8 +444,19 @@ def add_request_table(self) -> None: self.table_widget.setItem(i, 2, QTableWidgetItem(url)) self.table_widget.setItem(i, 3, QTableWidgetItem(host)) + remove_item = QTableWidgetItem() + remove_item.setFlags(Qt.ItemIsEnabled) + self.table_widget.setItem(i, 4, remove_item) + + remove_button = QPushButton("Remove") + remove_button.clicked.connect(lambda _, request_id=request_id: self.remove_request(request_id)) + self.table_widget.setCellWidget(i, 4, remove_button) + return None + def remove_request(self, request_id): + self.racer.gui_remove_request(request_id) + def send_batch(self) -> None: self.save_data() self.update_json_timer.stop() From 06a952ce821509d662d7ab24e99902a722f74d1e Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Tue, 28 Mar 2023 10:22:32 +0200 Subject: [PATCH 27/48] Removed Notifications --- CompuRacer_Core/src/gui.py | 54 -------------------------------------- 1 file changed, 54 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 13a4bb8..59ff5d4 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -233,7 +233,6 @@ def load_logs(self) -> None: return None def add_request_to_batch(self, request_id) -> None: - self.showNotification("RequestID " + request_id + " has been added to active Batch!") self.racer.comm_curr_add(self.state, request_id) return None @@ -299,7 +298,6 @@ def reload_json(self) -> None: def set_current_batch(self, batch_name) -> None: self.racer.set_curr_batch_by_name(batch_name) self.current_batch = batch_name - self.showNotification("Set current batch to " + batch_name) return None @@ -324,24 +322,6 @@ def new_request_window(self, request_id) -> None: def create_new_batch(self, batch_name) -> None: batch_name = batch_name.text() self.racer.gui_create_new_batch(batch_name) - self.showNotification("Added New Batch " + batch_name + ". Add a request to your batch so you can open your batch") - - return None - - @staticmethod - def showNotification(notifyText) -> None: - messageBox = QMessageBox() - messageBox.setIcon(QMessageBox.Information) - messageBox.setText(notifyText) - - messageBox.setGeometry(0, 0, 500, 50) - - timer = QTimer() - timer.setSingleShot(True) - timer.timeout.connect(messageBox.close) - timer.start(5000) - - messageBox.exec() return None @@ -487,23 +467,6 @@ def reload_json(self) -> None: return None - @staticmethod - def showNotification(notifyText) -> None: - messageBox = QMessageBox() - messageBox.setIcon(QMessageBox.Information) - messageBox.setText(notifyText) - - messageBox.setGeometry(0, 0, 500, 50) - - timer = QTimer() - timer.setSingleShot(True) - timer.timeout.connect(messageBox.close) - timer.start(5000) - - messageBox.exec() - - return None - class RequestWindow(QMainWindow): def __init__(self, request_id, racer, state, command_processor): @@ -624,20 +587,3 @@ def reload_json(self) -> None: self.deleteLater() return None - - @staticmethod - def showNotification(notifyText) -> None: - messageBox = QMessageBox() - messageBox.setIcon(QMessageBox.Information) - messageBox.setText(notifyText) - - messageBox.setGeometry(0, 0, 500, 50) - - timer = QTimer() - timer.setSingleShot(True) - timer.timeout.connect(messageBox.close) - timer.start(5000) - - messageBox.exec() - - return None From 780e196ec68ab588c8cec0af6c856c3678159b83 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:25:48 +0200 Subject: [PATCH 28/48] deleted comment --- CompuRacer_Core/src/compu_racer_core.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index e018487..e4a125e 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -1130,12 +1130,6 @@ def rem_request(self, request_id, ask_confirmation=False): f"{used_in}. It must be removed individually.", utils.QType.ERROR) return -1 - # remove request from the batches - # if not self.command_processor.accept_yes_no(f"The request with id '{request_id}' is used by batches: " - # f"{used_in}, continue?\n\tIt will be removed from these batches and their results are cleared!!", - # utils.QType.WARNING): - # return -1 - # remove request from the batches for batch_name in used_in: self.state['batches'][batch_name].remove(request_id) ask_confirmation = False From 847f6346cbd8ca680d1e31d45b6e4e763576eb5b Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:26:04 +0200 Subject: [PATCH 29/48] added new unstatic command --- CompuRacer_Core/src/compu_racer_core.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index e4a125e..d2b10d2 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -1926,6 +1926,31 @@ def comm_curr_remove(self, request_id=None, wait_time=None): else: self.print_formatted(f"Removal of current batch requests cancelled.", utils.QType.INFORMATION) + def gui_comm_curr_remove(self, request_id=None, wait_time=None): + """ + Removes requests from the current batch + :param self: reference to the CompuRacer + :param request_id: the request to remove, or if None, all requests + :param wait_time: the wait_time of the request to remove, or if None, all regardless of wait_time + :return: 0 on success and -1 on error + """ + if not self.state['current_batch']: + self.print_formatted( + f"Cannot remove a request from current batch: There is no current batch! First, select a current batch.", + utils.QType.ERROR) + return -1 + curr_batch = self.state['batches'][self.state['current_batch']] + if curr_batch.is_empty(): + self.print_formatted(f"Cannot remove a request from current batch: The current batch is empty!", + utils.QType.ERROR) + return -1 + if request_id is None: + # remove all items from the batch + question = "Are you sure you want to remove all requests from the current batch?" + self.print_formatted("Dit is een andere test voor request nummer : " + request_id) + + curr_batch.remove(request_id, wait_time) + # ------------------------------------------------------------------------------------------------- # # ------------------------------------- Main helper functions ------------------------------------- # # ------------------------------------------------------------------------------------------------- # From 72dc80e809774c40b33fda885fb3ae5e6b6114d0 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:26:27 +0200 Subject: [PATCH 30/48] fixed request widget bug --- CompuRacer_Core/src/gui.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 59ff5d4..e2bdf6f 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -370,21 +370,14 @@ def init_ui(self) -> None: return None - def create_requests_widget(self, vbox) -> None: - vbox.addWidget(QLabel("")) - + def create_requests_widget(self, vbox): self.table_widget = QTableWidget() + vbox.addWidget(QLabel("")) self.table_widget.setColumnCount(5) self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Host", "Remove"]) - self.table_widget.setColumnWidth(0, 50) - self.table_widget.setColumnWidth(1, 50) - self.table_widget.setColumnWidth(2, 300) - self.table_widget.setColumnWidth(3, 100) self.add_request_table() - return None - def load_json(self, filepath): with open(filepath, 'r') as file: data = json.load(file) From 73b6af65f776812dd67745d8d0e2a5c0747a28c4 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:26:52 +0200 Subject: [PATCH 31/48] Added abiity to remove requests --- CompuRacer_Core/src/gui.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index e2bdf6f..8fbd548 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -150,14 +150,18 @@ def create_logs_widget(self, vbox, logs_tab) -> None: def create_requests_button_widget(self, request, row) -> None: add_request_button = QPushButton("Add", self) window_button = QPushButton("Open", self) + remove_button = QPushButton("Remove", self) add_request_button.clicked.connect(lambda _, request_id=str(request): self.add_request_to_batch(request_id)) window_button.clicked.connect(lambda _, request_id=request: self.new_request_window(request_id)) + remove_button.clicked.connect(lambda _, request_id=str(request): self.remove_request(request_id)) - self.request_buttons.append((add_request_button, window_button)) + self.request_buttons.append((add_request_button, window_button, remove_button)) self.table_widget.setCellWidget(row, 5, add_request_button) self.table_widget.setCellWidget(row, 6, window_button) + self.table_widget.setCellWidget(row, 7, remove_button) + return None def load_requests(self) -> None: @@ -301,6 +305,11 @@ def set_current_batch(self, batch_name) -> None: return None + def remove_request(self, request_id) -> None: + self.racer.gui_comm_curr_remove(request_id) + + return None + def new_batch_window(self, batch_name) -> None: self.save_data() self.update_json_timer.stop() From 5b81d7b9a5e7f7979e1048cce0356b512418fb8b Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:27:31 +0200 Subject: [PATCH 32/48] Changed ability to remove requests --- CompuRacer_Core/src/gui.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 8fbd548..2a7b1ee 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -412,7 +412,18 @@ def add_request_table(self) -> None: items = self.load_json("state/batches/" + self.batch_name + ".json")["items"] requests = self.load_json("state/state.json")["requests"] - # --- Load in all data --- # + self.table_widget = QTableWidget(len(items), 5, self) + self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host", "Remove"]) + self.table_widget.setColumnWidth(0, 50) + self.table_widget.setColumnWidth(1, 50) + self.table_widget.setColumnWidth(2, 300) + self.table_widget.setColumnWidth(3, 100) + self.table_widget.setColumnWidth(4, 100) + + remove_button = QPushButton("Remove", self) + + self.table_widget.verticalHeader().hide() + for i, item in enumerate(items): request_id = item["key"][0] request = requests[request_id] @@ -458,6 +469,11 @@ def save_data(self) -> None: return None + def remove_request(self, request_id) -> None: + self.racer.gui_comm_curr_remove(request_id) + + return None + def reload_json(self) -> None: if self.isActiveWindow(): self.save_data() From 23e3711b304f51fc31db1f4ac82b9991241aadb7 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:27:41 +0200 Subject: [PATCH 33/48] cleanup --- CompuRacer_Core/src/gui.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 2a7b1ee..ca5e266 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -436,19 +436,12 @@ def add_request_table(self) -> None: self.table_widget.setItem(i, 1, QTableWidgetItem(method)) self.table_widget.setItem(i, 2, QTableWidgetItem(url)) self.table_widget.setItem(i, 3, QTableWidgetItem(host)) - - remove_item = QTableWidgetItem() - remove_item.setFlags(Qt.ItemIsEnabled) - self.table_widget.setItem(i, 4, remove_item) - - remove_button = QPushButton("Remove") - remove_button.clicked.connect(lambda _, request_id=request_id: self.remove_request(request_id)) self.table_widget.setCellWidget(i, 4, remove_button) - return None + remove_button.clicked.connect(lambda _, request_id=str(request_id): self.remove_request(request_id)) + self.racer.print_formatted("Dit is een test voor request : " + request_id) - def remove_request(self, request_id): - self.racer.gui_remove_request(request_id) + return None def send_batch(self) -> None: self.save_data() From fccb6ff6a532ea8f4d98ac3c0cc2e75696d81239 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 29 Mar 2023 10:27:51 +0200 Subject: [PATCH 34/48] Bug fixes --- CompuRacer_Core/src/gui.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index ca5e266..5a086a1 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -247,20 +247,20 @@ def get_json_data(self, directory, name) -> dict: return data - def check_current_batch(self, name, row, current_button, window_button, current_batch) -> None: + def check_current_batch(self, name, row, button1, button2, current_batch) -> None: if name == current_batch: for col in range(self.table_widget.columnCount()): item = self.table_widget.item(row, col) if item is not None: item.setBackground(Qt.gray) - current_button.setEnabled(False) - window_button.setEnabled(True) + button1.setEnabled(False) + button2.setEnabled(True) else: - window_button.setEnabled(False) + button2.setEnabled(False) if name == "Imm": - current_button.setEnabled(False) - window_button.setEnabled(False) + button1.setEnabled(False) + button2.setEnabled(False) return None @@ -518,7 +518,7 @@ def init_ui(self): self.update_json_timer.start(10000) def load_request(self) -> None: - requests_data = load_json("state/state.json")["requests"] + requests_data = self.load_json("state/state.json")["requests"] request_data = requests_data.get(str(self.request_id)) if not request_data: @@ -576,6 +576,12 @@ def add_button_widget(self, vbox) -> None: return None + def load_json(self, filepath): + with open(filepath, 'r') as file: + data = json.load(file) + + return data + def go_back(self) -> None: self.general_window = MainGUI(self.racer, self.state, self.command_processor) self.general_window.show() From 0e297586f5985d64c8b2514e293aeb7c32054ac0 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 20 Apr 2023 13:37:35 +0200 Subject: [PATCH 35/48] merge conflicts --- CompuRacer_Core/src/gui.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 5a086a1..ec076ac 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -237,7 +237,7 @@ def load_logs(self) -> None: return None def add_request_to_batch(self, request_id) -> None: - self.racer.comm_curr_add(self.state, request_id) + self.racer.comm_curr_add(self.racer, request_id) return None @@ -300,13 +300,13 @@ def reload_json(self) -> None: return None def set_current_batch(self, batch_name) -> None: - self.racer.set_curr_batch_by_name(batch_name) + self.racer.set_curr_batch_by_name(self.racer, batch_name) self.current_batch = batch_name return None def remove_request(self, request_id) -> None: - self.racer.gui_comm_curr_remove(request_id) + self.racer.comm_requests_remove(self.racer, request_id, None, False) return None @@ -330,7 +330,7 @@ def new_request_window(self, request_id) -> None: def create_new_batch(self, batch_name) -> None: batch_name = batch_name.text() - self.racer.gui_create_new_batch(batch_name) + self.racer.comm_batches_create_new(self.racer, batch_name) return None @@ -446,7 +446,7 @@ def add_request_table(self) -> None: def send_batch(self) -> None: self.save_data() self.update_json_timer.stop() - self.racer.gui_send_batches() + self.racer.comm_batches_send(self.racer) return None @@ -463,7 +463,7 @@ def save_data(self) -> None: return None def remove_request(self, request_id) -> None: - self.racer.gui_comm_curr_remove(request_id) + self.racer.comm_curr_remove(self.racer, request_id) return None From 8eb7057f8c5e7b0a82917dfd7ab45c7ddf9ed649 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 5 Apr 2023 14:56:53 +0200 Subject: [PATCH 36/48] Fine tuning removing requests --- CompuRacer_Core/src/compu_racer_core.py | 26 +++++++++---------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index d2b10d2..efb374d 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -873,7 +873,7 @@ def comm_requests_comp(self, request_id_1, request_id_2, print_matches=False): self.colorprint_comp_results(self, comp) @staticmethod # do not add requests to this list in any other way - def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_confirmation=True): + def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_confirmation=False): with self.requests_list_lock: if not self.state['requests']: self.print_formatted(f"There is no request to delete: The total request list is empty!", @@ -896,15 +896,12 @@ def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_ return elif request_id_last is not None: # remove a range of requests - if not ask_confirmation or self.command_processor.accept_yes_no( - f"Are you sure you want to remove requests with id between and including {request_id_first} and {request_id_last}?", - utils.QType.WARNING): - for i, request_id in enumerate(copy.deepcopy(list(self.state['requests'].keys()))): - if request_id_first <= request_id <= request_id_last: - if self.rem_request(self, request_id, False) == -1: - failed_requests.append(request_id) - else: - success_requests.append(request_id) + for i, request_id in enumerate(copy.deepcopy(list(self.state['requests'].keys()))): + if request_id_first <= request_id <= request_id_last: + if self.rem_request(self, request_id, False) == -1: + failed_requests.append(request_id) + else: + success_requests.append(request_id) else: self.print_formatted(f"Removal of range of requests cancelled.", utils.QType.INFORMATION) return @@ -1134,13 +1131,8 @@ def rem_request(self, request_id, ask_confirmation=False): self.state['batches'][batch_name].remove(request_id) ask_confirmation = False - if not ask_confirmation or self.command_processor.accept_yes_no( - f"Are you sure you want to remove the request with id '{request_id}'?", - utils.QType.WARNING): - self.__change_state('requests', sub_search=request_id, do_delete=True) - self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) - else: - self.print_formatted(f"Removal of request cancelled.", utils.QType.INFORMATION) + self.__change_state('requests', sub_search=request_id, do_delete=True) + self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) # --------------------------------------------------------------------------------------------------- # # ------------------------------------- Batch command functions ------------------------------------- # From 4583f94998c56b18d4a114ed82a41e09a41613f3 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 6 Apr 2023 13:34:42 +0200 Subject: [PATCH 37/48] Request updating --- CompuRacer_Core/src/gui.py | 86 +++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index ec076ac..74f4222 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -30,6 +30,7 @@ def __init__(self, racer, state, command_processor) -> None: self.current_batch = None self.data_requests = None self.table_widget = None + self.table_widget_requests = None self.command_processor = command_processor self.racer = racer @@ -69,17 +70,16 @@ def create_request_widget(self, vbox, requests_tab) -> None: vbox.addWidget(QLabel("Requests Information")) # --- Creating Table --- # - self.table_widget = QTableWidget(len(self.data_requests["requests"]), 8) - self.table_widget.setColumnWidth(0, 30) - self.table_widget.setColumnWidth(1, 400) - self.table_widget.setColumnWidth(3, 200) - self.table_widget.setColumnWidth(4, 100) - self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open", "Remove"]) - vbox.addWidget(self.table_widget) + self.table_widget_requests = QTableWidget() + self.table_widget_requests.setColumnCount(8) + self.table_widget_requests.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open", "Remove"]) + vbox.addWidget(self.table_widget_requests) self.load_requests() + self.update_json() requests_tab.setLayout(vbox) + self.table_widget_requests.show() return None @@ -120,14 +120,22 @@ def create_batch_widget(self, vbox, batches_tab) -> None: self.load_batches(file_names, directory, current_batch) # --- JSON Parsing Timer --- # - self.update_json_timer = QTimer() - self.update_json_timer.timeout.connect(self.reload_json) - self.update_json_timer.start(5000) + self.update_json() batches_tab.setLayout(vbox) return None + def update_json(self): + self.save_data() + self.load_requests() + + print("python1") + + self.update_json_timer = QTimer() + self.update_json_timer.timeout.connect(lambda: self.update_json()) + self.update_json_timer.start(5000) + def create_logs_widget(self, vbox, logs_tab) -> None: vbox.addWidget(QLabel("Logs")) @@ -158,34 +166,38 @@ def create_requests_button_widget(self, request, row) -> None: self.request_buttons.append((add_request_button, window_button, remove_button)) - self.table_widget.setCellWidget(row, 5, add_request_button) - self.table_widget.setCellWidget(row, 6, window_button) - self.table_widget.setCellWidget(row, 7, remove_button) + self.table_widget_requests.setCellWidget(row, 5, add_request_button) + self.table_widget_requests.setCellWidget(row, 6, window_button) + self.table_widget_requests.setCellWidget(row, 7, remove_button) return None - def load_requests(self) -> None: - for idx, request in enumerate(self.data_requests["requests"]): - # --- Insert row number {forloopnumber} --- # - row = self.table_widget.rowCount() - self.table_widget.insertRow(row) - - # --- Create Buttons --- # - self.create_requests_button_widget(request, row) - - # --- Insert data into row --- # - self.table_widget.setItem(row, 0, QTableWidgetItem(str(request))) - self.table_widget.setItem(row, 1, QTableWidgetItem(str(self.data_requests["requests"][request]["url"]))) - self.table_widget.setItem(row, 2, QTableWidgetItem(str(self.data_requests["requests"][request]["method"]))) - self.table_widget.setItem(row, 3, QTableWidgetItem(str(self.data_requests["requests"][request]["timestamp"]))) - - headers = self.data_requests["requests"][request].get("headers", {}) - host = headers.get("Host", "") - self.table_widget.setItem(row, 4, QTableWidgetItem(str(host))) - - self.remove_empty_rows() + def load_requests(self): + self.load_json_requests() + for request_id, request_data in self.data_requests["requests"].items(): + existing_row = None + for row in range(self.table_widget_requests.rowCount()): + if self.table_widget_requests.item(row, 0).text() == request_id: + existing_row = row + break - return None + if existing_row is not None: + self.table_widget_requests.setItem(existing_row, 1, QTableWidgetItem(str(request_data["url"]))) + self.table_widget_requests.setItem(existing_row, 2, QTableWidgetItem(str(request_data["method"]))) + self.table_widget_requests.setItem(existing_row, 3, QTableWidgetItem(str(request_data["timestamp"]))) + headers = request_data.get("headers", {}) + host = headers.get("Host", "") + self.table_widget_requests.setItem(existing_row, 4, QTableWidgetItem(str(host))) + else: + row = self.table_widget_requests.rowCount() + self.table_widget_requests.insertRow(row) + self.table_widget_requests.setItem(row, 0, QTableWidgetItem(str(request_id))) + self.table_widget_requests.setItem(row, 1, QTableWidgetItem(str(request_data["url"]))) + self.table_widget_requests.setItem(row, 2, QTableWidgetItem(str(request_data["method"]))) + self.table_widget_requests.setItem(row, 3, QTableWidgetItem(str(request_data["timestamp"]))) + headers = request_data.get("headers", {}) + host = headers.get("Host", "") + self.table_widget_requests.setItem(row, 4, QTableWidgetItem(str(host))) def load_batches(self, file_names, directory, current_batch) -> callable([]): self.batch_buttons.clear() @@ -277,14 +289,12 @@ def remove_empty_rows(self) -> None: return None - def load_json_requests(self) -> None: + def load_json_requests(self): with open('state/state.json', 'r') as f: self.data_requests = json.load(f) - return None - def save_data(self) -> None: - self.racer.comm_general_save(True) + self.racer.comm_general_save() return None From df61f964238337d5c04f309cce98310698f806cd Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 6 Apr 2023 13:40:34 +0200 Subject: [PATCH 38/48] Delete row on updating requests --- CompuRacer_Core/src/gui.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 74f4222..5a025a6 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -174,6 +174,15 @@ def create_requests_button_widget(self, request, row) -> None: def load_requests(self): self.load_json_requests() + rows_to_delete = [] + for row in range(self.table_widget_requests.rowCount()): + request_id = self.table_widget_requests.item(row, 0).text() + if request_id not in self.data_requests["requests"]: + rows_to_delete.append(row) + + for row in reversed(rows_to_delete): + self.table_widget_requests.removeRow(row) + for request_id, request_data in self.data_requests["requests"].items(): existing_row = None for row in range(self.table_widget_requests.rowCount()): @@ -199,6 +208,8 @@ def load_requests(self): host = headers.get("Host", "") self.table_widget_requests.setItem(row, 4, QTableWidgetItem(str(host))) + self.create_requests_button_widget(request_id, row) + def load_batches(self, file_names, directory, current_batch) -> callable([]): self.batch_buttons.clear() From de214ee5cc48a7531e3a6837eb2a193d2b0398c2 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Fri, 7 Apr 2023 11:22:25 +0200 Subject: [PATCH 39/48] Update reloading batches --- CompuRacer_Core/src/gui.py | 133 ++++++++++++------------------------- 1 file changed, 42 insertions(+), 91 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 5a025a6..0d3a9f9 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -31,6 +31,9 @@ def __init__(self, racer, state, command_processor) -> None: self.data_requests = None self.table_widget = None self.table_widget_requests = None + self.table_widget_batches = None + self.file_names = None + self.directory = None self.command_processor = command_processor self.racer = racer @@ -47,6 +50,9 @@ def init_ui(self) -> None: self.showFullScreen() self.setWindowTitle("CompuRacer GUI") + self.directory = "state/batches" + self.file_names = load_json_batches(self.directory) + tabs = QTabWidget() general_tab = QWidget() logs_tab = QWidget() @@ -62,6 +68,8 @@ def init_ui(self) -> None: self.create_batch_widget(vbox_general, general_tab) self.create_logs_widget(vbox_logs, logs_tab) + self.update_json() + self.setCentralWidget(tabs) return None @@ -75,29 +83,22 @@ def create_request_widget(self, vbox, requests_tab) -> None: self.table_widget_requests.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open", "Remove"]) vbox.addWidget(self.table_widget_requests) - self.load_requests() - self.update_json() - requests_tab.setLayout(vbox) self.table_widget_requests.show() + self.load_requests() + return None def create_batch_widget(self, vbox, batches_tab) -> None: vbox.addWidget(QLabel("Batches Information")) - directory = "state/batches" - file_names = load_json_batches(directory) - # --- Creating table --- # - self.table_widget = QTableWidget(len(file_names), 6) - self.table_widget.setColumnWidth(0, 400) - self.table_widget.setHorizontalHeaderLabels(["Name", "Allow Redirects", "Sync Last Byte", "Send Timeout", "Set Current Batch", "Open Batch"]) - vbox.addWidget(self.table_widget) - - # --- Clearing content before creating new --- # - self.table_widget.clearContents() - self.table_widget.setRowCount(0) + self.table_widget_batches = QTableWidget() + self.table_widget_batches.setColumnCount(6) + self.table_widget_batches.setColumnWidth(0, 400) + self.table_widget_batches.setHorizontalHeaderLabels(["Name", "Allow Redirects", "Sync Last Byte", "Send Timeout", "Set Current Batch", "Open Batch"]) + vbox.addWidget(self.table_widget_batches) # --- Add new batch --- # add_batch_field = QLineEdit() @@ -115,12 +116,7 @@ def create_batch_widget(self, vbox, batches_tab) -> None: quit_button.clicked.connect(QApplication.quit) vbox.addWidget(quit_button) - # --- Load in all batches --- # - current_batch = self.data_requests["current_batch"] - self.load_batches(file_names, directory, current_batch) - - # --- JSON Parsing Timer --- # - self.update_json() + self.load_batches() batches_tab.setLayout(vbox) @@ -129,6 +125,7 @@ def create_batch_widget(self, vbox, batches_tab) -> None: def update_json(self): self.save_data() self.load_requests() + self.load_batches() print("python1") @@ -174,7 +171,9 @@ def create_requests_button_widget(self, request, row) -> None: def load_requests(self): self.load_json_requests() + rows_to_delete = [] + for row in range(self.table_widget_requests.rowCount()): request_id = self.table_widget_requests.item(row, 0).text() if request_id not in self.data_requests["requests"]: @@ -210,11 +209,20 @@ def load_requests(self): self.create_requests_button_widget(request_id, row) - def load_batches(self, file_names, directory, current_batch) -> callable([]): + def load_batches(self) -> callable([]): + self.directory = "state/batches" + self.file_names = load_json_batches(self.directory) + self.batch_buttons.clear() + current_batch = self.data_requests["current_batch"] + + # remove existing rows + for row in reversed(range(self.table_widget_batches.rowCount())): + self.table_widget_batches.removeRow(row) + def load_table(): - for idx, name in enumerate(file_names): + for idx, name in enumerate(self.file_names): # --- Create command-buttons --- # current_button = QPushButton("Set Current", self) window_button = QPushButton("Open", self) @@ -225,27 +233,25 @@ def load_table(): self.batch_buttons.append((current_button, window_button)) # --- Insert row number {forloopnumber} --- # - row = self.table_widget.rowCount() - self.table_widget.insertRow(row) - self.table_widget.setItem(row, 0, QTableWidgetItem(str(name))) - self.table_widget.setCellWidget(row, 4, current_button) - self.table_widget.setCellWidget(row, 5, window_button) + row = self.table_widget_batches.rowCount() + self.table_widget_batches.insertRow(row) + self.table_widget_batches.setItem(row, 0, QTableWidgetItem(str(name))) + self.table_widget_batches.setCellWidget(row, 4, current_button) + self.table_widget_batches.setCellWidget(row, 5, window_button) self.check_current_batch(name, row, current_button, window_button, current_batch) - data = self.get_json_data(directory, name) + data = self.get_json_data(name) for col, col_name in enumerate(["Allow Redirects", "Sync Last Byte", "Send Timeout"]): value = data.get(col_name.lower().replace(" ", "_")) - self.table_widget.setItem(row, col + 1, QTableWidgetItem(str(value))) + self.table_widget_batches.setItem(row, col + 1, QTableWidgetItem(str(value))) if name == current_batch: - item = self.table_widget.item(row, col + 1) + item = self.table_widget_batches.item(row, col + 1) if item is not None: item.setBackground(Qt.gray) - self.remove_empty_rows() - load_table() return load_table @@ -256,7 +262,6 @@ def load_logs(self) -> None: self.table_widget.insertRow(row) self.table_widget.setItem(row, 0, QTableWidgetItem(str(command))) - self.remove_empty_rows() return None def add_request_to_batch(self, request_id) -> None: @@ -264,16 +269,16 @@ def add_request_to_batch(self, request_id) -> None: return None - def get_json_data(self, directory, name) -> dict: - with open(os.path.join(directory, name + ".json"), "r") as file: + def get_json_data(self, name) -> dict: + with open(os.path.join(self.directory, name + ".json"), "r") as file: data = json.load(file) return data def check_current_batch(self, name, row, button1, button2, current_batch) -> None: if name == current_batch: - for col in range(self.table_widget.columnCount()): - item = self.table_widget.item(row, col) + for col in range(self.table_widget_batches.columnCount()): + item = self.table_widget_batches.item(row, col) if item is not None: item.setBackground(Qt.gray) button1.setEnabled(False) @@ -287,19 +292,6 @@ def check_current_batch(self, name, row, button1, button2, current_batch) -> Non return None - def remove_empty_rows(self) -> None: - for row in range(self.table_widget.rowCount() - 1, -1, -1): - empty = True - for col in range(self.table_widget.columnCount()): - item = self.table_widget.item(row, col) - if item is not None and not item.text().strip() == "": - empty = False - break - if empty: - self.table_widget.removeRow(row) - - return None - def load_json_requests(self): with open('state/state.json', 'r') as f: self.data_requests = json.load(f) @@ -309,17 +301,6 @@ def save_data(self) -> None: return None - def reload_json(self) -> None: - if self.isActiveWindow(): - self.save_data() - self.update_json_timer.stop() - self.hide() - self.general_window = MainGUI(self.racer, self.state, self.command_processor) - self.general_window.show() - self.deleteLater() - - return None - def set_current_batch(self, batch_name) -> None: self.racer.set_curr_batch_by_name(self.racer, batch_name) self.current_batch = batch_name @@ -394,10 +375,6 @@ def init_ui(self) -> None: vbox.insertWidget(0, self.table_widget) - self.update_json_timer = QTimer() - self.update_json_timer.timeout.connect(lambda: self.reload_json()) - self.update_json_timer.start(10000) - return None def create_requests_widget(self, vbox): @@ -488,17 +465,6 @@ def remove_request(self, request_id) -> None: return None - def reload_json(self) -> None: - if self.isActiveWindow(): - self.save_data() - self.update_json_timer.stop() - self.hide() - self.general_window = BatchWindow(self.batch_name, self.racer, self.state, self.command_processor) - self.general_window.show() - self.deleteLater() - - return None - class RequestWindow(QMainWindow): def __init__(self, request_id, racer, state, command_processor): @@ -534,10 +500,6 @@ def init_ui(self): vbox.insertWidget(0, self.table_widget) - self.update_json_timer = QTimer() - self.update_json_timer.timeout.connect(self.reload_json) - self.update_json_timer.start(10000) - def load_request(self) -> None: requests_data = self.load_json("state/state.json")["requests"] request_data = requests_data.get(str(self.request_id)) @@ -614,14 +576,3 @@ def save_data(self) -> None: self.racer.comm_general_save(True) return None - - def reload_json(self) -> None: - if self.isActiveWindow(): - self.save_data() - self.update_json_timer.stop() - self.hide() - self.general_window = RequestWindow(self.request_id, self.racer, self.state, self.command_processor) - self.general_window.show() - self.deleteLater() - - return None From 0e1c57faa927d111c178a1dab234b2b60a53224b Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Tue, 11 Apr 2023 15:32:37 +0200 Subject: [PATCH 40/48] Update code --- CompuRacer_Core/src/compu_racer_core.py | 33 ++++++++++++++--------- CompuRacer_Core/src/gui.py | 36 ++++++++++++++++--------- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index efb374d..15e399d 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -873,7 +873,7 @@ def comm_requests_comp(self, request_id_1, request_id_2, print_matches=False): self.colorprint_comp_results(self, comp) @staticmethod # do not add requests to this list in any other way - def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_confirmation=False): + def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_confirmation=True): with self.requests_list_lock: if not self.state['requests']: self.print_formatted(f"There is no request to delete: The total request list is empty!", @@ -895,16 +895,19 @@ def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_ self.print_formatted(f"Removal of all requests cancelled.", utils.QType.INFORMATION) return elif request_id_last is not None: - # remove a range of requests - for i, request_id in enumerate(copy.deepcopy(list(self.state['requests'].keys()))): - if request_id_first <= request_id <= request_id_last: - if self.rem_request(self, request_id, False) == -1: - failed_requests.append(request_id) - else: - success_requests.append(request_id) - else: - self.print_formatted(f"Removal of range of requests cancelled.", utils.QType.INFORMATION) - return + if not ask_confirmation or self.command_processor.accept_yes_no( + f"Are you sure you want to remove requests with id between and including {request_id_first} and {request_id_last}?", + utils.QType.WARNING): + # remove a range of requests + for i, request_id in enumerate(copy.deepcopy(list(self.state['requests'].keys()))): + if request_id_first <= request_id <= request_id_last: + if self.rem_request(self, request_id, False) == -1: + failed_requests.append(request_id) + else: + success_requests.append(request_id) + else: + self.print_formatted(f"Removal of range of requests cancelled.", utils.QType.INFORMATION) + return else: # remove one request if self.rem_request(self, request_id_first, True) == -1: @@ -1108,7 +1111,7 @@ def gui_remove_request(self, request_id): curr_batch.remove(request_id, None) @staticmethod # do not add requests to this list in any other way - def rem_request(self, request_id, ask_confirmation=False): + def rem_request(self, request_id, ask_confirmation=True): with self.requests_list_lock: if request_id not in self.state['requests']: self.print_formatted(f"Cannot remove request:\n\t" @@ -1127,6 +1130,12 @@ def rem_request(self, request_id, ask_confirmation=False): f"{used_in}. It must be removed individually.", utils.QType.ERROR) return -1 + # remove request from the batches + if ask_confirmation: + if not self.command_processor.accept_yes_no(f"The request with id '{request_id}' is used by batches: " + f"{used_in}, continue?\n\tIt will be removed from these batches and their results are cleared!!", + utils.QType.WARNING): + return -1 for batch_name in used_in: self.state['batches'][batch_name].remove(request_id) ask_confirmation = False diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 0d3a9f9..0b29612 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -15,7 +15,6 @@ def load_json_batches(directory) -> List[Any]: data = json.load(file) if "name" in data: file_names.append(data["name"]) - return file_names @@ -68,8 +67,6 @@ def init_ui(self) -> None: self.create_batch_widget(vbox_general, general_tab) self.create_logs_widget(vbox_logs, logs_tab) - self.update_json() - self.setCentralWidget(tabs) return None @@ -80,6 +77,9 @@ def create_request_widget(self, vbox, requests_tab) -> None: # --- Creating Table --- # self.table_widget_requests = QTableWidget() self.table_widget_requests.setColumnCount(8) + self.table_widget_requests.setColumnWidth(0, 20) + self.table_widget_requests.setColumnWidth(1, 500) + self.table_widget_requests.setColumnWidth(3, 200) self.table_widget_requests.setHorizontalHeaderLabels(["ID", "URL", "Method", "Timestamp", "Host", "Add To Batch", "Open", "Remove"]) vbox.addWidget(self.table_widget_requests) @@ -122,16 +122,12 @@ def create_batch_widget(self, vbox, batches_tab) -> None: return None - def update_json(self): + def update_json(self) -> None: self.save_data() self.load_requests() self.load_batches() - print("python1") - - self.update_json_timer = QTimer() - self.update_json_timer.timeout.connect(lambda: self.update_json()) - self.update_json_timer.start(5000) + return None def create_logs_widget(self, vbox, logs_tab) -> None: vbox.addWidget(QLabel("Logs")) @@ -169,7 +165,7 @@ def create_requests_button_widget(self, request, row) -> None: return None - def load_requests(self): + def load_requests(self) -> None: self.load_json_requests() rows_to_delete = [] @@ -209,6 +205,8 @@ def load_requests(self): self.create_requests_button_widget(request_id, row) + return None + def load_batches(self) -> callable([]): self.directory = "state/batches" self.file_names = load_json_batches(self.directory) @@ -267,6 +265,8 @@ def load_logs(self) -> None: def add_request_to_batch(self, request_id) -> None: self.racer.comm_curr_add(self.racer, request_id) + self.update_json() + return None def get_json_data(self, name) -> dict: @@ -292,10 +292,12 @@ def check_current_batch(self, name, row, button1, button2, current_batch) -> Non return None - def load_json_requests(self): + def load_json_requests(self) -> None: with open('state/state.json', 'r') as f: self.data_requests = json.load(f) + return None + def save_data(self) -> None: self.racer.comm_general_save() @@ -305,11 +307,15 @@ def set_current_batch(self, batch_name) -> None: self.racer.set_curr_batch_by_name(self.racer, batch_name) self.current_batch = batch_name + self.update_json() + return None def remove_request(self, request_id) -> None: self.racer.comm_requests_remove(self.racer, request_id, None, False) + self.update_json() + return None def new_batch_window(self, batch_name) -> None: @@ -334,6 +340,8 @@ def create_new_batch(self, batch_name) -> None: batch_name = batch_name.text() self.racer.comm_batches_create_new(self.racer, batch_name) + self.update_json() + return None @@ -377,7 +385,7 @@ def init_ui(self) -> None: return None - def create_requests_widget(self, vbox): + def create_requests_widget(self, vbox) -> None: self.table_widget = QTableWidget() vbox.addWidget(QLabel("")) self.table_widget.setColumnCount(5) @@ -385,7 +393,9 @@ def create_requests_widget(self, vbox): self.add_request_table() - def load_json(self, filepath): + return None + + def load_json(self, filepath) -> List[Any]: with open(filepath, 'r') as file: data = json.load(file) From a2fa969e171a5014267a23239b9df626c825bffd Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 20 Apr 2023 13:38:19 +0200 Subject: [PATCH 41/48] merge conflicts --- CompuRacer_Core/src/compu_racer_core.py | 79 +++++++++---------------- 1 file changed, 29 insertions(+), 50 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index 15e399d..c1a4463 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -100,7 +100,7 @@ class CompuRacer: immediate_batch_name = "Imm" progress_bar_width = 100 - def __init__(self, port, proxy, queue, use_only_cli): + def __init__(self, port, proxy, queue, cli_check): """ Creates a new CompuRacer instance :param queue: the queue to be used when we want to display a filepicker dialog to the user @@ -110,7 +110,7 @@ def __init__(self, port, proxy, queue, use_only_cli): # if the queue is None, we cannot and will not show dialogs self.dialog_queue = queue - self.use_only_cli = use_only_cli + self.cli_check = cli_check # add shutdown hooks signal.signal(signal.SIGINT, self.force_shutdown) @@ -201,7 +201,7 @@ def set_unchanged(self): if self.command_processor.is_changed(): self.command_processor.set_changed(False) - def start(self, use_only_cli): + def start(self, cli_check, racer): """ Starts the CompuRacer """ @@ -224,7 +224,7 @@ def start(self, use_only_cli): self.print_formatted("Starting command processor..", utils.QType.INFORMATION) time.sleep(0.25) utils.clear_output() - self.command_processor.start(use_only_cli, self, self.state) + self.command_processor.start(cli_check, racer, self.state) def comm_general_save(self, do_print=True): """ @@ -910,7 +910,7 @@ def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_ return else: # remove one request - if self.rem_request(self, request_id_first, True) == -1: + if self.rem_request(self, request_id_first, False) == -1: failed_requests.append(request_id_first) else: success_requests.append(request_id_first) @@ -1062,7 +1062,6 @@ def add_request(self, a_request, used_from_interface=False, print_information=Tr return self.comm_batches_create_new(self, self.immediate_batch_name, False, not used_from_interface, allow_redirects, sync_last_byte, send_timeout) - immediate_batch = self.state['batches'][self.immediate_batch_name] try: immediate_batch.add(req_id, 0, par, seq, False) @@ -1106,10 +1105,6 @@ def request_used_in(self, request_id): used_in.append(batch_name) return used_in - def gui_remove_request(self, request_id): - curr_batch = self.state['batches'][self.state['current_batch']] - curr_batch.remove(request_id, None) - @staticmethod # do not add requests to this list in any other way def rem_request(self, request_id, ask_confirmation=True): with self.requests_list_lock: @@ -1139,6 +1134,13 @@ def rem_request(self, request_id, ask_confirmation=True): for batch_name in used_in: self.state['batches'][batch_name].remove(request_id) ask_confirmation = False + if not ask_confirmation or self.command_processor.accept_yes_no( + f"Are you sure you want to remove the request with id '{request_id}'?", + utils.QType.WARNING): + self.__change_state('requests', sub_search=request_id, do_delete=True) + self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) + else: + self.print_formatted(f"Removal of request cancelled.", utils.QType.INFORMATION) self.__change_state('requests', sub_search=request_id, do_delete=True) self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) @@ -1911,46 +1913,23 @@ def comm_curr_remove(self, request_id=None, wait_time=None): self.print_formatted(f"Cannot remove a request from current batch: The current batch is empty!", utils.QType.ERROR) return -1 - if request_id is None: - # remove all items from the batch - question = "Are you sure you want to remove all requests from the current batch?" - elif wait_time is None: - # remove all items with a certain ID from the batch - question = f"Are you sure you want to remove all requests with id '{request_id}' from the current batch?" - else: - # remove a specific item with a certain ID and wait_time from the batch - question = f"Are you sure you want to remove the request with id '{request_id}' and wait_time '{wait_time}' from the current batch?" - if self.command_processor.accept_yes_no(question, utils.QType.WARNING): - num_removed = curr_batch.remove(request_id, wait_time) - self.print_formatted(f"All matching requests are removed from the current batch.\nNumber: {num_removed}", - utils.QType.INFORMATION) - else: - self.print_formatted(f"Removal of current batch requests cancelled.", utils.QType.INFORMATION) - - def gui_comm_curr_remove(self, request_id=None, wait_time=None): - """ - Removes requests from the current batch - :param self: reference to the CompuRacer - :param request_id: the request to remove, or if None, all requests - :param wait_time: the wait_time of the request to remove, or if None, all regardless of wait_time - :return: 0 on success and -1 on error - """ - if not self.state['current_batch']: - self.print_formatted( - f"Cannot remove a request from current batch: There is no current batch! First, select a current batch.", - utils.QType.ERROR) - return -1 - curr_batch = self.state['batches'][self.state['current_batch']] - if curr_batch.is_empty(): - self.print_formatted(f"Cannot remove a request from current batch: The current batch is empty!", - utils.QType.ERROR) - return -1 - if request_id is None: - # remove all items from the batch - question = "Are you sure you want to remove all requests from the current batch?" - self.print_formatted("Dit is een andere test voor request nummer : " + request_id) - - curr_batch.remove(request_id, wait_time) + if self.cli_check: + if request_id is None: + # remove all items from the batch + question = "Are you sure you want to remove all requests from the current batch?" + elif wait_time is None: + # remove all items with a certain ID from the batch + question = f"Are you sure you want to remove all requests with id '{request_id}' from the current batch?" + else: + # remove a specific item with a certain ID and wait_time from the batch + question = f"Are you sure you want to remove the request with id '{request_id}' and wait_time '{wait_time}' from the current batch?" + if self.command_processor.accept_yes_no(question, utils.QType.WARNING): + num_removed = curr_batch.remove(request_id, wait_time) + self.print_formatted(f"All matching requests are removed from the current batch.\nNumber: {num_removed}", + utils.QType.INFORMATION) + num_removed = curr_batch.remove(request_id, wait_time) + self.print_formatted(f"All matching requests are removed from the current batch.\nNumber: {num_removed}", + utils.QType.INFORMATION) # ------------------------------------------------------------------------------------------------- # # ------------------------------------- Main helper functions ------------------------------------- # From ba40bd9e17734289285b275e13b7cc30cc3a0f68 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Wed, 12 Apr 2023 11:30:31 +0200 Subject: [PATCH 42/48] Remove request changed --- CompuRacer_Core/src/compu_racer_core.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index c1a4463..ade5591 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -910,7 +910,7 @@ def comm_requests_remove(self, request_id_first=None, request_id_last=None, ask_ return else: # remove one request - if self.rem_request(self, request_id_first, False) == -1: + if self.rem_request(self, request_id_first, True) == -1: failed_requests.append(request_id_first) else: success_requests.append(request_id_first) @@ -1120,28 +1120,14 @@ def rem_request(self, request_id, ask_confirmation=True): f"The request with id '{request_id}' is (also) used by the immediate batch!", utils.QType.ERROR) return -1 - if not ask_confirmation: + if self.cli_check: self.print_formatted(f"The request with id '{request_id}' is used by batches: " f"{used_in}. It must be removed individually.", utils.QType.ERROR) return -1 - # remove request from the batches - if ask_confirmation: - if not self.command_processor.accept_yes_no(f"The request with id '{request_id}' is used by batches: " - f"{used_in}, continue?\n\tIt will be removed from these batches and their results are cleared!!", - utils.QType.WARNING): - return -1 for batch_name in used_in: self.state['batches'][batch_name].remove(request_id) ask_confirmation = False - if not ask_confirmation or self.command_processor.accept_yes_no( - f"Are you sure you want to remove the request with id '{request_id}'?", - utils.QType.WARNING): - self.__change_state('requests', sub_search=request_id, do_delete=True) - self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) - else: - self.print_formatted(f"Removal of request cancelled.", utils.QType.INFORMATION) - self.__change_state('requests', sub_search=request_id, do_delete=True) self.print_formatted(f"Request with id '{request_id}' is removed", utils.QType.INFORMATION) From 378acc92288280c5968e18002de970109a915092 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Mon, 17 Apr 2023 10:14:44 +0200 Subject: [PATCH 43/48] Deleted timer (timer does not exist) --- CompuRacer_Core/src/gui.py | 1 - 1 file changed, 1 deletion(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 0b29612..ed09dcf 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -320,7 +320,6 @@ def remove_request(self, request_id) -> None: def new_batch_window(self, batch_name) -> None: self.save_data() - self.update_json_timer.stop() self.batch_window = BatchWindow(batch_name, self.racer, self.state, self.command_processor) self.batch_window.show() self.hide() From 3e12bf3159194b4a87d5f41d0695c13966967a2c Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Mon, 17 Apr 2023 12:58:27 +0200 Subject: [PATCH 44/48] Work in progress --- CompuRacer_Core/src/gui.py | 96 +++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 21 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index ed09dcf..78d701a 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -378,28 +378,60 @@ def init_ui(self) -> None: self.add_button_widget(vbox) self.setCentralWidget(tabs) - self.create_requests_widget(vbox) + self.add_request_table(vbox) + self.add_propperty_widget(vbox) vbox.insertWidget(0, self.table_widget) return None - def create_requests_widget(self, vbox) -> None: - self.table_widget = QTableWidget() - vbox.addWidget(QLabel("")) - self.table_widget.setColumnCount(5) - self.table_widget.setHorizontalHeaderLabels(["ID", "URL", "Method", "Host", "Remove"]) - - self.add_request_table() - - return None - def load_json(self, filepath) -> List[Any]: with open(filepath, 'r') as file: data = json.load(file) return data + def update_json(self) -> None: + self.save_data() + self.load_requests() + + return None + + def add_propperty_widget(self, vbox) -> None: + allow_redirects = self.load_json("state/batches/" + self.batch_name + ".json")["allow_redirects"] + sync_last_byte = self.load_json("state/batches/" + self.batch_name + ".json")["sync_last_byte"] + send_tiemout = self.load_json("state/batches/" + self.batch_name + ".json")["send_timeout"] + + change_allow_redirects_field = QLineEdit() + change_allow_redirects_button = QPushButton("Change Allow_Redirects", self) + change_allow_redirects_button.clicked.connect(lambda _, input_field=change_allow_redirects_field: self.change_allow_redirects(input_field)) + + change_sync_last_byte_field = QLineEdit() + change_sync_last_byte_button = QPushButton("Change Sync_Last_Byte", self) + change_sync_last_byte_button.clicked.connect(lambda _, input_field=change_sync_last_byte_field: self.change_sync_last_byte(input_field)) + + change_send_timeout_field = QLineEdit() + change_send_timeout_button = QPushButton("Change Send_Timeout", self) + change_send_timeout_button.clicked.connect(lambda _, input_field=change_send_timeout_field: self.change_send_timeout(input_field)) + + hbox = QHBoxLayout() + hbox.addWidget(change_allow_redirects_field) + hbox.addWidget(change_allow_redirects_button) + + hbox.addWidget(change_sync_last_byte_field) + hbox.addWidget(change_sync_last_byte_button) + + hbox.addWidget(change_send_timeout_field) + hbox.addWidget(change_send_timeout_button) + + vbox.addLayout(hbox) + + return None + + def add_propperties(self, vbox) -> None: + + return None + def add_button_widget(self, vbox) -> None: send_batch_button = QPushButton("Send Batch") go_back_button = QPushButton("Go Back") @@ -415,21 +447,44 @@ def add_button_widget(self, vbox) -> None: return None - def add_request_table(self) -> None: - items = self.load_json("state/batches/" + self.batch_name + ".json")["items"] - requests = self.load_json("state/state.json")["requests"] - - self.table_widget = QTableWidget(len(items), 5, self) + def add_request_table(self, vbox) -> None: + self.table_widget = QTableWidget() + self.table_widget.setColumnCount(5) self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host", "Remove"]) self.table_widget.setColumnWidth(0, 50) self.table_widget.setColumnWidth(1, 50) - self.table_widget.setColumnWidth(2, 300) + self.table_widget.setColumnWidth(2, 600) self.table_widget.setColumnWidth(3, 100) self.table_widget.setColumnWidth(4, 100) + vbox.addWidget(self.table_widget) + + self.load_requests() + + return None + + def change_allow_redirects(self, value): + value.text() + + return None + + def change_sync_last_byte(self, value): + value.text() + + return None + + def change_send_timeout(self, value): + value.text() + + return None + + def load_requests(self) -> None: + items = self.load_json("state/batches/" + self.batch_name + ".json")["items"] + requests = self.load_json("state/state.json")["requests"] remove_button = QPushButton("Remove", self) - self.table_widget.verticalHeader().hide() + # set the number of rows in the table widget + self.table_widget.setRowCount(len(items)) for i, item in enumerate(items): request_id = item["key"][0] @@ -446,9 +501,6 @@ def add_request_table(self) -> None: self.table_widget.setCellWidget(i, 4, remove_button) remove_button.clicked.connect(lambda _, request_id=str(request_id): self.remove_request(request_id)) - self.racer.print_formatted("Dit is een test voor request : " + request_id) - - return None def send_batch(self) -> None: self.save_data() @@ -472,6 +524,8 @@ def save_data(self) -> None: def remove_request(self, request_id) -> None: self.racer.comm_curr_remove(self.racer, request_id) + self.update_json() + return None From a48ff4e84ec738a3d68774fd7171dba8f4707ebf Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 20 Apr 2023 12:52:51 +0200 Subject: [PATCH 45/48] Fixed change propperties of batch --- CompuRacer_Core/src/gui.py | 94 ++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 24 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 78d701a..9aac01f 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -348,6 +348,7 @@ class BatchWindow(QMainWindow): def __init__(self, batch_name, racer, state, command_processor) -> None: super().__init__() + self.table_widget_propperty = None self.showFullScreen() self.setWindowTitle("Batch: " + batch_name) @@ -376,13 +377,17 @@ def init_ui(self) -> None: vbox.addStretch() + self.add_batch_propperty_widget(vbox) + self.add_button_widget(vbox) self.setCentralWidget(tabs) self.add_request_table(vbox) - self.add_propperty_widget(vbox) vbox.insertWidget(0, self.table_widget) + # Add batch_tab to tabs widget + tabs.addTab(batch_tab, "Batch") + return None def load_json(self, filepath) -> List[Any]: @@ -394,31 +399,34 @@ def load_json(self, filepath) -> List[Any]: def update_json(self) -> None: self.save_data() self.load_requests() + self.load_propperties() return None - def add_propperty_widget(self, vbox) -> None: - allow_redirects = self.load_json("state/batches/" + self.batch_name + ".json")["allow_redirects"] - sync_last_byte = self.load_json("state/batches/" + self.batch_name + ".json")["sync_last_byte"] - send_tiemout = self.load_json("state/batches/" + self.batch_name + ".json")["send_timeout"] + def add_batch_propperty_widget(self, vbox) -> None: + self.table_widget_propperty = QTableWidget() + self.table_widget_propperty.setColumnCount(3) + self.table_widget_propperty.setHorizontalHeaderLabels(["Allow Redirects", "Sync Last Byte", "Send Timeout"]) + vbox.addWidget(self.table_widget_propperty) - change_allow_redirects_field = QLineEdit() - change_allow_redirects_button = QPushButton("Change Allow_Redirects", self) - change_allow_redirects_button.clicked.connect(lambda _, input_field=change_allow_redirects_field: self.change_allow_redirects(input_field)) + self.add_propperty_widget(vbox) + self.load_propperties() - change_sync_last_byte_field = QLineEdit() - change_sync_last_byte_button = QPushButton("Change Sync_Last_Byte", self) - change_sync_last_byte_button.clicked.connect(lambda _, input_field=change_sync_last_byte_field: self.change_sync_last_byte(input_field)) + return None + + def add_propperty_widget(self, vbox) -> None: + change_allow_redirects_button = QPushButton("Change Allow Redirects", self) + change_allow_redirects_button.clicked.connect(lambda _: self.change_allow_redirects()) + + change_sync_last_byte_button = QPushButton("Change Sync Last Byte", self) + change_sync_last_byte_button.clicked.connect(lambda _: self.change_sync_last_byte()) change_send_timeout_field = QLineEdit() - change_send_timeout_button = QPushButton("Change Send_Timeout", self) + change_send_timeout_button = QPushButton("Change Send Timeout", self) change_send_timeout_button.clicked.connect(lambda _, input_field=change_send_timeout_field: self.change_send_timeout(input_field)) hbox = QHBoxLayout() - hbox.addWidget(change_allow_redirects_field) hbox.addWidget(change_allow_redirects_button) - - hbox.addWidget(change_sync_last_byte_field) hbox.addWidget(change_sync_last_byte_button) hbox.addWidget(change_send_timeout_field) @@ -428,7 +436,21 @@ def add_propperty_widget(self, vbox) -> None: return None - def add_propperties(self, vbox) -> None: + def load_propperties(self) -> None: + properties = self.load_json("state/batches/" + self.batch_name + ".json") + allow_redirects = properties["allow_redirects"] + sync_last_byte = properties["sync_last_byte"] + send_timeout = properties["send_timeout"] + + print(allow_redirects) + print(sync_last_byte) + print(send_timeout) + + self.table_widget_propperty.setRowCount(1) + + self.table_widget_propperty.setItem(0, 0, QTableWidgetItem("test")) + self.table_widget_propperty.setItem(0, 1, QTableWidgetItem(str(sync_last_byte))) + self.table_widget_propperty.setItem(0, 2, QTableWidgetItem(str(send_timeout))) return None @@ -449,8 +471,8 @@ def add_button_widget(self, vbox) -> None: def add_request_table(self, vbox) -> None: self.table_widget = QTableWidget() - self.table_widget.setColumnCount(5) - self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host", "Remove"]) + self.table_widget.setColumnCount(8) + self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host", "Delay Time", "Num Parallel", "Num Sequential", "Remove"]) self.table_widget.setColumnWidth(0, 50) self.table_widget.setColumnWidth(1, 50) self.table_widget.setColumnWidth(2, 600) @@ -463,18 +485,35 @@ def add_request_table(self, vbox) -> None: return None - def change_allow_redirects(self, value): - value.text() + def change_allow_redirects(self) -> None: + allow_redirects = self.load_json("state/batches/" + self.batch_name + ".json")["allow_redirects"] + + if allow_redirects is True: + self.racer.comm_curr_change_redirects(self.racer, False) + else: + self.racer.comm_curr_change_redirects(self.racer, True) + + self.update_json() return None - def change_sync_last_byte(self, value): - value.text() + def change_sync_last_byte(self): + sync_last_byte = self.load_json("state/batches/" + self.batch_name + ".json")["sync_last_byte"] + + if sync_last_byte is True: + self.racer.comm_curr_change_sync(self.racer, False) + else: + self.racer.comm_curr_change_sync(self.racer, True) + + self.update_json() return None def change_send_timeout(self, value): - value.text() + send_timeout = int(value.text()) + + self.racer.comm_curr_change_timeout(self.racer, send_timeout) + self.update_json() return None @@ -488,6 +527,10 @@ def load_requests(self) -> None: for i, item in enumerate(items): request_id = item["key"][0] + delay_time = item["key"][1] + num_parallel = item["value"][0] + num_sequential = item["value"][1] + request = requests[request_id] method = request["method"] @@ -498,7 +541,10 @@ def load_requests(self) -> None: self.table_widget.setItem(i, 1, QTableWidgetItem(method)) self.table_widget.setItem(i, 2, QTableWidgetItem(url)) self.table_widget.setItem(i, 3, QTableWidgetItem(host)) - self.table_widget.setCellWidget(i, 4, remove_button) + self.table_widget.setItem(i, 4, QTableWidgetItem(str(delay_time))) + self.table_widget.setItem(i, 5, QTableWidgetItem(str(num_parallel))) + self.table_widget.setItem(i, 6, QTableWidgetItem(str(num_sequential))) + self.table_widget.setCellWidget(i, 7, remove_button) remove_button.clicked.connect(lambda _, request_id=str(request_id): self.remove_request(request_id)) From 99f1498cb1bf76c2a9a0d569de95c49a2793d656 Mon Sep 17 00:00:00 2001 From: Bart van Wijk Date: Thu, 20 Apr 2023 13:54:19 +0200 Subject: [PATCH 46/48] Fix after merge --- CompuRacer_Core/src/compu_racer_core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CompuRacer_Core/src/compu_racer_core.py b/CompuRacer_Core/src/compu_racer_core.py index ade5591..d23930c 100644 --- a/CompuRacer_Core/src/compu_racer_core.py +++ b/CompuRacer_Core/src/compu_racer_core.py @@ -201,7 +201,7 @@ def set_unchanged(self): if self.command_processor.is_changed(): self.command_processor.set_changed(False) - def start(self, cli_check, racer): + def start(self, cli_check): """ Starts the CompuRacer """ @@ -224,7 +224,7 @@ def start(self, cli_check, racer): self.print_formatted("Starting command processor..", utils.QType.INFORMATION) time.sleep(0.25) utils.clear_output() - self.command_processor.start(cli_check, racer, self.state) + self.command_processor.start(cli_check, self, self.state) def comm_general_save(self, do_print=True): """ From 02c43c7cac27ab6ba5f426e8bd4659a19f9b9d8e Mon Sep 17 00:00:00 2001 From: Bart van Wijk <91336914+Wolkjuh@users.noreply.github.com> Date: Mon, 8 May 2023 09:40:12 +0200 Subject: [PATCH 47/48] Updated some checks --- CompuRacer_Core/src/gui.py | 43 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index 9aac01f..c7a2f87 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -2,9 +2,12 @@ import os from typing import List, Any -from PyQt5.QtCore import Qt, QTimer -from PyQt5.QtWidgets import QPushButton, QMainWindow, QVBoxLayout, QLabel, QTableWidget, QTableWidgetItem, QTabWidget, QWidget, QMessageBox, QLineEdit, QHBoxLayout, QApplication, QHeaderView, QTableView +from PyQt5.QtCore import Qt from PyQt5.QtGui import QStandardItem, QStandardItemModel +from PyQt5.QtWidgets import QPushButton, QMainWindow, QVBoxLayout, QLabel, QTableWidget, QTableWidgetItem, QTabWidget, \ + QWidget, QLineEdit, QHBoxLayout, QApplication, QHeaderView, QTableView + +from src.batch import Batch def load_json_batches(directory) -> List[Any]: @@ -23,7 +26,6 @@ def __init__(self, racer, state, command_processor) -> None: super().__init__() self.request_window = None - self.update_json_timer = None self.general_window = None self.batch_window = None self.current_batch = None @@ -327,8 +329,7 @@ def new_batch_window(self, batch_name) -> None: return None def new_request_window(self, request_id) -> None: - self.save_data() - self.update_json_timer.stop() + self.update_json() self.request_window = RequestWindow(request_id, self.racer, self.state, self.command_processor) self.request_window.show() self.hide() @@ -352,9 +353,8 @@ def __init__(self, batch_name, racer, state, command_processor) -> None: self.showFullScreen() self.setWindowTitle("Batch: " + batch_name) - self.update_json_timer = None self.general_window = None - self.table_widget = None + self.table_widget = QTableWidget() self.racer = racer self.batch_name = batch_name @@ -385,7 +385,6 @@ def init_ui(self) -> None: vbox.insertWidget(0, self.table_widget) - # Add batch_tab to tabs widget tabs.addTab(batch_tab, "Batch") return None @@ -405,8 +404,8 @@ def update_json(self) -> None: def add_batch_propperty_widget(self, vbox) -> None: self.table_widget_propperty = QTableWidget() - self.table_widget_propperty.setColumnCount(3) - self.table_widget_propperty.setHorizontalHeaderLabels(["Allow Redirects", "Sync Last Byte", "Send Timeout"]) + self.table_widget_propperty.setColumnCount(4) + self.table_widget_propperty.setHorizontalHeaderLabels(["Allow Redirects", "Sync Last Byte", "Send Timeout", "Batch Sent"]) vbox.addWidget(self.table_widget_propperty) self.add_propperty_widget(vbox) @@ -441,16 +440,17 @@ def load_propperties(self) -> None: allow_redirects = properties["allow_redirects"] sync_last_byte = properties["sync_last_byte"] send_timeout = properties["send_timeout"] - - print(allow_redirects) - print(sync_last_byte) - print(send_timeout) + sent_batch = properties["results"] self.table_widget_propperty.setRowCount(1) - self.table_widget_propperty.setItem(0, 0, QTableWidgetItem("test")) + self.table_widget_propperty.setItem(0, 0, QTableWidgetItem(str(allow_redirects))) self.table_widget_propperty.setItem(0, 1, QTableWidgetItem(str(sync_last_byte))) self.table_widget_propperty.setItem(0, 2, QTableWidgetItem(str(send_timeout))) + if len(sent_batch) == 0: + self.table_widget_propperty.setItem(0, 3, QTableWidgetItem("False")) + else: + self.table_widget_propperty.setItem(0, 3, QTableWidgetItem("True")) return None @@ -470,7 +470,6 @@ def add_button_widget(self, vbox) -> None: return None def add_request_table(self, vbox) -> None: - self.table_widget = QTableWidget() self.table_widget.setColumnCount(8) self.table_widget.setHorizontalHeaderLabels(["ID", "Method", "URL", "Host", "Delay Time", "Num Parallel", "Num Sequential", "Remove"]) self.table_widget.setColumnWidth(0, 50) @@ -510,10 +509,11 @@ def change_sync_last_byte(self): return None def change_send_timeout(self, value): - send_timeout = int(value.text()) + if value.text().isdigit(): + send_timeout = int(value.text()) - self.racer.comm_curr_change_timeout(self.racer, send_timeout) - self.update_json() + self.racer.comm_curr_change_timeout(self.racer, send_timeout) + self.update_json() return None @@ -522,7 +522,6 @@ def load_requests(self) -> None: requests = self.load_json("state/state.json")["requests"] remove_button = QPushButton("Remove", self) - # set the number of rows in the table widget self.table_widget.setRowCount(len(items)) for i, item in enumerate(items): @@ -550,9 +549,10 @@ def load_requests(self) -> None: def send_batch(self) -> None: self.save_data() - self.update_json_timer.stop() self.racer.comm_batches_send(self.racer) + self.update_json() + return None def go_back(self) -> None: @@ -585,7 +585,6 @@ def __init__(self, request_id, racer, state, command_processor): self.command_processor = command_processor self.general_window = None - self.update_json_timer = None self.table_widget = QWidget() From 57b9ab75b8cbe2ed707a7204f20e4559ea1bbc16 Mon Sep 17 00:00:00 2001 From: Bart van Wijk <91336914+Wolkjuh@users.noreply.github.com> Date: Mon, 8 May 2023 09:54:29 +0200 Subject: [PATCH 48/48] Fixed removing requests --- CompuRacer_Core/src/gui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CompuRacer_Core/src/gui.py b/CompuRacer_Core/src/gui.py index c7a2f87..8b064ee 100644 --- a/CompuRacer_Core/src/gui.py +++ b/CompuRacer_Core/src/gui.py @@ -568,7 +568,7 @@ def save_data(self) -> None: return None def remove_request(self, request_id) -> None: - self.racer.comm_curr_remove(self.racer, request_id) + self.racer.comm_requests_remove(self.racer, request_id, None, False) self.update_json()