def begin_tasks(self, tasks, status_message, total_size, threads=TransCodaSettings.get_max_threads()): TransCoda.logger.info(status_message) self.progressbar.setVisible(True) self.progressbar.setValue(0) self.progressbar.setMaximum(total_size) self.executor = CommonUtils.CommandExecutionFactory(tasks, logger=TransCoda.logger, max_threads=threads) self.executor.finish_event.connect(self.jobs_complete_event) self.statusBar().showMessage(status_message) self.executor.start()
def validate_and_start_encoding(self, run_indices=None): def create_runnable(_item): runnable = EncoderCommand(_item) runnable.signals.result.connect(self.result_received_event) runnable.signals.status.connect(self.status_received_event) runnable.signals.log_message.connect(self.terminal_view.log_message) return runnable runnables = [] is_video = False if run_indices is not None: self.main_panel.update_item_status(run_indices, EncoderStatus.WAITING) for index in run_indices: item = self.main_panel.get_items(index) is_video = is_video or item.is_video() runnables.append(create_runnable(item)) else: for index in range(0, self.main_panel.row_count()): item = self.main_panel.get_items(index) self.main_panel.update_item_status([index], EncoderStatus.WAITING) is_video = is_video or item.is_video() runnables.append(create_runnable(item)) if len(runnables) <= 0: self.statusBar().showMessage("Nothing to encode!") return if TransCodaSettings.sort_by_size(): runnables.sort(key=lambda x: x.file.file_size) self.tool_bar.encoding_started() if is_video and TransCodaSettings.is_single_thread_video(): self.begin_tasks(runnables, f"Dispatching {len(runnables)} jobs for serial encoding", len(runnables), threads=1) else: self.begin_tasks(runnables, f"Dispatching {len(runnables)} jobs for encoding", len(runnables), threads=TransCodaSettings.get_max_threads())