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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CompuRacer_Core/src/command_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

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"
__version__ = "v1.1.0"

class GuiThread(QThread):
start_gui_signal = pyqtSignal()
Expand Down Expand Up @@ -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)
Expand Down
132 changes: 34 additions & 98 deletions CompuRacer_Core/src/compu_racer_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,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)],
Expand Down Expand Up @@ -624,7 +624,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)],
Expand Down Expand Up @@ -895,19 +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
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:
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:
Expand Down Expand Up @@ -1059,15 +1059,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(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)
Expand Down Expand Up @@ -1112,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"
Expand All @@ -1126,28 +1120,16 @@ def rem_request(self, request_id, ask_confirmation=False):
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 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

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 ------------------------------------- #
Expand All @@ -1163,9 +1145,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)
Expand Down Expand Up @@ -1221,10 +1200,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):
Expand All @@ -1234,7 +1210,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)
Expand All @@ -1249,10 +1225,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):
Expand Down Expand Up @@ -1474,14 +1447,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!",
Expand Down Expand Up @@ -1798,7 +1763,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
Expand Down Expand Up @@ -1829,37 +1794,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):
Expand Down Expand Up @@ -1965,21 +1899,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)
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 ------------------------------------- #
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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

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_())
Loading