0
from enum import IntEnum
from PySide2 import QtWidgets, QtCore, QtGui
from PySide2.QtWidgets import QMessageBox
import os
from PySide2.QtWidgets import*
from PySide2.QtGui import*
from PySide2 import QtCore

class DockWidget(QtWidgets.QWidget):
    widget_for = 1234
    def __init__(self, iface):
        super().__init__(iface)

        self.iface = iface
        
        #self.image = Slika()

        self.layout = QtWidgets.QVBoxLayout()
        self.model = QtWidgets.QFileSystemModel()
        self.model.setRootPath(QtCore.QDir.rootPath())

        self.tree = QtWidgets.QTreeView()
        self.tree.setModel(self.model)
        self.tree.setRootIndex(self.model.index(QtCore.QDir.currentPath()))
        self.tree.clicked.connect(self.Slika)

        self.layout.addWidget(self.tree)
        self.setLayout(self.layout)
        
    def Slika(self, index):
        ext = [".jpg", ".png", ".pdf"]
        indexItem = self.model.index(index.row(), 0, index.parent())

        file = self.model.filePath(indexItem)
        #self.model.setRootPath(file)
        if file.endswith(tuple(ext)):
            
                index = self.tree.currentIndex()
                file_path = self.model.filePath(index)

                self.window = QWidget()
                self.window.setWindowTitle("View Image")
                self.picture = QPixmap(file_path)
                self.label = QLabel(self.window)
                self.label.setPixmap(self.picture)
                self.label.setGeometry(QtCore.QRect(10, 40, self.picture.width(), self.picture.height()))
                #self.window.resize(self.picture.width()+20, self.picture.height()+100)
                self.window.show()
            
        else:
            try:
                try:
                    try:
                        with open(file ,'r') as f:
                            tekst = f.read()
                    
                        fileName = QtCore.QFileInfo(file).fileName()

                        self.iface.setText(tekst)

                    except UnicodeDecodeError as type_error:
                        QMessageBox.information(self, "Message", "Mozete otvoriti samo tekstualne fajlove i slike.")

                except PermissionError as not_found:
                    pass

            except FileNotFoundError as not_found:
                pass   


I have already set self.central_widget = QtWidgets.QTabWidget(self) in my mainwindow, text is not a problem only picture is

Demi-Lune
  • 1,720
  • 2
  • 12
  • 22
  • Just a remark on readability: no need to nest all those try. Have a look at: https://stackoverflow.com/questions/6095717/python-one-try-multiple-except – Demi-Lune Dec 06 '21 at 16:12

0 Answers0