"""
FtpCube
Copyright (C) Michael Gilfix
This file is part of FtpCube.
You should have received a file COPYING containing license terms
along with this program; if not, write to Michael Gilfix
(mgilfix@eecs.tufts.edu) for a copy.
This version of FtpCube is open source; you can redistribute it and/or
modify it under the terms listed in the file COPYING.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
"""
import wx
import utils
class MessageDialog(wx.MessageDialog):
"""Message dialog wrapper class."""
pass
class InputBox(wx.TextEntryDialog):
"""Text input box wrapper class."""
pass
class FileDialog(wx.FileDialog):
"""File choosing dialog wrapper class."""
pass
class DirDialog(wx.DirDialog):
"""Directory browsing dialog wrapper class."""
pass
def displayErrorDialog(frame, msg):
"""Displays an error message to the end user.
The specified message is the error text displayed. The frame serves as
the parent frame for this error dialog."""
dialog = MessageDialog(frame, str(msg), _("Ftpcube Error"), style=wx.OK | wx.ICON_ERROR)
dialog.SetIcon(utils.getAppIcon())
dialog.ShowModal()
dialog.Destroy()
def displayMessageDialog(frame, title, msg, style):
"""Displays a message to the user.
The specified message is the error text displayed. The frame serves as
the parent frame for the message dialog. The title sets the dialog window
title and the style corresponds to the wxPython style for the window."""
dialog = MessageDialog(frame, str(msg), title, style)
dialog.SetIcon(utils.getAppIcon())
ret = dialog.ShowModal()
dialog.Destroy()
return ret
def displayInputDialog(frame, title, msg):
"""Displays a text input box to the end user.
Displays a text input box using the specified frame as the parent frame.
The title and message are used to decorate the box. If the user responds
by clicking the OK button, then the contents of the box are returned.
Otherwise, the None value is returned."""
input_box = InputBox(frame, str(msg), title)
input_box.SetIcon(utils.getAppIcon())
ret = input_box.ShowModal()
if ret == wx.ID_OK:
return input_box.GetValue()
else:
return None
def displayFileDialog(frame, title, style=None):
"""Displays a file choosing dialog.
Displays a file choosing dialog using the specified frame as the parent
frame. The specified title is set on the dialog window. If the user
responds by clicking on the OK button for the dialog, then the corresponding
file path is returned. Otherwise, the None value is returned."""
if style is None:
style = wx.FILE_MUST_EXIST
dialog = FileDialog(frame, title, utils.getStartPath(), '', style=style)
dialog.SetIcon(utils.getAppIcon())
ret = dialog.ShowModal()
if ret == wx.ID_OK:
return dialog.GetPath()
else:
return None
def displayDirDialog(frame, title):
"""Displays a directory browsing dialog.
Displays a directory browsing dialog using the specified frame as the parent
frame. The specified title is set on the dialog window. If the user responds
by clicking on the OK button for the dialog, then the corresponding
directory path is returned. Otherwise, the None value is returned."""
dialog = DirDialog(frame, title, utils.getStartPath())
dialog.SetIcon(utils.getAppIcon())
ret = dialog.ShowModal()
if ret == wx.ID_OK:
return dialog.GetPath()
else:
return None
|