Support for text files

Added Support for text file displaying.
dev
Peery 4 years ago
parent 907f90ffdd
commit 8e61bffbd3

@ -30,7 +30,9 @@ class Window(QtWidgets.QMainWindow):
self.__pixmap: QPixmap = None
self.__video: QVideoWidget = None
self.__player: QtMultimedia.QMediaPlayer = None
self.__text_player: QtWidgets.QTextEdit = None
self.__showing_video: bool = False
self.__showing_text: bool = False
self.__tmp_imageid_spinbox: int = None
@ -526,6 +528,10 @@ class Window(QtWidgets.QMainWindow):
#self.ui.image_frame.layout().removeWidget(self.__video)
self.__video.hide()
self.ui.image_label.show()
if self.__showing_text: # remove text are from image layout
self.__text_player.hide()
self.ui.image_label.show()
if file_ending in ["gif"]:
self.__showing_video = False
self.__pixmap = QMovie(full_path)
@ -534,7 +540,7 @@ class Window(QtWidgets.QMainWindow):
self.__pixmap.frameChanged.connect(self.on_movie_frame_changed)
elif file_ending in ["webm", "mp4", "mov"]:
self.__showing_video = True
self.__video = QVideoWidget()
self.__video = QVideoWidget() if self.__video is None else self.__video
self.__player = QtMultimedia.QMediaPlayer(None, QtMultimedia.QMediaPlayer.VideoSurface)
self.__player.setVideoOutput(self.__video)
self.__player.setMedia(QtMultimedia.QMediaContent(QUrl.fromLocalFile(full_path)))
@ -545,6 +551,21 @@ class Window(QtWidgets.QMainWindow):
self.__player.stateChanged.connect(self.on_movie_player_state_changed)
self.__player.positionChanged.connect(self.on_movie_position_changed)
elif file_ending in ["txt"]: # for stories or text files
self.__showing_text = True
self.ui.image_label.hide()
self.__text_player = QtWidgets.QTextEdit() if self.__text_player is None else self.__text_player
with open(full_path, "r") as text_file:
story = text_file.read()
text_file.close()
self.__text_player.setText(story)
self.__text_player.setReadOnly(True)
self.ui.image_frame.layout().addWidget(self.__text_player)
self.__text_player.show()
else:
self.__showing_video = False
self.__pixmap = QPixmap(full_path)

Loading…
Cancel
Save