本文整理汇总了Python中PyQt5.QtWidgets.QFileSystemModel.fileInfo方法的典型用法代码示例。如果您正苦于以下问题:Python QFileSystemModel.fileInfo方法的具体用法?Python QFileSystemModel.fileInfo怎么用?Python QFileSystemModel.fileInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QFileSystemModel
的用法示例。
在下文中一共展示了QFileSystemModel.fileInfo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AssetBrowser
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import fileInfo [as 别名]
class AssetBrowser(QMainWindow, Ui_MainWindow):
asset_clicked = pyqtSignal(str, str, name='assetClicked')
def __init__(self):
super(AssetBrowser, self).__init__()
self.setupUi(self)
self.dir_model = QFileSystemModel()
self.dir_model.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
self.dir_model.setReadOnly(False)
self.dir_view.setModel(self.dir_model)
self.dir_view.hideColumn(1)
self.dir_view.hideColumn(2)
self.dir_view.hideColumn(3)
self.file_model = QFileSystemModel()
self.file_model.setFilter(QDir.NoDotAndDotDot | QDir.Files)
self.file_model.setReadOnly(False)
self.file_view.setModel(self.file_model)
def open_project(self, project_dir):
path = os.path.join(project_dir)
self.dir_model.setRootPath(path)
self.file_model.setRootPath(path)
self.dir_view.setRootIndex(self.dir_model.index(path))
self.file_view.setRootIndex(self.file_model.index(path))
def dir_clicked(self, idx):
path = self.dir_model.fileInfo(idx).absoluteFilePath()
self.file_view.setRootIndex(self.file_model.setRootPath(path))
def file_doubleclicked(self, idx):
fileinfo = self.file_model.fileInfo(idx)
path = fileinfo.absoluteFilePath()
ext = fileinfo.suffix()
self.asset_clicked.emit(path, ext)
示例2: AssetBrowser
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import fileInfo [as 别名]
class AssetBrowser(QMainWindow, Ui_MainWindow, PlaygroundModule):
Name = "asset_browser"
def __init__(self, module_manager):
super(AssetBrowser, self).__init__()
self.setupUi(self)
self.init_module(module_manager)
self.dir_model = QFileSystemModel()
self.dir_model.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
self.dir_model.setReadOnly(False)
self.dir_view.setModel(self.dir_model)
self.dir_view.hideColumn(1)
self.dir_view.hideColumn(2)
self.dir_view.hideColumn(3)
self.file_model = QFileSystemModel()
self.file_model.setFilter(QDir.NoDotAndDotDot | QDir.Files)
self.file_model.setReadOnly(False)
self.file_view.setModel(self.file_model)
self.dock = self.modules_manager.new_docked(self, self.Name, "Asset browser",
Qt.BottomDockWidgetArea)
self.modules_manager.main_window.splitDockWidget(self.dock,
self.modules_manager["asset_view"].dock, Qt.Horizontal)
def on_open_project(self, project):
project_dir = project.project_dir
path = os.path.join(project_dir)
self.dir_model.setRootPath(path)
self.file_model.setRootPath(path)
self.dir_view.setRootIndex(self.dir_model.index(path))
self.file_view.setRootIndex(self.file_model.index(path))
def dir_clicked(self, idx):
path = self.dir_model.fileInfo(idx).absoluteFilePath()
self.file_view.setRootIndex(self.file_model.setRootPath(path))
def file_doubleclicked(self, idx):
fileinfo = self.file_model.fileInfo(idx)
path = fileinfo.absoluteFilePath()
ext = fileinfo.suffix()
asset_name = path.replace(self.project_manager.project_dir, '').replace('/src/', '').split('.')[0]
self.modules_manager.open_asset(path, asset_name, ext)
def file_clicked(self, idx):
fileinfo = self.file_model.fileInfo(idx)
path = fileinfo.absoluteFilePath()
ext = fileinfo.suffix()
asset_name = path.replace(self.project_manager.project_dir, '').replace('/src/', '').split('.')[0]
self.modules_manager.show_asset(path, asset_name, ext)
示例3: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QFileSystemModel [as 别名]
# 或者: from PyQt5.QtWidgets.QFileSystemModel import fileInfo [as 别名]
#.........这里部分代码省略.........
widget.show()
else:
widget.removeTab(
widget.indexOf(tab))
if widget.count() == 0:
widget.hide()
def addjustBrowserWidth(self):
w = self.ui.tabWidgetBrowser.count() * 80
self.ui.splitterInner.setSizes([w, self.ui.splitterInner.width() - w])
@pyqtSlot(bool)
def openFile(self, checked=True, path=None):
"""
Open a new file.
If current editor is associated with a file or its content is not null,
Then create a new editor tab
:return:
"""
path = QFileDialog.getOpenFileName()[0] if not path else path
if len(path) != 0:
qfile = QFile(path)
if not qfile.open(QFile.ReadOnly or QFile.Text):
QMessageBox.warning(self, 'Application',
'Cannot read file %s:\n%s.' % (path, qfile.errorString()))
return
with open(path, 'r') as _file:
content = _file.read()
if self.currentEditor.file or len(self.currentEditor.document().toPlainText()) > 0:
self.createEditorTab()
# associate file on disk with editor
self.currentEditor.file = path
# update tab name
index = self.ui.tabWidgetEditor.indexOf(self.currentEditorTab)
_translate = QCoreApplication.translate
self.ui.tabWidgetEditor.setTabText(
index, _translate("MainWindow", ntpath.basename(path)))
self.ui.tabWidgetEditor.setCurrentIndex(index)
self.currentEditor.setPlainText(content)
@pyqtSlot(int)
def openFileFromTree(self, index):
f = self.fileTreeModel.fileInfo(index)
if f.isFile():
self.openFile(path=f.filePath())
@pyqtSlot(bool)
def newFile(self, checked):
"""
create a new editor tab
:param action:
:return:
"""
self.createEditorTab()
index = self.ui.tabWidgetEditor.indexOf(self.currentEditorTab)
_translate = QCoreApplication.translate
self.ui.tabWidgetEditor.setTabText(
index, _translate("MainWindow", 'New File'))
self.ui.tabWidgetEditor.setCurrentIndex(index)
@pyqtSlot(bool)
def saveFile(self, checked=None):
"""
Save file.
If current editor is associated with a file on the disk,
then save it. Or save file as...
:param checked:
:return: Saved or canceled
"""
if self.currentEditor.file:
if self.currentEditor.document().isModified():
with open(self.currentEditor.file, 'w') as f:
f.write(self.currentEditor.document().toPlainText())
self.currentEditor.document().setModified(False)
return True
else:
return self.saveFileAs()
@pyqtSlot(bool)
def saveFileAs(self, checked=None):
"""
Save File As...
:param checked:
:return: If saved or canceled
"""
dialog = QFileDialog()
dialog.setWindowModality(Qt.WindowModal)
dialog.setAcceptMode(QFileDialog.AcceptSave)
if dialog.exec_():
filepath = dialog.selectedFiles()[0]
with open(filepath, 'w') as f:
f.write(self.currentEditor.document().toPlainText())
self.currentEditor.document().setModified(False)
self.currentEditor.file = filepath
return True
else:
return False