def on_button_clicked(self): # If any button is clicked this gets called. # Gets the name of the button that called this method from the main widget. # Makes sure the creds can be read, and gets the specific_names for # the script from the json data using the name of the button. # Creates a ScriptRunner with specific_names and the button name # split into carrier and platform. Moves the ScriptRunner to a new QThread(), objThread. # Connects the start of objThread to the method calling execute_script, and # connects the end of the objThread to a cleanup method. # Starts the thread, updates the label, and appends both the sr and the QThread to lists. sending_button = self.widget.sender() text = sending_button.text() splitName = text.split() carrier = splitName[0] platform = splitName[1] specific_names = self.data[text] # If edit mode is on, send these names to the editor and chill with the rest of the function if self.edit_name_mode: self.currently_editing_button = text self.open_editor(specific_names) return # Otherwise, read and set credentials creds = self.read_creds() if creds == "": return objThread = QThread() sr = ScriptRunner(carrier, specific_names, platform, creds, self.chrome_driver_path) sr.moveToThread(objThread) sr.finished.connect(self.complete_script) objThread.started.connect(sr.start) objThread.finished.connect(objThread.exit) objThread.start() self.currently_running_scripts.append(sr) self.threads.append(objThread) if len(self.currently_running_scripts) == 1: self.label.setText("Working on it...") else: self.label.setText( f"Working on {len(self.currently_running_scripts)} tasks...") self.window.setWindowTitle("In progress")