Created
June 19, 2014 18:37
-
-
Save ZGainsforth/4a887e25aa8c0eeaa052 to your computer and use it in GitHub Desktop.
Use a wx DirDialog, FileDialog, or Messagebox without the overhead of starting wx, etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Without having to worry about all the hassle of starting a wx app or remembering flags, just | |
# show a dialog box to get a directory, file or messagebox and be done with it. | |
# Zack Gainsforth 2014 | |
import wx | |
if 'app' not in locals(): | |
app = wx.App(None) | |
def DirDialog(DefaultDir='', Title='Select Directory:'): | |
dlg = wx.DirDialog (None, Title, DefaultDir, wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) | |
if dlg.ShowModal() == wx.ID_OK: | |
DirName = dlg.GetPath() | |
else: | |
DirName = None | |
dlg.Destroy() | |
return DirName | |
def FileDialog(DefaultDir='', Title='Select File:', Extension=''): | |
dlg = wx.FileDialog (None, Title, DefaultDir, '', Extension, wx.FD_DEFAULT_STYLE | wx.FD_FILE_MUST_EXIST) | |
if dlg.ShowModal() == wx.ID_OK: | |
FileName = dlg.GetPath() | |
else: | |
FileName = None | |
dlg.Destroy() | |
return FileName | |
def MessageBox(Title='Information', Message=None): | |
dlg = wx.MessageBox(Message, Title, wx.OK | wx.ICON_INFORMATION) | |
dlg.ShowModal() | |
dlg.Destroy() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment