python类askopenfilenames()的实例源码

spe2fitsGUI.py 文件源码 项目:spe2fits 作者: jerryjiahaha 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def chooseDialogFiles(self):
        filenames = filedialog.askopenfilenames(
                defaultextension = '.SPE',
                filetypes = [('WinViewer Documents', '.SPE'), ('all files', '.*'),],
                parent = self,
                title = "Select .SPE files",
                multiple = True,
                )
        print(filenames)
        if len(filenames) == 0:
            return
        self.chooseFilePath = os.path.dirname(
                os.path.realpath(filenames[0])
                )
        print("select:", self.chooseFilePath)
        self.chooseFileOutDir = filedialog.askdirectory(
                initialdir = self.chooseFilePath,
                parent = self,
                title = "Select output Directory",
                mustexist = False,
                )
        print("out:", self.chooseFileOutDir)
        if not self.checkDir(self.chooseFileOutDir):
            return
        self.convertFiles(filenames, self.chooseFileOutDir)
smt_iv_apocalypse_save_editor.py 文件源码 项目:SMT_IV_Apocalypse_Save_Editor 作者: waynelimt 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def openFileChooser(self):
        sel_file = filedialog.askopenfilenames(parent=self, initialdir=os.path.dirname(os.path.realpath(sys.argv[0])),
                                               filetypes=(("Save files", "*.sav"), ("All files", "*.*")))
        if sel_file:
            sel_file = sel_file[0]
            # print(sel_file)
            if os.path.isfile(sel_file):
                self.saveFilePathTxt.set(sel_file)
                self.saveFilePath = sel_file
                self.saveFileDir = os.path.dirname(sel_file)
                self.saveFileName = os.path.basename(sel_file)
                # print(self.saveFileName)
                # Reset Info
                self.clearMCSelSkillInfo()
                self.mcSkillListBox.select_clear(0, tk.END)
                self.clearDeStats()
                self.clearDeSelSkillInfo()
                self.deSkillListBox.select_clear(0, tk.END)
                self.processSaveFile()
smt_iv_save_editor.py 文件源码 项目:SMT_IV_Save_Editor 作者: waynelimt 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def openFileChooser(self):
        sel_file = filedialog.askopenfilenames(parent=self, initialdir=os.path.dirname(os.path.realpath(sys.argv[0])),
                                               filetypes=(("Save files", "*.sav"), ("All files", "*.*")))
        if sel_file:
            sel_file = sel_file[0]
            # print(sel_file)
            if os.path.isfile(sel_file):
                self.saveFilePathTxt.set(sel_file)
                self.saveFilePath = sel_file
                self.saveFileDir = os.path.dirname(sel_file)
                self.saveFileName = os.path.basename(sel_file)
                # print(self.saveFileName)
                # Reset Info
                self.clearMCSelSkillInfo()
                self.mcSkillListBox.select_clear(0, tk.END)
                self.clearDeStats()
                self.clearDeSelSkillInfo()
                self.deSkillListBox.select_clear(0, tk.END)
                self.processSaveFile()
Expression_list.py 文件源码 项目:Gellish 作者: AndriesSHP 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def Combine_Files_with_Network(self): #, Gel_db):
        """Select one or more Gellish files in a dialog and import files into the database tables,
        after syntactic verification, but without consistency verification.
        """
        # Select one or more files to be imported
        file_path_names = filedialog.askopenfilenames(filetypes=[("CSV files","*.csv"),("JSON files","*.json"),\
                                                             ("All files","*.*")], title="Select file")
        #print('Selected file(s):',modelFiles)
        if file_path_names == '':
            Message(self.Gel_net.GUI_lang_index, \
                '\nThe file name is blank or the inclusion is cancelled. There is no file read.',\
                '\nDe file naam is blanco of het inlezen is gecancelled. Er is geen file ingelezen.')
            return

        # Read file(s)
        for file_path_and_name in file_path_names:
            # Split file_path_and_name in file path and file name
            path_name = file_path_and_name.rsplit('/', maxsplit=1)
            if len(path_name) == 2:
                Message(self.Gel_net.GUI_lang_index, \
                        '\nReading file <{}> from directory {}.'.format(path_name[1], path_name[0]),\
                        '\nLees file <{}> van directory {}.'.format(path_name[1], path_name[0]))
                file_name = path_name[1]
                file_path = path_name[0]
            else:
                Message(self.Gel_net.GUI_lang_index, \
                        '\nReading file <{}> from current directory.'.format(file_path_and_name),\
                        '\nLees file <{}> van actuele directory.'.format(file_path_and_name))
                file_name = file_path_and_name
                file_path = ''

            # Create file object
            file = Gellish_file(file_path_and_name, self.Gel_net)

            # Import expressions from file
            self.Import_Gellish_from_file(file) #, Gel_db)
            self.files_read.append(file)

