From 7a87a3098e21b5a1b80481c69c1758d81aa8bac9 Mon Sep 17 00:00:00 2001 From: Nyre221 <104171042+Nyre221@users.noreply.github.com> Date: Mon, 16 Oct 2023 21:25:42 +0200 Subject: [PATCH] added support for .kra. Close #18 --- container_viewer.py | 4 ++++ page_viewer.py | 18 ++++++++++++++++++ quick_view.py | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/container_viewer.py b/container_viewer.py index 9cb1d2f..d51465d 100644 --- a/container_viewer.py +++ b/container_viewer.py @@ -361,6 +361,8 @@ def __preload_icons__(self): "/usr/share/icons/breeze/mimetypes/16/application-vnd.oasis.opendocument.text.svg") self.iso_image_icon = QIcon( "/usr/share/icons/breeze/mimetypes/16/application-x-iso.svg") + self.krita_image_icon = QIcon( + "/usr/share/icons/breeze-dark/mimetypes/64/application-x-krita.svg") def __list_icon_chooser__(self, path, is_folder=False): # returns the icon based on the file type. @@ -393,6 +395,8 @@ def __list_icon_chooser__(self, path, is_folder=False): icon = self.document_icon elif extension in [".iso", ".img"]: icon = self.iso_image_icon + elif extension in [".kra"]: + icon = self.krita_image_icon else: icon = self.unknown_icon return icon diff --git a/page_viewer.py b/page_viewer.py index d69db72..7cf4164 100644 --- a/page_viewer.py +++ b/page_viewer.py @@ -14,6 +14,7 @@ import signal import time from queue import Queue +import zipfile class PageViewer(QWidget): @@ -144,6 +145,9 @@ def load_file(self, path, extension): elif extension in [".doc", ".docx", ".odt", ".ods", ".xlsx", ".xls", ".csv", ".odp", ".ppt", ".pptx"]: # converts to pdf. self.__convert_document__(path=path) + elif extension in [".kra"]: + # converts to pdf. + self.__open_kra__(path=path) def __file_loaded__(self): # hides the messages/loading screen and shows qpage. @@ -160,6 +164,20 @@ def hide(self) -> None: self.is_active_viewer = False return super().hide() + def __open_kra__(self,path): + # create a temporary folder + if self.temp_dir is None: + self.temp_dir = tempfile.mkdtemp() + + # open .kra and extract the preview + with zipfile.ZipFile(path, 'r') as zip_ref: + zip_ref.extract("mergedimage.png",self.temp_dir) + + output_dir = self.temp_dir+"/mergedimage.png" + self.load_file(output_dir,".png") + + + def __convert_document__(self, path): # shows a message and stops the function if libreoffice was not found. if self.libreoffice_command is None: diff --git a/quick_view.py b/quick_view.py index 556f5be..4bdfb26 100644 --- a/quick_view.py +++ b/quick_view.py @@ -130,7 +130,7 @@ def load_file_at_index(self, index): if is_folder or extension in [".zip", ".gz", ".xz", ".rar"]: self.load_container_viewer(self.current_file) - elif extension in [".pdf", ".png", ".jpeg", ".jpg", ".webp", ".doc", ".docx", ".odt", ".ods", ".xlsx", ".xls", ".csv", ".odp", ".ppt", ".pptx",".svg", ".svgz"]: + elif extension in [".pdf", ".png", ".jpeg", ".jpg", ".webp", ".doc", ".docx", ".odt", ".ods", ".xlsx", ".xls", ".csv", ".odp", ".ppt", ".pptx",".svg", ".svgz",".kra"]: self.load_page_viewer(self.current_file, extension)