Skip to content

Commit

Permalink
added support for .kra. Close #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyre221 authored Oct 16, 2023
1 parent 61e2e8f commit 7a87a30
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions container_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions page_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import signal
import time
from queue import Queue
import zipfile


class PageViewer(QWidget):
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion quick_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 7a87a30

Please sign in to comment.