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()
def openFile(self, near = None): fileDialog = Q.QFileDialog(self) fileDialog.setAcceptMode(Q.QFileDialog.AcceptOpen) fileDialog.setFileMode(Q.QFileDialog.ExistingFiles) fileDialog.setFilter(Q.QDir.Hidden|Q.QDir.AllEntries|Q.QDir.System) fileDialog.setViewMode(Q.QFileDialog.Detail) if near is not None: if isinstance(near,str): near = Q.QFileInfo(near) if isinstance(near,Q.QFileInfo): if near.isDir(): near = Q.QDir(near.filePath()) else: near = near.dir() if not isinstance(near,Q.QDir): near = Q.QDir.home() fileDialog.setDirectory(near.canonicalPath()) if fileDialog.exec(): if fileDialog.selectedFiles(): if not self.player: # return self.player = self._parent.getPlayerAt(-1) for filePath in fileDialog.selectedFiles(): print("\n"+filePath+"\n") self.player.command("loadfile",str(filePath),"append-play") w = self.player.widget if w:w.sized_once = False
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()
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])
def on_load(self): image_filters = "Images (*.jpg *.jpeg *.png *.bmp)" file_name = Qt.QFileDialog.getOpenFileName(self, "Load image", self.last_load_path, image_filters)[0] if not file_name: return self.last_load_path = Qt.QFileInfo(file_name).absolutePath() # Load image as bytes with open(file_name, 'rb') as f: img_data = f.read() nparr = np.frombuffer(img_data, np.uint8) self.image_source = cv2.imdecode(nparr, cv2.IMREAD_UNCHANGED) height, width, channels = self.image_source.shape self.setWindowTitle(WINDOW_TITLE + '. {}x{} ({} channels). {}'.format( width, height, channels, file_name)) # Трансформация BGR->RGB если 3 канала. У картинок с прозрачностью каналов 4 и для них почему if channels == 3: code = cv2.COLOR_BGR2RGB elif channels == 4: code = cv2.COLOR_BGRA2RGB else: raise Exception( 'Unexpected number of channels: {}'.format(channels)) self.image_source = cv2.cvtColor(self.image_source, code) self.refresh_HSV()
def getFileInfo(path): """获取文件的图片和名字""" fileInfo = Qt.QFileInfo(path) fileIcon = Qt.QFileIconProvider() icon = QtGui.QIcon(fileIcon.icon(fileInfo)) name = QtCore.QFileInfo(path).fileName() return icon, name
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])
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))
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)
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)
def load(self): image_filters = "Images (*.jpg *.jpeg *.png *.bmp)" self.file_name = Qt.QFileDialog.getOpenFileName(self, "Load image", self.last_load_path, image_filters)[0] if not self.file_name: return self.last_load_path = Qt.QFileInfo(self.file_name).absolutePath() self.image_source = Image.open(self.file_name).convert('RGB') self._do_pixelate()
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)
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)))
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()