python类FileDialog()的实例源码

bciplayer.py 文件源码 项目:cebl 作者: idfah 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def saveCap(self):
        cap = self.src.getEEGSecs(self.getSessionTime(), filter=False)
        saveDialog = wx.FileDialog(self, message='Save EEG data.',
            wildcard='Pickle (*.pkl)|*.pkl|All Files|*',
            style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)

        try:
            if saveDialog.ShowModal() == wx.ID_CANCEL:
                return
            cap.saveFile(saveDialog.GetPath())
        except Exception:
            wx.LogError('Save failed!')
            raise
        finally:
            saveDialog.Destroy()

    ##def decimate(self, cap):
    ##    #cap = cap.demean().bandpass(0.5, 10.0, order=3)
    ##    cap = cap.copy().demean().bandpass(0.5, 12.0, order=3)

    ##    # kind of a hack XXX - idfah
    ##    if cap.getSampRate() > 32.0:
    ##        decimationFactor = int(np.round(cap.getSampRate()/32.0))
    ##        cap = cap.downsample(decimationFactor)

    ##    return cap
p300grid.py 文件源码 项目:cebl 作者: idfah 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def saveCap(self):
        cap = self.src.getEEGSecs(self.getSessionTime(), filter=False)
        saveDialog = wx.FileDialog(self, message='Save EEG data.',
            wildcard='Pickle (*.pkl)|*.pkl|All Files|*',
            style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)

        try:
            if saveDialog.ShowModal() == wx.ID_CANCEL:
                return
            cap.saveFile(saveDialog.GetPath())
        except Exception:
            wx.LogError('Save failed!')
            raise
        finally:
            saveDialog.Destroy()
p300bot.py 文件源码 项目:cebl 作者: idfah 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def saveCap(self):
        cap = self.src.getEEGSecs(self.getSessionTime(), filter=False)
        saveDialog = wx.FileDialog(self, message='Save EEG data.',
            wildcard='Pickle (*.pkl)|*.pkl|All Files|*',
            style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)

        try:
            if saveDialog.ShowModal() == wx.ID_CANCEL:
                return
            cap.saveFile(saveDialog.GetPath())
        except Exception:
            wx.LogError('Save failed!')
            raise
        finally:
            saveDialog.Destroy()
wxgraphics.py 文件源码 项目:cebl 作者: idfah 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def saveFile(self):
        self.refresh()

        saveDialog = wx.FileDialog(self, message='Save Image',
                wildcard='Portable Network Graphics (*.png)|*.png|All Files|*',
                style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)

        try:
            if saveDialog.ShowModal() != wx.ID_CANCEL:
                img = self.drawingBuffer.ConvertToImage()
                img.SaveFile(saveDialog.GetPath(), wx.BITMAP_TYPE_PNG)

        except Exception as e:
            wx.LogError('Save failed!')
            raise

        finally:
            saveDialog.Destroy()
file_picker.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def on_browser_button(self, evt):
        cur_entry = self.current_textctrl_GetValue()
        if len(cur_entry) == 0:
            cur_entry = self.default_entry
        cur_entry = os.path.abspath(os.path.expanduser(cur_entry))
        cur_entry_parts = [a for a in ['/'] + cur_entry.split('/') if len(a) > 0]
        while (len(cur_entry_parts) >= 1 and
               not (os.path.isdir(os.path.join(*cur_entry_parts)) or
                    os.path.isfile(os.path.join(*cur_entry_parts)))):
            cur_entry_parts = cur_entry_parts[:-1]
        if len(cur_entry_parts) > 1:
            cur_entry = os.path.join(*cur_entry_parts)
        else:
            cur_entry = os.path.expanduser('~')
        if os.path.isdir(cur_entry):
            cur_basename = ''
            cur_dirname = cur_entry
        else:
            cur_basename = os.path.basename(cur_entry)
            cur_dirname = os.path.dirname(cur_entry)
        if self.is_files_not_dirs:
            dlg = wx.FileDialog(self, "Choose a file:", style=wx.DD_DEFAULT_STYLE,
                                defaultDir=cur_dirname, defaultFile=cur_basename, wildcard=self.allowed_extensions)
            # TODO: defaultFile is not being set to cur_basename in the dialog box
        else:
            dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE, defaultPath=cur_dirname)
        if dlg.ShowModal() == wx.ID_OK:
            self._on_load(dlg.GetPath())
        dlg.Destroy()
