def NewFile(self,e):
wcd='All files(*)|*'
dest = 'stopgo_project_'
destid = int(time.time())
try:
dirname = self.clargs['project']
except OSError:
dirname = os.path.expanduser('~')
except:
dirname = os.path.join(os.path.expanduser('~'),self.myprefs['dir'])
sd = wx.FileDialog(self, message='Save file as...',
defaultDir=dirname, defaultFile='stopgo_project_' + str(destid),
wildcard=wcd,
style=wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
if sd.ShowModal() == wx.ID_OK:
projnam = sd.GetFilename()
projpath= os.path.join(sd.GetPath(),projnam)
# make the directory
# the OS does this for us but just in case..
#if not os.path.exists( os.path.dirname(projpath) ):
#os.makedirs( os.path.dirname(projpath))
# make image dir
os.makedirs( os.path.join(os.path.dirname(projpath),'images'))
dbfile = projpath
self.imgdir = os.path.join(os.path.dirname(projpath), 'images')
logging.exception(dbfile)
logging.exception(projpath)
logging.exception(self.imgdir)
self.con = sq.connect(dbfile, isolation_level=None )
self.cur = self.con.cursor()
self.cur.execute("CREATE TABLE IF NOT EXISTS Project(Id INTEGER PRIMARY KEY, Path TEXT, Name TEXT, [timestamp] timestamp)")
self.cur.execute("CREATE TABLE IF NOT EXISTS Timeline(Id INTEGER PRIMARY KEY, Image TEXT, Blackspot INT)")
self.cur.execute("INSERT INTO Project(Path, Name, timestamp) VALUES (?,?,?)", ("images", "StopGo Project", datetime.now() ))
#self.con.close()
self.BindKeys(dbfile)
sb = self.GetStatusBar()
stat = os.path.basename(projpath) + ' created'
sb.SetStatusText(stat, 0)
sb.SetStatusText('', 1)
sd.Destroy()
python类FD_SAVE的实例源码
def report_chooser(title=None, mode='r', parent = None, **kwargs):
'''A specialized file_chooser function for multiplierz files. Otherwise,
works just like file_chooser.
'parent' is the parent of the dialog--used when this is called by a GUI
element. It is perfectly fine to leave it as None, and the GUI frame will
have no parent.
'title' can be left blank for the following default titles based on mode:
r - 'Choose multiplierz File:'
w - 'Save File:'
m - 'Choose multiplierz Files:'
'mode' is one of 'r', 'w', and 'm', just as for file_chooser.
**kwargs can include any additional options to pass to the FileDialog constructor,
such as defaultDir (default directory).'''
# For legacy reasons, these are often misplaced in scripts.
# But they're both necessarily typed differently, so its sortable.
if isinstance(parent, basestring) and not isinstance(title, basestring):
title, parent = parent, title
wildcard = ("Worksheets (*.xls; *.xlsx)|*.xls; *.xlsx|"
"Comma-separated Values (*.csv)|*.csv|"
"mzResults Database (*.mzd)|*.mzd|"
"mzIdentML (*.mzid)|*.mzid")
if not title:
title = {'r': 'Choose multiplierz File:',
'w': 'Save File:',
'm': 'Choose multiplierz Files:'}[mode]
style = { 'r': wx.FD_OPEN,
'm': wx.FD_MULTIPLE,
'w': wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT }[mode]
#index = {'.xls': 0,
#'.xlsx': 0,
#'.csv': 1,
#'.mzd': 2}[settings.default_format]
index = 0
try:
file_dialog = wx.FileDialog(parent, title, wildcard=wildcard, style=style, **kwargs)
except wx._core.PyNoAppError as err:
app = mzApp()
app.launch()
file_dialog = wx.FileDialog(None, title, wildcard=wildcard, style=style, **kwargs)
file_dialog.SetFilterIndex(index)
file_name = None
if file_dialog.ShowModal() == wx.ID_OK:
if mode == 'm':
file_name = file_dialog.GetPaths()
else:
file_name = file_dialog.GetPath()
file_dialog.Destroy()
return file_name