def start_story(self): """ Is activated with the "Start Story" button. If the story is already running or the story is finished, the button changes to the "Restart" button to restart application. """ if self.start_btn.text() == "Start Story": QtGui.QApplication.processEvents() print("Start button pressed") # Enable button self.pause_btn.setEnabled(True) # Disable buttons self.lang_switch_btn.setText( QtGui.QApplication.translate("main_window", "Close", None, QtGui.QApplication.UnicodeUTF8)) self.start_btn.setText( QtGui.QApplication.translate("main_window", "Close and restart", None, QtGui.QApplication.UnicodeUTF8)) # Prepare new Story self.text_service = None self.image_list = queue.Queue() self.img_index = 0 self.sentence_counter = 0 self.sentence_list = [] # self.text_service.get_sentence_list() self.highlighted_sentence_list = [] # Start story self.text_service = TextService(self.text_edit.toPlainText(), self, self.lang_en, self.def_counter) self.text_service.change_img.connect(self.switch_to_next_image) self.sentence_list = self.text_service.get_sentence_list() self.status_lbl.setText("Preloading...") QtGui.QApplication.processEvents() wait = 0.1 if len(self.text_service.keyword_list) > 3: while self.image_list.qsize() < 2: continue else: wait = 3 self.text_service.start_story(wait_seconds=wait) self.status_lbl.setText("Story is playing") QtGui.QApplication.processEvents() # End of Story else: print("Restart button pressed") self.text_service.stop_play() self.close() restart()
def __init__(self, text): """ Initialize Story Window :param text: text that should be displayed """ super().__init__(flags=QtCore.Qt.FramelessWindowHint) self.setObjectName("MainWindow") self.image_list = queue.Queue() self.img_index = 0 self.setStyleSheet("background-color: rgb(50, 50, 50);") self.central_widget = QtGui.QWidget(self) self.central_widget.setObjectName("central_widget") self.main_layout = QtGui.QVBoxLayout(self.central_widget) self.main_layout.setObjectName("mainlayout") spacer_item = QtGui.QSpacerItem(20, 100, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) self.main_layout.addItem(spacer_item) self.grid_layout = QtGui.QGridLayout() self.grid_layout.setSizeConstraint(QtGui.QLayout.SetMinimumSize) self.grid_layout.setObjectName("grid_layout") self.image_frame = QtGui.QFrame(self) self.image_frame.setMinimumSize(QtCore.QSize(0, 400)) self.image_frame.setMaximumSize(QtCore.QSize(16777215, 512)) self.image_layout = QtGui.QHBoxLayout(self.image_frame) self.image_layout.setSpacing(120) self.image_layout.setContentsMargins(40, -1, 40, -1) self.image_holder3 = QtGui.QLabel(self.image_frame) self.image_holder3.setAlignment(QtCore.Qt.AlignCenter) self.image_layout.addWidget(self.image_holder3) self.image_holder2 = QtGui.QLabel(self.image_frame) self.image_holder2.setAlignment(QtCore.Qt.AlignCenter) self.image_layout.addWidget(self.image_holder2) self.image_holder1 = QtGui.QLabel(self.image_frame) self.image_holder1.setAlignment(QtCore.Qt.AlignCenter) self.image_layout.addWidget(self.image_holder1) self.grid_layout.addWidget(self.image_frame, 0, 0, 1, 1) self.main_layout.addLayout(self.grid_layout) self.frame = QtGui.QFrame(self) self.frame.setMinimumSize(QtCore.QSize(0, 100)) self.subtitle_layout = QtGui.QGridLayout(self.frame) self.subtitle_label = QtGui.QLabel(self.frame) self.subtitle_label.setAlignment(QtCore.Qt.AlignCenter) self.subtitle_label.setObjectName("subtitle_label") self.subtitle_layout.addWidget(self.subtitle_label, 0, 0, 1, 1) self.main_layout.addWidget(self.frame) self.setCentralWidget(self.central_widget) self.subtitle_label.setStyleSheet("font: bold 22px; color: white;") self.subtitle_label.setText( QtGui.QApplication.translate("Form", "Subtitles", None, QtGui.QApplication.UnicodeUTF8)) self.setWindowTitle( QtGui.QApplication.translate("StoryWindow", "Real Time Story Teller", None, QtGui.QApplication.UnicodeUTF8)) self.text_service = TextService(text, self) self.sentence_counter = 0 self.sentence_list = self.text_service.get_sentence_list() self.text_service.change_img.connect(self.switch_to_next_image)