示例#1
0
    def __init__(self, parent=None):
        super(Tree, self).__init__(parent)
        self.setupUi(self)
        self.setWindowTitle("File_Tree")
        self.tree = QTreeWidget()
        font = QtGui.QFont()
        font.setFamily('文泉驿等宽微米黑')
        font.setPixelSize(20)
        path = './Resources/PDFJS/web'
        self.tree.setFont(font)
        self.tree.setStyleSheet(
            "QTreeView::item:hover{color: lightgrey; background-color: rgb(50,50,50)}"
            "QTreeView::item:selected{color: lightgrey; background-color:rgb(80,110,205)}"
            "QTreeView{color: lightgrey; background-color: rgb(30, 30, 30)}"
            "QHeaderView::section{color: lightgrey; background-color: rgb(30, 30, 30);}"
        )
        self.tree.setColumnCount(1)
        self.tree.setColumnWidth(0, 50)
        self.tree.setHeaderLabels(["书籍列表"])
        self.tree.setIconSize(Qt.QSize(25, 25))
        self.tree.setSelectionMode(QAbstractItemView.ExtendedSelection)

        dirs = file_name(path)

        fileInfo = Qt.QFileInfo(path)
        fileIcon = Qt.QFileIconProvider()
        icon = QtGui.QIcon(fileIcon.icon(fileInfo))
        root = FileTreeItem(self.tree)
        root.setText(0, path.split('/')[-1])
        root.setIcon(0, QtGui.QIcon(icon))
        self.CreateTree(dirs, root, path)
        self.setCentralWidget(self.tree)
        QApplication.processEvents()
示例#2
0
    def Open_Folder(self):
        path = QFileDialog.getExistingDirectory(self, "选取文件夹", "./")
        if path == '':
            return
        self.tree = QTreeWidget()
        font = QtGui.QFont()
        font.setFamily('文泉驿等宽微米黑')
        font.setPixelSize(20)
        self.tree.setFont(font)
        self.tree.setColumnCount(1)
        self.tree.setColumnWidth(0, 50)
        self.tree.setHeaderLabels(["书籍列表"])
        self.tree.setIconSize(Qt.QSize(25, 25))
        self.tree.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.tree.setStyleSheet(
            "QTreeView::item:hover{color: lightgrey; background-color: rgb(50,50,50)}"
            "QTreeView::item:selected{color: lightgrey; background-color:rgb(80,110,205)}"
            "QTreeView{color: lightgrey; background-color: rgb(30, 30, 30)}"
            "QHeaderView::section{color: lightgrey; background-color: rgb(30, 30, 30);}"
        )
        self.tree.doubleClicked.connect(
            lambda x: self.EmitFilePath(self.tree.itemFromIndex(x)))

        dirs = file_name(path)

        fileInfo = Qt.QFileInfo(path)
        fileIcon = Qt.QFileIconProvider()
        icon = QtGui.QIcon(fileIcon.icon(fileInfo))
        root = FileTreeItem(self.tree)
        root.setText(0, path.split('/')[-1])
        root.setIcon(0, QtGui.QIcon(icon))
        self.CreateTree(dirs, root, path)
        self.setCentralWidget(self.tree)
        QApplication.processEvents()
示例#3
0
    def setp_path(self):
        self.directory = QFileDialog.getExistingDirectory(self, "选取文件夹", "./")
        if self.directory:
            self.path_dir = []
            self.le_Pic_path.setText(self.directory)
            self.path_files = os.listdir(self.directory)

            fileInfo = Qt.QFileInfo(self.directory)
            fileIcon = Qt.QFileIconProvider()
            icon = QtGui.QIcon(fileIcon.icon(fileInfo))
            self.icon = icon

            self.tree.setRootIsDecorated(False)
            self.tree.setAlternatingRowColors(True)

            model = QFileSystemModel()
            model.setRootPath(self.directory)
            model.setFilter(QDir.Dirs)
            self.tree.setModel(model)
            self.file_num_max = len(self.path_files)
            for paths in self.path_files:
                self.path_dir.append(self.directory + '/' + paths)
            self.tree.setModel(model)

            self.loadImg(self.path_dir[0])
示例#4
0
def getFileInfo(path):
    """获取文件的图片和名字"""
    fileInfo = Qt.QFileInfo(path)
    fileIcon = Qt.QFileIconProvider()
    icon = QtGui.QIcon(fileIcon.icon(fileInfo))
    name = QtCore.QFileInfo(path).fileName()
    return icon, name
示例#5
0
文件: main2.py 项目: 2017ND/dl_detect
    def setp_path(self):
        self.directory = QFileDialog.getExistingDirectory(self, "选取文件夹", "./")
        if self.directory:
            self.treeWidget.clear()
            self.path_dir = []
            self.le_Pic_path.setText(self.directory)
            self.path_files = os.listdir(self.directory)

            fileInfo = Qt.QFileInfo(self.directory)
            fileIcon = Qt.QFileIconProvider()
            icon = QtGui.QIcon(fileIcon.icon(fileInfo))
            root = QTreeWidgetItem(self.treeWidget)
            self.root = root
            root.setIcon(0, QtGui.QIcon(icon))
            root.setText(0, self.directory)
            brush_green = QBrush(QtCore.Qt.green)
            root.setBackground(0, brush_green)
            brush_blue = QBrush(QtCore.Qt.blue)
            root.setBackground(1, brush_blue)

            self.file_num_max = len(self.path_files)
            for paths in self.path_files:
                self.path_dir.append(self.directory + '/' + paths)
            self.CreateTree(root)
            self.treeWidget.addTopLevelItem(root)
            self.treeWidget.expandAll()
            self.loadImg(self.path_dir[0])
