当前位置: 首页>>代码示例>>Python>>正文


Python QFileDialog.getOpenFileName方法代码示例

本文整理汇总了Python中PyQt4.Qt.QFileDialog.getOpenFileName方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.getOpenFileName方法的具体用法?Python QFileDialog.getOpenFileName怎么用?Python QFileDialog.getOpenFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.Qt.QFileDialog的用法示例。


在下文中一共展示了QFileDialog.getOpenFileName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _open_FASTA_File

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
    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
开发者ID:alaindomissy,项目名称:nanoengineer,代码行数:36,代码来源:ProteinSequenceEditor.py

示例2: read_element_rgb_table

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
 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        
开发者ID:ematvey,项目名称:NanoEngineer-1,代码行数:36,代码来源:elementColors.py

示例3: openStrandSequenceFile

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
 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
开发者ID:elfion,项目名称:nanoengineer,代码行数:34,代码来源:DnaSequenceEditor.py

示例4: import_bookmarks

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
    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)
开发者ID:BobPyron,项目名称:calibre,代码行数:27,代码来源:bookmarkmanager.py

示例5: import_bookmarks

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
    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'])
开发者ID:089git,项目名称:calibre,代码行数:27,代码来源:bookmarkmanager.py

示例6: LoadAction

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
 def LoadAction(self):
     if not self.MainProgramm.DataSaved :
         msgbox = QMessageBox(QMessageBox.Question, "Frage", "Soll die vorherige Messung ueberschrieben werden ?", QMessageBox.No| QMessageBox.Yes)
         if not msgbox.exec_() == QMessageBox.Yes:
             return
     filename = QFileDialog.getOpenFileName(self,"Messung laden")
     if not filename == '':
         self.MainProgramm.LoadFile(filename)
     return
开发者ID:mbieker,项目名称:Schaukel,代码行数:11,代码来源:MainWindow.py

示例7: loadControl

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
    def loadControl(self):
        self.CfileName = QFileDialog.getOpenFileName(self,
                "Open Points File",
                "",
                "All Files (*);;Text Files (*.txt)", "")
        if self.CfileName:
#             self.lineEditPoints.setText(fileName)
            self.treeControl.clear()
            self.readControlFile(self.CfileName)
        self.updateControl.setVisible(True)
开发者ID:CraigNielsen,项目名称:LeastSquaresGui,代码行数:12,代码来源:main1.py

示例8: loadObs

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
    def loadObs(self):
        self.CalcProvisionals.setEnabled(True)
        fileName = QFileDialog.getOpenFileName(self,
                "Open Points File",
                "",
                "All Files (*);;Text Files (*.txt)", "")
        if fileName:
#             self.lineEditPoints.setText(fileName)
            self.treeObs.clear()
            self.readObsFile(fileName)
开发者ID:CraigNielsen,项目名称:LeastSquaresGui,代码行数:12,代码来源:main1.py

示例9: Open

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
 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'))
开发者ID:Dem0n3D,项目名称:variabledirection,代码行数:16,代码来源:main.py

示例10: resize

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
 def resize(self):
     # on a choisi de remplacer la couv, redimesionnement et sauvegarde de la nouvelle image
     newcouv = QFileDialog.getOpenFileName(None, "Sélectionnez la nouvelle couverture :",
                                           QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation),
                                           "Images (*.png *.gif *.jpg *.jpeg *.bmp)")
     if not newcouv:
         return self.suppr_comm()
     log('\t remplacement de la couverture')
     newimg = Image.open(newcouv)
     im = Image.open(self.monepub.imagedecouv)
     oldwidth, oldheight = im.size
     newimg = newimg.resize((oldwidth, oldheight))
     newimg.save(self.monepub.imagedecouv)
     self.ccouv.close()
     return tatoo.suppr_tatoo(self.monepub)
开发者ID:vdfebook,项目名称:PersonnaLiseur,代码行数:17,代码来源:job.py

示例11: stepSelect

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
    def stepSelect(self, phase = 0):
        if phase == 0:
            self.setWindowTitle(QString(u'Выбрать архив'))
            self.progressBar.setValue(30)
            self.emitStep(self.stepSelect, 1)
            return
        
#         print("archive")
        self.archiveName = QFileDialog.getOpenFileName(None, u"Выберите архив",
                                                    u"cps/updates",
                                                    'CNC.upd.tar.gz')
        if(self.archiveName == ""):
            print("archiveName is null, exit")
            app.closeAllWindows()
            
        print("open " + self.archiveName)
#         time.sleep(5)
        self.emitStep(self.stepUpload)
开发者ID:superkulpa,项目名称:phx-cnc-ui,代码行数:20,代码来源:update.py

