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()
python类FD_SAVE的实例源码
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 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 saveMessages(self, event=None):
"""Save the message log to file.
"""
saveDialog = wx.FileDialog(self.scrolledPanel, message='Save Message Log',
wildcard='Text Files (*.txt)|*.txt|All Files|*',
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
try:
if saveDialog.ShowModal() == wx.ID_CANCEL:
return
with open(saveDialog.GetPath(), 'w') as fileHandle:
fileHandle.write(self.messageArea.GetValue())
except Exception as e:
wx.LogError('Save failed!')
raise
finally:
saveDialog.Destroy()
def stopRecording(self):
if self.recordingTime is not None:
secsToSave = time.time() - self.recordingTime
wx.LogMessage('Page %s saving %f secs of EEG' % (self.name, secsToSave))
cap = self.src.getEEGSecs(secsToSave, 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:
cap.saveFile(saveDialog.GetPath())
except Exception as e:
wx.LogError('Save failed!')
raise
finally:
saveDialog.Destroy()
self.recordButton.SetLabel('Start Recording')
self.recordingTime = None
def getpath(title, filt, k, para=None):
"""Get the defaultpath of the ImagePy"""
dpath = manager.ConfigManager.get('defaultpath')
if dpath ==None:
dpath = root_dir # './'
dic = {'open':wx.FD_OPEN, 'save':wx.FD_SAVE}
dialog = wx.FileDialog(curapp, title, dpath, '', filt, dic[k])
rst = dialog.ShowModal()
path = None
if rst == wx.ID_OK:
path = dialog.GetPath()
dpath = os.path.split(path)[0]
manager.ConfigManager.set('defaultpath', dpath)
if para!=None:para['path'] = path
dialog.Destroy()
return rst if para!=None else path
def on_save_as(self):
if self.get_project_filename():
dir_name, file_name = os.path.split(self.get_project_filename())
style = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT
wildcard = "Arquivo de projeto do GRIPy (*.pgg)|*.pgg"
fdlg = wx.FileDialog(self.GetTopWindow(),
'Escolha o arquivo PGG',
#dir_name, file_name,
wildcard=wildcard, style=style
)
if fdlg.ShowModal() == wx.ID_OK:
file_name = fdlg.GetFilename()
dir_name = fdlg.GetDirectory()
if not file_name.endswith('.pgg'):
file_name += '.pgg'
disableAll = wx.WindowDisabler()
wait = wx.BusyInfo("Saving GriPy project. Wait...")
self.save_project_data(os.path.join(dir_name, file_name))
del wait
del disableAll
fdlg.Destroy()
def onSaveAs(self,event):
fd = wx.FileDialog(self,message="Save the coordinates as...",style=wx.FD_SAVE,
wildcard="Comma separated value (*.csv)|*.csv")
fd.ShowModal()
self.filename = fd.GetPath()
self.save(self.filename)
def OnButtonSaveAs(self, msg):
if not self.model.status:
wx.MessageBox('No export file has been successfully loaded yet!')
return
dialog = wx.FileDialog(
self, 'Save As ...', style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
result = dialog.ShowModal()
if result != wx.ID_OK:
return
# Show filedialog and get value
self.model.save(dialog.GetPath())
def saveResultText(self, resultText):
saveDialog = wx.FileDialog(self, message='Save Result Text.',
wildcard='Text (*.txt)|*.txt|All Files|*',
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
try:
if saveDialog.ShowModal() == wx.ID_CANCEL:
return
with open(saveDialog.GetPath(), 'w') as fd:
fd.write(resultText)
except Exception:
wx.LogError('Save failed!')
raise
finally:
saveDialog.Destroy()
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
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 saveResultText(self, resultText):
saveDialog = wx.FileDialog(self, message='Save Result Text.',
wildcard='Text (*.txt)|*.txt|All Files|*',
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
try:
if saveDialog.ShowModal() == wx.ID_CANCEL:
return
with open(saveDialog.GetPath(), 'w') as fd:
fd.write(resultText)
except Exception:
wx.LogError('Save failed!')
raise
finally:
saveDialog.Destroy()
#def decimate(self, cap):
# #cap = cap.demean().bandpass(0.5, 20.0, order=3)
# # original
# #cap = cap.copy().demean().bandpass(0.5, 12.0, order=3)
# # biosemi hack XXX - idfah
# cap = cap.copy().demean().reference((36,37)).deleteChans(range(32,40))
# cap.keepChans(('Fz', 'Cz', 'P3', 'Pz', 'P4', 'P7', 'Oz', 'P8'))
# # 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
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 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()
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
def OnSaveScreenshot(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)
saveImageGL(self.glcanvas, filepath)
dlg.Destroy()
return
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])
def on_save(self, evt):
dic = {'open':wx.FD_OPEN, 'save':wx.FD_SAVE}
filt = 'PNG files (*.png)|*.png'
dialog = wx.FileDialog(self, 'Save Picture', '', '', filt, wx.FD_SAVE)
rst = dialog.ShowModal()
if rst == wx.ID_OK:
path = dialog.GetPath()
self.canvas.save_bitmap(path)
dialog.Destroy()
def _OnSave(self,typename="Csv",sep=","):
dialog=wx.FileDialog(self,typename,style=wx.FD_SAVE)
if dialog.ShowModal()==wx.ID_OK:
self.file=dialog.GetPath()
self.save_tab(self.file, sep)
dialog.Destroy()
def OnSave(self,event):
if self.file=='':
dialog=wx.FileDialog(None,'wxpython Notebook(s)',style=wx.FD_SAVE)
if dialog.ShowModal()==wx.ID_OK:
self.file=dialog.GetPath()
self.text.SaveFile(self.file)
dialog.Destroy()
else:
self.text.SaveFile(self.file)
def OnSaveAs(self,event):
dialog=wx.FileDialog(None,'wxpython notebook',style=wx.FD_SAVE)
if dialog.ShowModal()==wx.ID_OK:
self.file=dialog.GetPath()
self.text.SaveFile(self.file)
dialog.Destroy()
def save(self, e):
if not hasattr(self, "brackets"):
errortext = "Make bracket before doing that"
w = wx.MessageDialog(self.parent, errortext,
"Error", wx.ICON_ERROR)
w.ShowModal()
w.Destroy()
return
dia = wx.FileDialog(self, "Save Bracket",
"", self.sname, "bp5000 bracket|*.bp5",
wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if dia.ShowModal() == wx.ID_CANCEL:
return
bracketio.write_bracket(dia.GetPath(), self.brackets)
def save_file(self, event):
'''??????????? '''
wildcard = "Text Files (*.txt)|*.txt|" "All files (*.*)|*.*"
dlg = wx.FileDialog(None, u"???????",
os.getcwd(),
defaultFile="",
style=wx.FD_SAVE, # |wx.FD_OVERWRITE_PROMPT
wildcard=wildcard
)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
with open(filename, 'w', encoding='utf-8') as f:
f.write(self.t1.GetValue()) # ??????????????
def on_export(self, event):
"""
Gets a file path via popup, then exports content
"""
exporters = plugin_loader.load_export_plugins()
wildcards = '|'.join([x.wildcard for x in exporters])
export_dialog = wx.FileDialog(self, "Export BOM", "", "",
wildcards,
wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
if export_dialog.ShowModal() == wx.ID_CANCEL:
return
base, ext = os.path.splitext(export_dialog.GetPath())
filt_idx = export_dialog.GetFilterIndex()
exporters[filt_idx]().export(base, self.component_type_map)
def file_chooser(title='Choose a file:', default_path = '', default_file = '',
mode='r', wildcard='*', parent_obj = None):
"""Provides a file chooser dialog and returns the file path(s) when the file(s) is selected.
mode option provides file dialog type: read single, read multiple, or save single.
mode = 'r' creates an 'Open' file dialog for single file read.
mode = 'm' creates an 'Open' file dialog for multiple files read.
mode = 'w' creates a 'Save' file dialog.
wildcard option can be specified as "*.xls"
Example:
>> file_chooser(title='Choose a file:', mode='r')
"""
wildcard = "%s|%s" % (wildcard, wildcard)
style = { 'r': wx.FD_OPEN,
'm': wx.FD_MULTIPLE,
'w': wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT }[mode]
try:
file_chooser = wx.FileDialog(parent_obj, title, wildcard=wildcard, style=style,
defaultDir = default_path, defaultFile = default_file)
except wx._core.PyNoAppError:
app = mzApp()
app.launch()
file_chooser = wx.FileDialog(parent_obj, title, wildcard=wildcard, style=style,
defaultDir = default_path, defaultFile = default_file)
file_name = None
if file_chooser.ShowModal() == wx.ID_OK:
if mode == 'm':
file_name = file_chooser.GetPaths()
else:
file_name = file_chooser.GetPath()
file_chooser.Destroy()
return file_name
def file_save_dialog(title):
dialog_style = wx.FD_SAVE
dialog = wx.FileDialog(
None, message=title,
defaultDir=os.getcwd(),
defaultFile='', style=dialog_style)
return dialog
def get_con_xml_path(self):
style = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT
dialog = wx.FileDialog(self, message='Save connections.xml',defaultFile='connections.xml', wildcard='connections.xml|connections.xml', style=style)
if dialog.ShowModal() == wx.ID_OK:
path = dialog.GetPath()
else:
path = None
dialog.Destroy()
return path
def onSaveFileAs(self, evt):
style = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT
wildcard = "Arquivo de console GRIPy (*.gripy_console)|*.gripy_console"
fdlg = wx.FileDialog(self, 'Escolha o arquivo gripy_console',
defaultDir=self.dir_name,
wildcard=wildcard,
style=style
)
if fdlg.ShowModal() == wx.ID_OK:
self.file_name = fdlg.GetFilename()
self.dir_name = fdlg.GetDirectory()
self._do_save()
fdlg.Destroy()
def OnCreateSnippet(self,event):
openFileDialog = wx.FileDialog(self, "Save i3 Colour snippet file", os.path.expanduser("~/.i3/"), "","i3 Colour snippet file |*", wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return
open(openFileDialog.GetPath(), 'w').close()
self.config.updateConfig(openFileDialog.GetPath())
os.system("rm '"+openFileDialog.GetPath()+"'")
os.system("mv '/tmp/i3tmpconf' '"+openFileDialog.GetPath()+"'")