##            Message(self.Gel_net.GUI_lang_index, \
##                    '\nRead file   : %s is added to list of read files.'              % (file.path_and_name),\
##                    '\nGelezen file: %s is toegevoegd aan lijst van gelezen files.\n' % (file.path_and_name))
class_tester.py 文件源码 项目:SIMS 作者: copperwire 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def file_location():
    root = tkinter.Tk()
    files = filedialog.askopenfilenames(parent=root,title='Choose files')
    files = root.tk.splitlist(files)
    return files
MCS_Functions.py 文件源码 项目:HSL_Dev 作者: MaxJackson 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_filenames():
    Tk().withdraw()
    print("Initializing Dialogue... \nPlease select a file.")
    tk_filenames = askopenfilenames(initialdir=os.getcwd(), title='Please select one or more files')
    filenames = list(tk_filenames)
    return filenames
extended_pyGISS.py 文件源码 项目:pyGISS 作者: afourmy 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def import_map(self):
        filepath = tk.filedialog.askopenfilenames(title='Import shapefile')
        if not filepath: 
            return
        else: 
            self.filepath ,= filepath
        self.draw_map()
extended_pyGISS.py 文件源码 项目:pyGISS 作者: afourmy 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def import_nodes(self):
        filepath = filedialog.askopenfilenames(filetypes = (('xls files','*.xls'),))
        if not filepath:
            return
        else:
            filepath ,= filepath
        book = xlrd.open_workbook(filepath)
        try:
            sheet = book.sheet_by_index(0)
        # if the sheet cannot be found, there's nothing to import
        except xlrd.biffh.XLRDError:
            warnings.warn('the excel file is empty: import failed')
        for row_index in range(1, sheet.nrows):
            x, y = self.to_canvas_coordinates(*sheet.row_values(row_index))
            self.create_object(x, y)
_dialogs.py 文件源码 项目:porcupine 作者: Akuli 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _dialog(action, last_path):
    # pygments supports so many different kinds of file types that
    # showing them all would be insane
    # TODO: allow configuring which file types are shown
    options = {'filetypes': [("All files", "*")]}

    # the mro thing is there to avoid import cycles (lol)
    tab = porcupine.get_tab_manager().current_tab
    if any(cls.__name__ == 'FileTab' for cls in type(tab).__mro__):
        if tab.filetype.patterns:
            options['filetypes'].insert(
                0, ("%s files" % tab.filetype.name, tab.filetype.patterns))
        elif 'filetypes' in last_options:
            options['filetypes'] = last_options['filetypes']

        if tab.path is not None:
            options['initialdir'] = os.path.dirname(tab.path)
        elif 'initialdir' in last_options:
            options['initialdir'] = last_options['initialdir']

    last_options.clear()
    last_options.update(options)

    if action == 'open':
        assert last_path is None
        options['title'] = "Open Files"

        filenames = [os.path.abspath(file)
                     for file in filedialog.askopenfilenames(**options)]
        if filenames:
            last_options['initialdir'] = os.path.dirname(filenames[0])
        return filenames

    assert action == 'save'
    options['title'] = "Save As"
    if last_path is not None:
        options['initialdir'] = os.path.dirname(last_path)
        options['initialfile'] = os.path.basename(last_path)

    # filename can be '' if the user cancelled
    filename = filedialog.asksaveasfilename(**options)
    if filename:
        filename = os.path.abspath(filename)
        last_options['defaultdir'] = os.path.dirname(filename)
        return filename
    return None


问题


面经


文章

微信
公众号

扫码关注公众号