Last active
December 23, 2015 16:39
-
-
Save hastern/6663853 to your computer and use it in GitHub Desktop.
Some utility functions for wxPython dialogs.
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
import os | |
import wx | |
def messageDialog(message, caption=wx.MessageBoxCaptionStr, style=wx.OK | wx.ICON_INFORMATION): | |
"""Utility method to create a generic message dialog""" | |
dial = wx.MessageDialog(None, message, caption, style) | |
return dial.ShowModal() | |
def fileDialog(mode, message, fileTypes = None, dir = wx.EmptyString): | |
"""Utility method to create a generic file dialog""" | |
wc = wx.FileSelectorDefaultWildcardStr if fileTypes is None else "|".join([ descr + " (*" + ext + ")|*" + ext for descr, ext in fileTypes]) | |
diag = wx.FileDialog(None, message, defaultDir=dir, wildcard = wc, style=mode) | |
diag.ShowModal() | |
return os.path.join(diag.Directory,diag.Filename) if diag.Filename != "" else None | |
def displayError(message, caption = 'An error occured'): | |
"""Specialised utility method for error dialogs""" | |
return messageDialog(message, caption, wx.OK | wx.ICON_ERROR) == wx.OK | |
def displayInformation(message, caption='Warning'): | |
"""Specialised utility method for information dialogs""" | |
return messageDialog(message, caption, wx.OK | wx.ICON_INFORMATION) == wx.OK | |
def displayQuestion(message, caption='Question'): | |
"""Specialised utility method for question dialogs""" | |
return messageDialog(message, caption, wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) | |
def loadFileDialog(message = "Load File", fileTypes = None, dir = wx.EmptyString): | |
"""Specialised utility method for file loading dialogs""" | |
return fileDialog(mode = wx.FD_OPEN, message= message, fileTypes = fileTypes, dir = dir) | |
def saveFileDialog(message = "Save File", fileTypes = None, dir = wx.EmptyString): | |
"""Specialised utility method for file saving dialogs""" | |
return fileDialog(mode = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT, message= message, fileTypes = fileTypes, dir = dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment