本文整理汇总了Python中PyQt4.QtGui.QFileDialog.getOpenFileName方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.getOpenFileName方法的具体用法?Python QFileDialog.getOpenFileName怎么用?Python QFileDialog.getOpenFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QFileDialog
的用法示例。
在下文中一共展示了QFileDialog.getOpenFileName方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: openImportFileDialog
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def openImportFileDialog( self ):
bLayers = False
layers = QgsMapLayerRegistry.instance().mapLayers().values()
for layer in layers:
if layer.type() == QgsMapLayer.VectorLayer:
if layer.dataProvider().capabilities() & QgsVectorDataProvider.AddFeatures:
bLayers = True
break
if not bLayers:
self.messageManager.show( QApplication.translate( "ImportAutoFields",
"First load some vector layers to QGIS where you would like to import AutoFields to." ), 'warning' )
return
settings = QSettings()
path = QFileDialog.getOpenFileName( self.iface.mainWindow(), QApplication.translate( "ImportAutoFields", "Select a JSON file" ),
settings.value( self.autoFieldManager.settingsPrefix + "/import/dir", "", type=str ), "JSON files (*.json)" )
if path:
settings.setValue( self.autoFieldManager.settingsPrefix + "/import/dir", os.path.dirname( path ) )
listAutoFields = self.validateInputJSON( path )
# Now openImportDialog()
dlg = ImportAutoFieldsDialog( self.iface.mainWindow(), self.autoFieldManager, self.messageManager, listAutoFields, path, self.dockWidget.chkCalculateOnExisting.isChecked() )
dlg.show()
示例2: _selectFile
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def _selectFile(self, mode='export'):
settings = QSettings('Faunalia', 'landmark')
lastDir = settings.value('lastZipDir', '.')
if mode == 'export':
fileName = QFileDialog.getSaveFileName(
None, self.tr('Select file'), lastDir, self.tr('ZIP files (*.zip *.ZIP)'))
else:
fileName = QFileDialog.getOpenFileName(
None, self.tr('Select file'), lastDir, self.tr('ZIP files (*.zip *.ZIP)'))
if fileName == '':
return None
if not fileName.lower().endswith('.zip'):
fileName += '.zip'
settings.setValue(
'lastZipDir', QFileInfo(fileName).absoluteDir().absolutePath())
return fileName
示例3: select_load_file
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def select_load_file(self):
"""[email protected] Select file to load in the field"""
sender=self.sender()
fileName = QFileDialog.getOpenFileName(self.dlg, "Select your file","")
if not fileName:
return
if sender == self.dlg.selectModelStep3:
self.dlg.inModel.setText(fileName)
示例4: setInDataset
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def setInDataset(self):
inName = QFileDialog.getOpenFileName(None,
'Select input dataset',
'',
"raster or vector (*.shp *.tif)",
)
if inName:
self.inDataset = QFileInfo(inName).absoluteFilePath()
self.dlg.inDataset.setText(QFileInfo(inName).absoluteFilePath())
示例5: OpenFileDialog
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def OpenFileDialog(self, title):
self.filename, _ = getOpenFileName(self,
title,
g.config.vars.Paths['import_dir'],
self.tr("All supported files (*.dxf *.ps *.pdf *%s);;"
"DXF files (*.dxf);;"
"PS files (*.ps);;"
"PDF files (*.pdf);;"
"Project files (*%s);;"
"All types (*.*)") % (c.PROJECT_EXTENSION, c.PROJECT_EXTENSION))
# If there is something to load then call the load function callback
if self.filename:
self.filename = file_str(self.filename)
logger.info(self.tr("File: %s selected") % self.filename)
示例6: getOpenFileName
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def getOpenFileName(ext="ini"):
"""
Open a filedialog where you must choose a file
:param ext: the extension of your file
:return: The selected file
"""
return QFileDialog.getOpenFileName(None, "Open File", str(expanduser("~")), "Extension file (*.{0})".format(ext))
示例7: browse
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def browse(self):
"""Display a FileDialog and select files"""
if self.displayAdvancedSettings:
filePathList = QFileDialog.getOpenFileNames(
self,
u'Select Text File(s)',
self.lastLocation,
u'Text files (*)'
)
if not filePathList:
return
filePathList = [os.path.normpath(f) for f in filePathList]
self.newFiles = u' / '.join(filePathList)
self.lastLocation = os.path.dirname(filePathList[-1])
self.updateGUI()
else:
filePath = QFileDialog.getOpenFileName(
self,
u'Open Text File',
self.lastLocation,
u'Text files (*)'
)
if not filePath:
return
self.file = os.path.normpath(filePath)
self.lastLocation = os.path.dirname(filePath)
self.updateGUI()
self.sendButton.settingsChanged()
示例8: openLogoPathSelector
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def openLogoPathSelector(self):
filename = QFileDialog.getOpenFileName(self, "Open File", "", "Image Files (*.png)" )
if filename:
self.logoPath.setText(filename)
示例9: addPhoto
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def addPhoto(self):
if self.landmarkId is not None:
settings = QSettings('MatsueGkukan', 'Gkukandb')
lastDir = settings.value('lastPhotoDir', '.')
fileName = QFileDialog.getOpenFileName(
self, self.tr('Select photo'), lastDir, self._createFilter())
if fileName == '':
return
settings.setValue('lastPhotoDir', QFileInfo(fileName).absoluteDir().absolutePath())
projectPath =self.GetPhotoFolderPath()+os.sep
photoPath = os.path.basename(fileName)
photoDate = self._photoDate(fileName).toString('yyyy-MM-dd')
if not self.openDatabase():
return
self.query.prepare('INSERT INTO t_photo("cdate", "filename", "landmark_id",lon,lat,angle,geomtype,geom) VALUES(?, ?, ?,?,?,?,?,?);')
self.query.addBindValue(photoDate)
self.query.addBindValue(photoPath)
self.query.addBindValue(self.landmarkId)
self.query.addBindValue(0)
self.query.addBindValue(0)
self.query.addBindValue(0)
self.query.addBindValue(0)
self.query.addBindValue('010100000000000000000000000000000000000000')
if self.query.exec_():
self._copyPhotoToFolder(fileName,self.landmarkId)
self.populatePhotos(-1)
else:
a= self.query.lastError().text()
self.db.close()
else:
self.landmarkMessage.emit(self.tr('Select landmark before adding a photo.'), QgsMessageBar.WARNING)
示例10: importList
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def importList(self):
"""Display a FileDialog and import file list"""
filePath = QFileDialog.getOpenFileName(
self,
u'Import File List',
self.lastLocation,
u'Text files (*)'
)
if not filePath:
return
self.file = os.path.normpath(filePath)
self.lastLocation = os.path.dirname(filePath)
self.error()
try:
fileHandle = codecs.open(filePath, encoding='utf8')
fileContent = fileHandle.read()
fileHandle.close()
except IOError:
QMessageBox.warning(
None,
'Textable',
"Couldn't open file.",
QMessageBox.Ok
)
return
try:
json_data = json.loads(fileContent)
temp_files = list()
for entry in json_data:
path = entry.get('path', '')
encoding = entry.get('encoding', '')
annotationKey = entry.get('annotation_key', '')
annotationValue = entry.get('annotation_value', '')
if path == '' or encoding == '':
QMessageBox.warning(
None,
'Textable',
"Selected JSON file doesn't have the right keys "
"and/or values.",
QMessageBox.Ok
)
return
temp_files.append((
path,
encoding,
annotationKey,
annotationValue,
))
self.files.extend(temp_files)
if temp_files:
self.sendButton.settingsChanged()
except ValueError:
QMessageBox.warning(
None,
'Textable',
"JSON parsing error.",
QMessageBox.Ok
)
return
示例11: importList
# 需要导入模块: from PyQt4.QtGui import QFileDialog [as 别名]
# 或者: from PyQt4.QtGui.QFileDialog import getOpenFileName [as 别名]
def importList(self):
"""Display a FileDialog and import URL list"""
filePath = QFileDialog.getOpenFileName(
self,
u'Import URL List',
self.lastLocation,
u'Text files (*)'
)
if not filePath:
return
self.file = os.path.normpath(filePath)
self.lastLocation = os.path.dirname(filePath)
self.error()
try:
fileHandle = codecs.open(filePath, encoding='utf8')
fileContent = fileHandle.read()
fileHandle.close()
except IOError:
QMessageBox.warning(
None,
'Textable',
"Couldn't open file.",
QMessageBox.Ok
)
return
try:
json_data = json.loads(fileContent)
temp_URLs = list()
for entry in json_data:
URL = entry.get('url', '')
encoding = entry.get('encoding', '')
annotationKey = entry.get('annotation_key', '')
annotationValue = entry.get('annotation_value', '')
if URL == '' or encoding == '':
QMessageBox.warning(
None,
'Textable',
"Selected JSON file doesn't have the right keys "
"and/or values.",
QMessageBox.Ok
)
return
temp_URLs.append((
URL,
encoding,
annotationKey,
annotationValue,
))
self.URLs.extend(temp_URLs)
if temp_URLs:
self.sendButton.settingsChanged()
except ValueError:
QMessageBox.warning(
None,
'Textable',
"Selected file is not in JSON format.",
QMessageBox.Ok
)
return