本文整理汇总了Python中PyQt5.QtCore.QFileInfo.baseName方法的典型用法代码示例。如果您正苦于以下问题:Python QFileInfo.baseName方法的具体用法?Python QFileInfo.baseName怎么用?Python QFileInfo.baseName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QFileInfo
的用法示例。
在下文中一共展示了QFileInfo.baseName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveImage
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import baseName [as 别名]
def saveImage(self):
""" Provides a dialog window to allow the user to save the image file.
"""
imageFile, _ = QFileDialog.getSaveFileName(self,
"Choose a filename to save the image", "", "Images (*.png)")
info = QFileInfo(imageFile)
if info.baseName() != '':
newImageFile = QFileInfo(info.absoluteDir(),
info.baseName() + '.png').absoluteFilePath()
if not self.finalWidget.pixmap().save(newImageFile, 'PNG'):
QMessageBox.warning(self, "Cannot save file",
"The file could not be saved.",
QMessageBox.Cancel, QMessageBox.NoButton,
QMessageBox.NoButton)
else:
QMessageBox.warning(self, "Cannot save file",
"Please enter a valid filename.", QMessageBox.Cancel,
QMessageBox.NoButton, QMessageBox.NoButton)
示例2: browsePath
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import baseName [as 别名]
def browsePath(self):
"""用户点击了浏览路径的按钮。如果成功设置了路径,就返回True,如果用户取消了操作或者出错,就返回False
返回的用途参见showEvent()"""
filename, selectedFilter = QFileDialog.getOpenFileName(self, self.windowTitle())
if not filename:
return False
fi = QFileInfo(filename)
if fi.isSymLink():
filename = fi.symLinkTarget()
if not os.path.exists(filename):
QMessageBox.information(self, self.windowTitle(), self.tr("快捷方式所指向的程序不正确。"))
return False
fi = QFileInfo(filename)
self.txtName.setText(fi.baseName())
self.txtPath.setText(fi.absoluteFilePath())
self.setFileIcon(fi.absoluteFilePath())
self.txtDir.setText(fi.dir().absolutePath())
return True
示例3: replaceImage
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import baseName [as 别名]
def replaceImage(self, filepath, title):
self.title = title
self.filepath = filepath
# set custom properties
self.setCustomProperty("title", title)
self.setCustomProperty("filepath", self.filepath)
self.setName(title)
fileInfo = QFileInfo(filepath)
ext = fileInfo.suffix()
if ext == "pdf":
s = QSettings()
oldValidation = s.value("/Projections/defaultBehavior")
s.setValue("/Projections/defaultBehavior", "useGlobal") # for not asking about crs
path = fileInfo.filePath()
baseName = fileInfo.baseName()
layer = QgsRasterLayer(path, baseName)
self.image = layer.previewAsImage(QSize(layer.width(), layer.height()))
s.setValue("/Projections/defaultBehavior", oldValidation)
else:
reader = QImageReader(filepath)
self.image = reader.read()
self.repaint()
示例4: initializeLayer
# 需要导入模块: from PyQt5.QtCore import QFileInfo [as 别名]
# 或者: from PyQt5.QtCore.QFileInfo import baseName [as 别名]
def initializeLayer(self, screenExtent=None):
if self.error or self.initialized or self.initializing:
return
if self.filepath is not None:
# not safe...
self.initializing = True
filepath = self.getAbsoluteFilepath()
if not os.path.exists(filepath):
# TODO integrate with BadLayerHandler ?
loadErrorDialog = LoadErrorDialog(filepath)
result = loadErrorDialog.exec_()
if result == 1:
# absolute
filepath = loadErrorDialog.lineEditImagePath.text()
# to relative if needed
self.filepath = utils.toRelativeToQGS(filepath)
self.setCustomProperty("filepath", self.filepath)
QgsProject.instance().setDirty(True)
else:
self.error = True
del loadErrorDialog
fileInfo = QFileInfo(filepath)
ext = fileInfo.suffix()
if ext == "pdf":
s = QSettings()
oldValidation = s.value("/Projections/defaultBehavior")
s.setValue("/Projections/defaultBehavior", "useGlobal") # for not asking about crs
path = fileInfo.filePath()
baseName = fileInfo.baseName()
layer = QgsRasterLayer(path, baseName)
self.image = layer.previewAsImage(QSize(layer.width(),layer.height()))
s.setValue("/Projections/defaultBehavior", oldValidation)
else:
reader = QImageReader(filepath)
self.image = reader.read()
self.initialized = True
self.initializing = False
self.setupCrs()
if screenExtent:
# constructor called from AddLayer action
# if not, layer loaded from QGS project file
# check if image already has georef info
# use GDAL
dataset = gdal.Open(filepath, gdal.GA_ReadOnly)
georef = None
if dataset:
georef = dataset.GetGeoTransform()
if georef and not self.is_default_geotransform(georef):
self.initializeExistingGeoreferencing(dataset, georef)
else:
# init to default params
self.setCenter(screenExtent.center())
self.setRotation(0.0)
sw = screenExtent.width()
sh = screenExtent.height()
self.resetScale(sw, sh)
self.commitTransformParameters()