示例12: get_sync_app_fs

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
    def get_sync_app_fs(self):
        '''
        Get path to selected sync_app
        '''
        self._log_location()
        sync_app = unicode(QFileDialog.getOpenFileName(
            self.gui,
            "Select sync app",
            os.path.expanduser("~"),
            "*.app").toUtf8())
        if sync_app:
            # Populate the filespec edit control
            self._log(sync_app)
            self.sync_app_path_le.setText(sync_app)

            # Populate the putative app name
            app_name = os.path.basename(sync_app)
            root_name = app_name.split('.')[0]
            self.app_name_le.setText(root_name)
开发者ID:GRiker,项目名称:calibre-syncman,代码行数:21,代码来源:sync_app_wizard.py

示例13: MainWidget

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]

#.........这里部分代码省略.........
                if idx < 3:
                    for i in range(idx, min(3, newLen)):
                        for j in range(2*i+1, 7):
                            self.ZMatModel.setItem(i, j, QStandardItem())
                            self.ZMatModel.item(i, j).setBackground(QColor(150,150,150))
                            self.ZMatModel.item(i, j).setFlags(Qt.ItemIsEnabled)
                if len(xyz) > idx:
                    xyz.pop(idx)
                    atoms.pop(idx)
            self.inp = xyz2zmat(xyz, atoms)
            self.populateZMatModel()
            for i in reversed(self.highList):
                self.window.removeItem(i[1])
            self.highList = []
            self.ZMatModel.dataChanged.connect(self.clearUpdateView)
        self.updateView()
        self.statusBar.clearMessage()
        if idxs:
            self.statusBar.showMessage('Deleted row(s): '+str([i+1 for i in idxs]), 3000)
        else:
            self.statusBar.showMessage('Deleted last row.', 3000)

    # show the periodic table widget
    def periodicTable(self):
        self.statusBar.clearMessage()
        self.statusBar.showMessage('Select element from periodic table.')
        self.periodicTableWidget.exec_()
        selection = self.periodicTableWidget.selection()
        return selection

    # import molecule with zmatrix coordinates
    def readZmat(self):
        self.ZMatModel.dataChanged.disconnect(self.clearUpdateView)
        filename = self.fileDialog.getOpenFileName(self, 'Open file', expanduser('~'), '*.zmat;;*.*')
        self.inp = []
        self.populateZMatModel()
        if filename:
            with open(filename, 'r') as f:
                next(f)
                next(f)
                for row in f:
                    self.inp.append(row.split())
                f.close()
            self.populateZMatModel()
        self.ZMatModel.dataChanged.connect(self.clearUpdateView)
        self.updateView()
        self.statusBar.clearMessage()
        self.statusBar.showMessage('Read molecule from '+filename+'.', 5000)
        self.showGaussAction.setEnabled(False)
        self.showFreqAction.setEnabled(False)

    # import molecule with xyz coordinates
    def readXYZ(self):
        self.ZMatModel.dataChanged.disconnect(self.clearUpdateView)
        filename = self.fileDialog.getOpenFileName(self, 'Open file', expanduser('~'), '*.xyz;;*.*')
        xyz = []
        elems = []
        self.inp = []
        self.populateZMatModel()
        if filename:
            with open(filename, 'r') as f:
                next(f)
                next(f)
                for row in f:
                    rs = row.split()
                    if len(rs) == 4:
开发者ID:shrx,项目名称:moldy,代码行数:70,代码来源:moldy.py

示例14: __init__

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
    def __init__(self, title=_('Choose Files'),
                       filters=[],
                       add_all_files_filter=True,
                       parent=None,
                       modal=True,
                       name='',
                       mode=QFileDialog.ExistingFiles,
                       default_dir=u'~',
                       no_save_dir=False,
                       combine_file_and_saved_dir=False
                       ):
        QObject.__init__(self)
        ftext = ''
        if filters:
            for filter in filters:
                text, extensions = filter
                extensions = ['*'+(i if i.startswith('.') else '.'+i) for i in
                        extensions]
                ftext += '%s (%s);;'%(text, ' '.join(extensions))
        if add_all_files_filter or not ftext:
            ftext += 'All files (*)'
        if ftext.endswith(';;'):
            ftext = ftext[:-2]

        self.dialog_name = name if name else 'dialog_' + title
        self.selected_files = None
        self.fd = None

        if combine_file_and_saved_dir:
            bn = os.path.basename(default_dir)
            prev = dynamic.get(self.dialog_name,
                    expanduser(u'~'))
            if os.path.exists(prev):
                if os.path.isfile(prev):
                    prev = os.path.dirname(prev)
            else:
                prev = expanduser(u'~')
            initial_dir = os.path.join(prev, bn)
        elif no_save_dir:
            initial_dir = expanduser(default_dir)
        else:
            initial_dir = dynamic.get(self.dialog_name,
                    expanduser(default_dir))
        if not isinstance(initial_dir, basestring):
            initial_dir = expanduser(default_dir)
        if not initial_dir or (not os.path.exists(initial_dir) and not (
                mode == QFileDialog.AnyFile and (no_save_dir or combine_file_and_saved_dir))):
            initial_dir = select_initial_dir(initial_dir)
        self.selected_files = []
        use_native_dialog = 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.environ
        with SanitizeLibraryPath():
            opts = QFileDialog.Option()
            if not use_native_dialog:
                opts |= QFileDialog.DontUseNativeDialog
            if mode == QFileDialog.AnyFile:
                f = unicode(QFileDialog.getSaveFileName(parent, title,
                    initial_dir, ftext, "", opts))
                if f:
                    self.selected_files.append(f)
            elif mode == QFileDialog.ExistingFile:
                f = unicode(QFileDialog.getOpenFileName(parent, title,
                    initial_dir, ftext, "", opts))
                if f and os.path.exists(f):
                    self.selected_files.append(f)
            elif mode == QFileDialog.ExistingFiles:
                fs = QFileDialog.getOpenFileNames(parent, title, initial_dir,
                        ftext, "", opts)
                for f in fs:
                    f = unicode(f)
                    if not f:
                        continue
                    if not os.path.exists(f):
                        # QFileDialog for some reason quotes spaces
                        # on linux if there is more than one space in a row
                        f = unquote(f)
                    if f and os.path.exists(f):
                        self.selected_files.append(f)
            else:
                if mode == QFileDialog.Directory:
                    opts |= QFileDialog.ShowDirsOnly
                f = unicode(QFileDialog.getExistingDirectory(parent, title, initial_dir, opts))
                if os.path.exists(f):
                    self.selected_files.append(f)
        if self.selected_files:
            self.selected_files = [unicode(q) for q in self.selected_files]
            saved_loc = self.selected_files[0]
            if os.path.isfile(saved_loc):
                saved_loc = os.path.dirname(saved_loc)
            if not no_save_dir:
                dynamic[self.dialog_name] = saved_loc
        self.accepted = bool(self.selected_files)