file_picker.py 文件源码 项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def on_browser_button(self, evt):
        cur_entry = self.current_textctrl_GetValue()
        if len(cur_entry) == 0:
            cur_entry = self.default_entry
        cur_entry = os.path.abspath(os.path.expanduser(cur_entry))
        cur_entry_parts = [a for a in ['/'] + cur_entry.split('/') if len(a) > 0]
        while (len(cur_entry_parts) >= 1 and
               not (os.path.isdir(os.path.join(*cur_entry_parts)) or
                    os.path.isfile(os.path.join(*cur_entry_parts)))):
            cur_entry_parts = cur_entry_parts[:-1]
        if len(cur_entry_parts) > 1:
            cur_entry = os.path.join(*cur_entry_parts)
        else:
            cur_entry = os.path.expanduser('~')
        if os.path.isdir(cur_entry):
            cur_basename = ''
            cur_dirname = cur_entry
        else:
            cur_basename = os.path.basename(cur_entry)
            cur_dirname = os.path.dirname(cur_entry)
        if self.is_files_not_dirs:
            dlg = wx.FileDialog(self, "Choose a file:", style=wx.DD_DEFAULT_STYLE,
                                defaultDir=cur_dirname, defaultFile=cur_basename, wildcard=self.allowed_extensions)
            # TODO: defaultFile is not being set to cur_basename in the dialog box
        else:
            dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE, defaultPath=cur_dirname)
        if dlg.ShowModal() == wx.ID_OK:
            self._on_load(dlg.GetPath())
        dlg.Destroy()
