本文整理汇总了Python中PyQt4.Qt.QFileDialog类的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog类的具体用法?Python QFileDialog怎么用?Python QFileDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QFileDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select_images_on_disk
def select_images_on_disk(uim, start_path=None):
dlg = QFileDialog()
logmsg('Select one or more images to add.')
image_list = dlg.getOpenFileNames(caption='Select one or more images to add.',\
directory=uim.hs.db_dpath)
image_list = [str(fpath) for fpath in image_list]
return image_list
示例2: select_database
def select_database(uim):
dlg = QFileDialog()
opt = QFileDialog.ShowDirsOnly
if uim.hs.db_dpath is None:
db_dpath = str(dlg.getExistingDirectory(caption='Open/New Database', options=opt))
else:
db_dpath = str(dlg.getExistingDirectory(\
caption='Open/New Database', options=opt, directory=uim.hs.db_dpath))
return db_dpath
示例3: Save
def Save(self):
d = QFileDialog(self)
s = d.getSaveFileName()
l = len(self.mt.Images)
for i in xrange(l):
self.mt.Images[i].save(s+'.'+str(i)+'.png')
f = open(s,"w")
f.write(str(l))
f.close()
示例4: Open
def Open(self):
d = QFileDialog(self)
s = d.getOpenFileName()
self.mt.exit = True
f = open(s,"r")
l = int(f.readline())
f.close()
self.mt.Images = []
for i in xrange(l):
self.mt.Images.append(QImage(s+'.'+str(i)+'.png'))
示例5: start_download
def start_download(self, request):
if not self.gui:
return
url = unicode(request.url().toString())
cf = self.get_cookies()
filename = get_download_filename(url, cf)
ext = os.path.splitext(filename)[1][1:].lower()
filename = ascii_filename(filename[:60] + '.' + ext)
if ext not in BOOK_EXTENSIONS:
if ext == 'acsm':
from calibre.gui2.dialogs.confirm_delete import confirm
if not confirm('<p>' + _('This ebook is a DRMed EPUB file. '
'You will be prompted to save this file to your '
'computer. Once it is saved, open it with '
'<a href="http://www.adobe.com/products/digitaleditions/">'
'Adobe Digital Editions</a> (ADE).<p>ADE, in turn '
'will download the actual ebook, which will be a '
'.epub file. You can add this book to calibre '
'using "Add Books" and selecting the file from '
'the ADE library folder.'),
'acsm_download', self):
return
home = os.path.expanduser('~')
name = QFileDialog.getSaveFileName(self,
_('File is not a supported ebook type. Save to disk?'),
os.path.join(home, filename),
'*.*')
if name:
name = unicode(name)
self.gui.download_ebook(url, cf, name, name, False)
else:
self.gui.download_ebook(url, cf, filename, tags=self.tags)
示例6: openStrandSequenceFile
def openStrandSequenceFile(self):
"""
Open (read) the user specified Strand sequence file and enter the
sequence in the Strand sequence Text edit. Note that it ONLY reads the
FIRST line of the file.
@TODO: It only reads in the first line of the file. Also, it doesn't
handle any special cases. (Once the special cases are clearly
defined, that functionality will be added.
"""
if self.parentWidget.assy.filename:
odir = os.path.dirname(self.parentWidget.assy.filename)
else:
odir = env.prefs[workingDirectory_prefs_key]
self.sequenceFileName = \
str(QFileDialog.getOpenFileName(
self,
"Load Strand Sequence",
odir,
"Strand Sequnce file (*.txt);;All Files (*.*);;"))
lines = self.sequenceFileName
try:
lines = open(self.sequenceFileName, "rU").readlines()
except:
print "Exception occurred to open file: ", self.sequenceFileName
return
sequence = lines[0]
sequence = QString(sequence)
sequence = sequence.toUpper()
self._updateSequenceAndItsComplement(sequence)
return
示例7: import_bookmarks
def import_bookmarks(self):
filename = QFileDialog.getOpenFileName(self, _("Import Bookmarks"), '%s' % os.getcwdu(), _("Pickled Bookmarks (*.pickle)"))
if filename == '':
return
imported = None
with open(filename, 'r') as fileobj:
imported = cPickle.load(fileobj)
if imported != None:
bad = False
try:
for bm in imported:
if len(bm) != 2:
bad = True
break
except:
pass
if not bad:
bookmarks = self._model.bookmarks[:]
for bm in imported:
if bm not in bookmarks and bm['title'] != 'calibre_current_page_bookmark':
bookmarks.append(bm)
self.set_bookmarks(bookmarks)
示例8: _open_FASTA_File
def _open_FASTA_File(self):
"""
Open (read) the user specified FASTA sequence file and load it into
the sequence field.
@TODO: It only reads in the first line of the file. Also, it doesn't
handle any special cases. (Once the special cases are clearly
defined, that functionality will be added.
@attention: This is not implemented yet.
"""
#Urmi 20080714: should not this be only fasta file, for both load and save
if self.parentWidget.assy.filename:
odir = os.path.dirname(self.parentWidget.assy.filename)
else:
odir = env.prefs[workingDirectory_prefs_key]
self.sequenceFileName = \
str(QFileDialog.getOpenFileName(
self,
"Load FASTA sequence for " + self.current_protein.name,
odir,
"FASTA file (*.txt);;All Files (*.*);;"))
lines = self.sequenceFileName
try:
lines = open(self.sequenceFileName, "rU").readlines()
except:
print "Exception occurred to open file: ", self.sequenceFileName
return
sequence = lines[0]
sequence = QString(sequence)
sequence = sequence.toUpper()
self._setSequence(sequence)
return
示例9: saveFavorite
def saveFavorite(self):
"""
Writes the current favorite (selected in the combobox) to a file, any
where in the disk that
can be given to another NE1 user (i.e. as an email attachment).
"""
cmd = greenmsg("Save Favorite File: ")
env.history.message(greenmsg("Save Favorite File:"))
current_favorite = self.favoritesComboBox.currentText()
favfilepath = getFavoritePathFromBasename(current_favorite)
formats = \
"Favorite (*.txt);;"\
"All Files (*.*)"
fn = QFileDialog.getSaveFileName(
self,
"Save Favorite As", # caption
favfilepath, #where to save
formats, # file format options
QString("Favorite (*.txt)") # selectedFilter
)
if not fn:
env.history.message(cmd + "Cancelled")
else:
saveFavoriteFile(str(fn), favfilepath)
return
示例10: read_element_rgb_table
def read_element_rgb_table(self):
"""
Open file browser to select a file to read from, read the data,
update elements color in the selector dialog and also the display models
"""
# Determine what directory to open.
import os
if self.w.assy.filename:
odir = os.path.dirname(self.w.assy.filename)
else:
from utilities.prefs_constants import workingDirectory_prefs_key
odir = env.prefs[workingDirectory_prefs_key]
self.fileName = str( QFileDialog.getOpenFileName(
self,
"Load Element Color",
odir,
"Elements color file (*.txt);;All Files (*.*);;"
))
if self.fileName:
colorTable = readElementColors(self.fileName)
if not colorTable:
env.history.message(redmsg("Error in element colors file: [" + self.fileName + "]. Colors not loaded."))
else:
env.history.message("Element colors loaded from file: [" + self.fileName + "].")
for row in colorTable:
row[1] /= 255.0; row[2] /= 255.0; row[3] /= 255.0
self.elemTable.setElemColors(colorTable)
self._updateModelDisplay()
elemNum = self.elementButtonGroup.checkedId()
self.setDisplay(elemNum)
#After loading a file, reset the flag
self.isElementModified = False
示例11: rezip_epub2
def rezip_epub2(self, epub, titre_dialogue="Enregistrer l'epub détatoué sous :"):
self.setLabelText('Reconstruction de l\'epub')
QtGui.QApplication.processEvents()
# choix du nom de l'epub
epub2 = QFileDialog.getSaveFileName(None, titre_dialogue, epub, 'epub(*.epub)')
if zipfile.is_zipfile(epub):
try:
zepub = zipfile.ZipFile(epub2, mode="w",
compression=zipfile.ZIP_DEFLATED, allowZip64=True)
# d'abord le mimetype non compressé.
zepub.write(os.path.join(self.dirtemp.name, "mimetype"), arcname="mimetype",
compress_type=zipfile.ZIP_STORED)
# puis les autres fichiers
exclude_files = ['.DS_Store', 'mimetype']
for root, _dirs, files in os.walk(self.dirtemp.name):
for fn in files:
if fn in exclude_files:
continue
absfn = os.path.join(root, fn)
zfn = os.path.relpath(absfn, self.dirtemp.name).replace(os.sep, '/')
zepub.write(absfn, zfn)
zepub.close()
except:
log('Impossible de rezipper cet epub.')
return
示例12: import_bookmarks
def import_bookmarks(self):
filename = QFileDialog.getOpenFileName(self, _("Import Bookmarks"), '%s' % os.getcwdu(), _("Pickled Bookmarks (*.pickle)"))
if not filename:
return
imported = None
with open(filename, 'r') as fileobj:
imported = cPickle.load(fileobj)
if imported is not None:
bad = False
try:
for bm in imported:
if 'title' not in bm:
bad = True
break
except:
pass
if not bad:
bookmarks = self.get_bookmarks()
for bm in imported:
if bm not in bookmarks:
bookmarks.append(bm)
self.set_bookmarks([bm for bm in bookmarks if bm['title'] != 'calibre_current_page_bookmark'])
示例13: selectDirectory
def selectDirectory(self):
directory = QFileDialog.getExistingDirectory(QFileDialog())
if len(directory) > 0:
directory = pathlib.Path(directory).resolve()
if directory.exists():
self._rddtDataExtractor.defaultPath = directory
self.directoryBox.setText(str(directory))
self.setUnsavedChanges(True)
示例14: saveToFile
def saveToFile(self):
fdiag = QFileDialog()
selectedFilter = QString()
if foundPandas:
filt = self.tr("Excel Open XML Document (*.xlsx);;Portable Network Graphics (*.png)")
else:
filt = self.tr("Portable Network Graphics (*.png)")
fileName = fdiag.getSaveFileName(self, self.tr("Save Data As"),
datetime.now().strftime('%Y-%m-%d-T%H%M%S-') + self.modeAscii,
filt, selectedFilter)
if len(fileName) == 0:
return
if 'png' in selectedFilter:
if fileName[-4:] == '.png':
fileName = fileName[0:-4]
px = QPixmap.grabWidget(self.graphGrp)
px.save(fileName + '.png', "PNG")
return
if fileName[-5:] == '.xlsx':
fileName = fileName[0:-5]
data = self.excelData.getData()
if len(data) == 0:
mb = QMessageBox()
mb.setIcon(QMessageBox.Warning)
mb.setWindowTitle(self.tr('Warning'))
mb.setText(self.tr('No data exists. No output file has been produced.'))
mb.exec_()
return
if data.ndim == 1: #Bad workaround if only one line exists
add = []
for idx in range(0,len(data)):
add.append(0)
data = np.vstack((data, np.array(add)))
df = pandas.DataFrame(data, columns=['Frequency', self.modeTuple[0], self.modeTuple[1]])
df.to_excel(str(fileName) + '.xlsx', index=False)
示例15: export_bookmarks
def export_bookmarks(self):
filename = QFileDialog.getSaveFileName(self, _("Export Bookmarks"),
'%s%suntitled.pickle' % (os.getcwdu(), os.sep),
_("Saved Bookmarks (*.pickle)"))
if not filename:
return
with open(filename, 'w') as fileobj:
cPickle.dump(self.get_bookmarks(), fileobj)