开发者ID:piewsook,项目名称:calibre,代码行数:93,代码来源:__init__.py

示例15: __init__

# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileName [as 别名]
    def __init__(
        self,
        title=_("Choose Files"),
        filters=[],
        add_all_files_filter=True,
        parent=None,
        modal=True,
        name="",
        mode=QFileDialog.ExistingFiles,
        default_dir="~",
        no_save_dir=False,
    ):
        QObject.__init__(self)
        ftext = ""
        if filters:
            for filter in filters:
                text, extensions = filter
                extensions = ["*" + (i if i.startswith(".") else "." + i) for i in extensions]
                ftext += "%s (%s);;" % (text, " ".join(extensions))
        if add_all_files_filter or not ftext:
            ftext += "All files (*)"
        if ftext.endswith(";;"):
            ftext = ftext[:-2]

        self.dialog_name = name if name else "dialog_" + title
        self.selected_files = None
        self.fd = None

        if no_save_dir:
            initial_dir = os.path.expanduser(default_dir)
        else:
            initial_dir = dynamic.get(self.dialog_name, os.path.expanduser(default_dir))
        if not isinstance(initial_dir, basestring):
            initial_dir = os.path.expanduser(default_dir)
        self.selected_files = []
        use_native_dialog = "CALIBRE_NO_NATIVE_FILEDIALOGS" not in os.environ
        with SanitizeLibraryPath():
            opts = QFileDialog.Option()
            if not use_native_dialog:
                opts |= QFileDialog.DontUseNativeDialog
            if mode == QFileDialog.AnyFile:
                f = unicode(QFileDialog.getSaveFileName(parent, title, initial_dir, ftext, "", opts))
                if f:
                    self.selected_files.append(f)
            elif mode == QFileDialog.ExistingFile:
                f = unicode(QFileDialog.getOpenFileName(parent, title, initial_dir, ftext, "", opts))
                if f and os.path.exists(f):
                    self.selected_files.append(f)
            elif mode == QFileDialog.ExistingFiles:
                fs = QFileDialog.getOpenFileNames(parent, title, initial_dir, ftext, "", opts)
                for f in fs:
                    f = unicode(f)
                    if not f:
                        continue
                    if not os.path.exists(f):
                        # QFileDialog for some reason quotes spaces
                        # on linux if there is more than one space in a row
                        f = unquote(f)
                    if f and os.path.exists(f):
                        self.selected_files.append(f)
            else:
                if mode == QFileDialog.Directory:
                    opts |= QFileDialog.ShowDirsOnly
                f = unicode(QFileDialog.getExistingDirectory(parent, title, initial_dir, opts))
                if os.path.exists(f):
                    self.selected_files.append(f)
        if self.selected_files:
            self.selected_files = [unicode(q) for q in self.selected_files]
            saved_loc = self.selected_files[0]
            if os.path.isfile(saved_loc):
                saved_loc = os.path.dirname(saved_loc)
            if not no_save_dir:
                dynamic[self.dialog_name] = saved_loc
        self.accepted = bool(self.selected_files)
开发者ID:randy1,项目名称:calibre,代码行数:76,代码来源:__init__.py


注:本文中的PyQt4.Qt.QFileDialog.getOpenFileName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。