make_timelapse.py 文件源码 项目:Pigrow 作者: Pragmatismo 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def audio_btn_click(self, e):
        openFileDialog = wx.FileDialog(self, "Select caps folder", "", "", "MP3 files (*.mp3)|*.mp3", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        openFileDialog.SetMessage("Select an audio file from to use")
        if openFileDialog.ShowModal() == wx.ID_CANCEL:
            return 'none'
        audio_track = openFileDialog.GetPath()
        self.audio_box.SetValue(str(audio_track))
make_timelapse.py 文件源码 项目:Pigrow 作者: Pragmatismo 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def select_caps_folder(self):
        openFileDialog = wx.FileDialog(self, "Select caps folder", "", "", "JPG files (*.jpg)|*.jpg", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        openFileDialog.SetMessage("Select an image from the caps folder you want to import")
        if openFileDialog.ShowModal() == wx.ID_CANCEL:
            return 'none'
        new_cap_path = openFileDialog.GetPath()

        capsdir = os.path.split(new_cap_path)
        capset   = capsdir[1].split(".")[0][0:-10]  # Used to select set if more than one are present
        cap_type = capsdir[1].split('.')[1]
        capsdir = capsdir[0] + '/'
        print(" Selected " + capsdir + " with capset; " + capset + " filetype; " + cap_type)
        return capsdir, capset, cap_type
common.py 文件源码 项目:bonsu 作者: bonsudev 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, parent, name, objectpath, textwidth, file_extension):
        def assign(input):
            self.objectpath.ChangeValue(input)
        def OnBrowse(self):
            if IsNotWX4():
                dlg = wx.FileDialog(parent, 'Choose a file', os.getcwd(), '',  file_extension, wx.OPEN)
            else:
                dlg = wx.FileDialog(parent, 'Choose a file', os.getcwd(), '',  file_extension, wx.FD_OPEN)
            if dlg.ShowModal() == wx.ID_OK:
                assign(dlg.GetPath())
            dlg.Destroy()
        def OnEdit(event):
            self.objectpath.ChangeValue(event.GetString())
        fontpointsize=wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT).GetPointSize()
        self.font = wx.Font(fontpointsize, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
        dc = wx.ScreenDC()
        dc.SetFont(self.font)
        textw,texth = dc.GetTextExtent(name)
        if textw > textwidth:
            labelw = textw
        else:
            labelw = textwidth
        wx.BoxSizer.__init__(self, wx.HORIZONTAL)
        self.label = StaticTextNew(parent, -1, name, style =wx.ALIGN_RIGHT, size=(labelw,-1) )
        self.label.SetFont(self.font)
        self.Add( self.label, 0, wx.CENTER )
        self.objectpath = TextCtrlNew(parent, -1)
        self.objectpath.SetFont(self.font)
        self.objectpath.SetValue(objectpath)
        self.objectpath.SetToolTipNew("Browse for file or type "+os.linesep+"path and name")
        self.objectpath.Bind(wx.EVT_TEXT_ENTER, OnEdit)
        self.Add( self.objectpath, 1, wx.CENTER |wx.EXPAND )
        self.button = ButtonNew(parent, -1, "Browse")
        self.button.SetFont(self.font)
        self.button.SetToolTipNew("Browse for file or type "+os.linesep+"path and name")
        self.button.Bind(wx.EVT_BUTTON, OnBrowse)
        self.Add( self.button, 0, wx.LEFT|wx.CENTER)
bonsu.py 文件源码 项目:bonsu 作者: bonsudev 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def OnOpen(self,e):
        panelphase = self.GetChildren()[1].GetPage(0)
        if panelphase.pipeline_started == False:
            cwd = self.CurrentWD()
            if IsNotWX4():
                dlg = wx.FileDialog(self, "Choose a file", cwd, "", "fin files (*.fin)|*.fin|All files (*.*)|*.*", wx.OPEN)
            else:
                dlg = wx.FileDialog(self, "Choose a file", cwd, "", "fin files (*.fin)|*.fin|All files (*.*)|*.*", wx.FD_OPEN)
            if dlg.ShowModal() == wx.ID_OK:
                self.filename = dlg.GetFilename()
                self.dirname = dlg.GetDirectory()
                RestoreInstance(self)
            dlg.Destroy()
bonsu.py 文件源码 项目:bonsu 作者: bonsudev 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def OnSave(self,e):
        panelphase = self.GetChildren()[1].GetPage(0)
        if panelphase.pipeline_started == False:
            cwd = self.CurrentWD()
            if IsNotWX4():
                dlg = wx.FileDialog(self, "Choose a file", cwd, "", "fin files (*.fin)|*.fin|All files (*.*)|*.*", wx.SAVE | wx.OVERWRITE_PROMPT)
            else:
                dlg = wx.FileDialog(self, "Choose a file", cwd, "", "fin files (*.fin)|*.fin|All files (*.*)|*.*", wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
            if dlg.ShowModal() == wx.ID_OK:
                self.filename=dlg.GetFilename()
                self.dirname=dlg.GetDirectory()
                SaveInstance(self)
            dlg.Destroy()
imViewer_Simple.py 文件源码 项目:augment3D 作者: yulkang 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def OnFileOpen(self, event):
        """Opens a selected file."""
        dlg = wx.FileDialog(self, 'Choose a file to add.', '', '', '*.*', wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            fullPath = dlg.GetPath()
            imageFile = dlg.GetFilename()
            # checkDICMHeader()
            self.show_file(imageFile, fullPath)
meshView.py 文件源码 项目:laplacian-meshes 作者: bmershon 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def OnLoadMesh(self, evt):
        dlg = wx.FileDialog(self, "Choose a file", ".", "", "OFF files (*.off)|*.off|TOFF files (*.toff)|*.toff|OBJ files (*.obj)|*.obj", wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            filename = dlg.GetFilename()
            dirname = dlg.GetDirectory()
            filepath = os.path.join(dirname, filename)
            print dirname
            self.glcanvas.mesh = PolyMesh()
            print "Loading mesh %s..."%filename
            self.glcanvas.mesh.loadFile(filepath)
            self.glcanvas.meshCentroid = self.glcanvas.mesh.getCentroid()
            self.glcanvas.meshPrincipalAxes = self.glcanvas.mesh.getPrincipalAxes()
            print "Finished loading mesh"
            print self.glcanvas.mesh
            self.glcanvas.initMeshBBox()
            self.glcanvas.Refresh()
        dlg.Destroy()
        return
meshView.py 文件源码 项目:laplacian-meshes 作者: bmershon 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def OnSaveMesh(self, evt):
        dlg = wx.FileDialog(self, "Choose a file", ".", "", "*", wx.SAVE)
        if dlg.ShowModal() == wx.ID_OK:
            filename = dlg.GetFilename()
            dirname = dlg.GetDirectory()
            filepath = os.path.join(dirname, filename)
            self.glcanvas.mesh.saveFile(filepath, True)
            self.glcanvas.Refresh()
        dlg.Destroy()
        return
meshView.py 文件源码 项目:laplacian-meshes 作者: bmershon 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def OnSaveScreenshot(self, evt):
        dlg = wx.FileDialog(self, "Choose a file", ".", "", "*", wx.SAVE)
        if dlg.ShowModal() == wx.ID_OK:
            filename = dlg.GetFilename()
            dirname = dlg.GetDirectory()
            filepath = os.path.join(dirname, filename)
            saveImageGL(self.glcanvas, filepath)
        dlg.Destroy()
        return
LapGUI.py 文件源码 项目:laplacian-meshes 作者: bmershon 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def OnSaveMesh(self, evt):
        dlg = wx.FileDialog(self, "Choose a file", ".", "", "*", wx.FD_SAVE)
        if dlg.ShowModal() == wx.ID_OK:
            filename = dlg.GetFilename()
            dirname = dlg.GetDirectory()
            filepath = os.path.join(dirname, filename)
            self.glcanvas.mesh.saveFile(filepath, True)
            self.glcanvas.Refresh()
        dlg.Destroy()
        return
card_viewer.py 文件源码 项目:magic-card-database 作者: drknotter 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def on_open(self,e):
        """ Open a file"""
        self.dirname = ''
        dlg = wx.FileDialog(self, "Choose a deck", self.dirname, "", "*.db", wx.FD_OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.filename = dlg.GetFilename()
            self.dirname = dlg.GetDirectory()
            print self.dirname, self.filename
#            f = open(os.path.join(self.dirname, self.filename), 'r')
#            self.control.SetValue(f.read())
#            f.close()
        dlg.Destroy()
ffmpeg.py 文件源码 项目:pyjam 作者: 10se1ucgo 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def browse(self, event):
        wildcard = "Audio and Video files ({wildcards})|{wildcards}".format(wildcards=';'.join(FILE_EXTS))
        file_dialog = wx.FileDialog(self, message="Select files",
                                    style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_FILE_MUST_EXIST, wildcard=wildcard)
        file_dialog.SetDirectory(self.in_dir) if self.in_dir else None
        if file_dialog.ShowModal() != wx.ID_OK:
            file_dialog.Destroy()
            return
        self.in_files = file_dialog.GetPaths()
        self.in_picker.GetTextCtrl().SetValue(str(file_dialog.GetFilenames()).strip('[]'))
        file_dialog.Destroy()
visuals.py 文件源码 项目:pyDataView 作者: edwardsmith999 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def save_dialogue(self, event, defaultFile):
        dlg = wx.FileDialog(self, defaultDir='./', defaultFile=defaultFile,
                            style=wx.FD_SAVE) 
        if (dlg.ShowModal() == wx.ID_OK):
            fpath = dlg.GetPath()
        dlg.Destroy()

        #Check if defined, if cancel pressed then return
        try:
            fpath
        except NameError:
            return

        if defaultFile == 'fig.png':
            try:
                print('Saving figure as ' + fpath)
                self.pyplotp.savefigure(fpath)
                print('Saved.')
            except ValueError:
                raise
        elif defaultFile == 'data.csv':
            print('Writing data as ' + fpath)
            self.pyplotp.writedatacsv(fpath)
            print('Finished.')
        elif defaultFile == 'script.py':
            self.pyplotp.writescript(fpath)

        #Output error as dialogue
        #import sys
        #exc_info = sys.exc_info()
        #print(exc_info, dir(exc_info), type(exc_info))
        #showMessageDlg(exc_info[1])
PLCOpenEditor.py 文件源码 项目:beremiz 作者: nucleron 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def OnOpenProjectMenu(self, event):
        if self.Controler is not None and not self.CheckSaveBeforeClosing():
            return
        filepath = ""
        if self.Controler is not None:
            filepath = self.Controler.GetFilePath()
        if filepath != "":
            directory = os.path.dirname(filepath)
        else:
            directory = os.getcwd()

        result = None

        dialog = wx.FileDialog(self, _("Choose a file"), directory, "",  _("PLCOpen files (*.xml)|*.xml|All files|*.*"), wx.OPEN)
        if dialog.ShowModal() == wx.ID_OK:
            filepath = dialog.GetPath()
            if os.path.isfile(filepath):
                self.ResetView()
                controler = PLCControler()
                result = controler.OpenXMLFile(filepath)
                self.Controler = controler
                self.LibraryPanel.SetController(controler)
                self.ProjectTree.Enable(True)
                self.PouInstanceVariablesPanel.SetController(controler)
                self._Refresh(PROJECTTREE, LIBRARYTREE)
            self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU)
        dialog.Destroy()

        if result is not None:
            (num, line) = result
            self.ShowErrorMessage(_("PLC syntax error at line {a1}:\n{a2}").format(a1=num, a2=line))


问题


面经


文章

微信
公众号

扫码关注公众号