示例#6
0
 def CreateTree(self, dirs, root, path):
     for i in dirs:
         path_new = path + '\\' + i
         if os.path.isdir(path_new):
             fileInfo = Qt.QFileInfo(path_new)
             fileIcon = Qt.QFileIconProvider()
             icon = QtGui.QIcon(fileIcon.icon(fileInfo))
             child = QTreeWidgetItem(root)
             child.setText(0, i)
             child.setIcon(0, QtGui.QIcon(icon))
             dirs_new = self.file_name(path_new)
             self.CreateTree(dirs_new, child, path_new)
         else:
             fileInfo = Qt.QFileInfo(path_new)
             fileIcon = Qt.QFileIconProvider()
             icon = QtGui.QIcon(fileIcon.icon(fileInfo))
             child = QTreeWidgetItem(root)
             child.setText(0, i)
             child.setIcon(0, QtGui.QIcon(icon))
示例#7
0
 def CreateTree(self, dirs, root, path):
     for i in dirs:
         path_new = path + '/' + i
         if os.path.isdir(path_new):
             fileInfo = Qt.QFileInfo(path_new)
             fileIcon = Qt.QFileIconProvider()
             icon = QtGui.QIcon(fileIcon.icon(fileInfo))
             child = FileTreeItem(root)
             child.setText(0, i)
             child.setIcon(0, QtGui.QIcon(icon))
             child.setFilePath(path_new)
         elif path_new[-4:] == '.pdf':
             fileInfo = Qt.QFileInfo(path_new)
             fileIcon = Qt.QFileIconProvider()
             icon = QtGui.QIcon(fileIcon.icon(fileInfo))
             child = FileTreeItem(root)
             child.setText(0, i)
             child.setIcon(0, QtGui.QIcon(icon))
             child.setFilePath(path_new)
示例#8
0
文件: main2.py 项目: 2017ND/dl_detect
 def CreateTree(self, root):
     for file in self.path_dir:
         if file:
             fileInfo = Qt.QFileInfo(file)
             fileIcon = Qt.QFileIconProvider()
             icon = QtGui.QIcon(fileIcon.icon(fileInfo))
             child = QTreeWidgetItem()
             child.setText(0, file.split('/')[-1])
             child.setIcon(0, QtGui.QIcon(icon))
             root.addChild(child)
示例#9
0
    def Open_Folder(self):
        print('clicked.')
        path = QFileDialog.getExistingDirectory(self, "选取文件夹", Settings.GlobalPath)
        if path == '':
            return
        self.tree.clear()
        dirs = file_name(path)

        file_info = Qt.QFileInfo(path)
        file_icon = Qt.QFileIconProvider()
        icon = QtGui.QIcon(file_icon.icon(file_info))
        root = FileTreeItem(self.tree)
        root.setText(0, path.split('/')[-1])
        root.setIcon(0, QtGui.QIcon(icon))
        self.CreateTree(dirs, root, path)
        QApplication.processEvents()
        self.PathSelected.emit(path)
示例#10
0
 def __init__(self, parent=None, path='../ICTFE'):
     super(FileTree, self).__init__(parent)
     self.setupUi(self)
     self.setWindowTitle("File_Tree")
     try:
         dirs = file_name(path)
     except:
         dirs = os.path.abspath('.')
     file_info = Qt.QFileInfo(path)
     file_icon = Qt.QFileIconProvider()
     icon = QtGui.QIcon(file_icon.icon(file_info))
     root = FileTreeItem(self.tree)
     root.setText(0, path.split('/')[-1])
     root.setIcon(0, QtGui.QIcon(icon))
     self.CreateTree(dirs, root, path)
     self.actionFileOpen.clicked.connect(self.Open_Folder)
     QApplication.processEvents()
     self.tree.doubleClicked.connect(
         lambda x: self.EmitFilePath(self.tree.itemFromIndex(x)))
示例#11
0
    def Open_Folder(self):
        #path = read_line(configure_file,1)
        #path = QFileDialog.getExistingDirectory(self, "选取文件夹", "./")
        path = 'D:/codes/python/Eve_ide'
        self.tree = QTreeWidget()
        self.tree.setColumnCount(1)
        self.tree.setColumnWidth(0, 50)
        #self.tree.setHeaderLabels(["EXPLORER"])
        self.tree.setIconSize(Qt.QSize(25, 25))
        self.tree.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.actionfileopen.triggered.connect(self.Open_Folder)

        dirs = file_name(path)

        fileInfo = Qt.QFileInfo(path)
        fileIcon = Qt.QFileIconProvider()
        icon = QtGui.QIcon(fileIcon.icon(fileInfo))
        root = QTreeWidgetItem(self.tree)
        root.setText(0, path.split('/')[-1])
        root.setIcon(0, QtGui.QIcon(icon))
        self.CreateTree(dirs, root, path)
        self.setCentralWidget(self.tree)
        QApplication.processEvents()