From: Kevin A. <ka...@us...> - 2004-08-12 19:11:22
|
Update of /cvsroot/pythoncard/PythonCard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15301 Modified Files: model.py debug.py dialog.py Log Message: dialog.py is now a thin wrapper around wx.lib.dialogs.py all dialog results now use DialogResults class instead of dictionary e.g. result.accepted instead of result['accepted'] see dialogs sample and other samples and tools for examples of change Index: debug.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/debug.py,v retrieving revision 1.131 retrieving revision 1.132 diff -C2 -d -r1.131 -r1.132 *** debug.py 14 May 2004 19:23:11 -0000 1.131 --- debug.py 12 Aug 2004 19:11:13 -0000 1.132 *************** *** 334,339 **** def onSelectColor(self, evt): result = dialog.colorDialog(self) ! if result['accepted']: ! self.wField.SetValue(str(result['color'])) def onSelectFont(self, evt): --- 334,339 ---- def onSelectColor(self, evt): result = dialog.colorDialog(self) ! if result.accepted: ! self.wField.SetValue(str(result.color)) def onSelectFont(self, evt): *************** *** 345,351 **** f = font.Font(desc) result = dialog.fontDialog(self, f) ! if result['accepted']: #color = dlg.getColor() ! f = result['font'] self.wField.SetValue("%s" % f) --- 345,351 ---- f = font.Font(desc) result = dialog.fontDialog(self, f) ! if result.accepted: #color = dlg.getColor() ! f = result.font self.wField.SetValue("%s" % f) Index: model.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/model.py,v retrieving revision 1.179 retrieving revision 1.180 diff -C2 -d -r1.179 -r1.180 *** model.py 9 Aug 2004 17:22:44 -0000 1.179 --- model.py 12 Aug 2004 19:11:13 -0000 1.180 *************** *** 48,51 **** --- 48,52 ---- import component import util + import dialog import types *************** *** 1188,1214 **** self._initLayout( aDialogRsrc.components ) ! # KEA 2001-10-14 ! # this is from ModalDialog in dialog.py ! def showModal(self): ! self._accepted = False ! self._returned = self.ShowModal() ! if self._returned == wx.ID_OK or self._returned == wx.ID_YES: ! self._accepted = True ! ! # KEA should these be getAccepted, getReturned? ! def accepted( self ) : ! return self._accepted ! ! # KEA added accessor for self._returned ! # should we just return numeric values instead? ! # should the the strings all be lowercase ! # Ok is actually displayed as OK in dialogs ! def returned( self ) : ! ret = self._returned for w in self.components.itervalues(): ! if ret == w.GetId(): return w.label ! def destroy( self ) : self.Destroy() --- 1189,1204 ---- self._initLayout( aDialogRsrc.components ) ! # this allows the labels to be something other than Ok, Cancel, No, etc. ! def _returnedString(self, returned): for w in self.components.itervalues(): ! if returned == w.GetId(): return w.label ! def showModal(self): ! result = dialog.DialogResults(self.ShowModal()) ! result.returnedString = self._returnedString(result.returned) ! return result ! ! def destroy(self): self.Destroy() Index: dialog.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/dialog.py,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** dialog.py 21 Jul 2004 19:16:43 -0000 1.33 --- dialog.py 12 Aug 2004 19:11:13 -0000 1.34 *************** *** 9,448 **** import font - ICON_EXCLAMATION = wx.ICON_EXCLAMATION # Shows an exclamation mark icon. - ICON_HAND = wx.ICON_HAND # Shows an error icon. - ICON_ERROR = wx.ICON_ERROR # Shows an error icon - the same as wxICON_HAND. - ICON_QUESTION = wx.ICON_QUESTION # Shows a question mark icon. - ICON_INFORMATION = wx.ICON_INFORMATION # Shows an information (i) icon. - - BUTTON_OK = wx.OK # Show an OK button. - BUTTON_CANCEL = wx.CANCEL # Show a Cancel button. - BUTTON_YES_NO = wx.YES_NO # Show Yes and No buttons. - BUTTON_YES_DEFAULT = wx.YES_DEFAULT # Used with wxYES_NO, makes Yes button the default - which is the default behaviour. - BUTTON_NO_DEFAULT = wx.NO_DEFAULT # Used with wxYES_NO, makes No button the default. - - RETURNED_OK = wx.ID_OK - RETURNED_CANCEL = wx.ID_CANCEL - RETURNED_YES = wx.ID_YES - RETURNED_NO = wx.ID_NO - - FILE_OPEN = wx.OPEN # This is an open dialog. - FILE_SAVE = wx.SAVE # This is a save dialog. - FILE_HIDE_READONLY = wx.HIDE_READONLY # Hide read-only files. - # For save dialog only: prompt for a confirmation if a file will be overwritten. - FILE_OVERWRITE_PROMPT = wx.OVERWRITE_PROMPT - # For open dialog only: allows selecting multiple files. - FILE_MULTIPLE = wx.MULTIPLE - # Change the current working directory to the directory where the file(s) chosen by the user are. - FILE_CHANGE_DIR = wx.CHANGE_DIR - - # For dir dialog only: allow creation of new directories - DIR_NEWDIR_BUTTON = wx.DD_NEW_DIR_BUTTON - - TEXT_MULTILINE = wx.TE_MULTILINE - TEXT_PASSWORD = wx.TE_PASSWORD - - class ModalDialog : - - def __init__( self, aParent ) : - self._parent = aParent - self._accepted = 0 - self._returned = 0 - self._dialog = None - - #def _getParent( self ) : - # return self._parent - - def _setDialog( self, aWxDialog ) : - self._dialog = aWxDialog - - def _getDialog( self ) : - return self._dialog - - # KEA I don't think we need this - def _setAccepted( self, aBoolean ) : - self._accepted = aBoolean - - def _showModal( self ) : - # KEA added wxID_YES to accepted condition - # and added a returned value - self._returned = self._dialog.ShowModal() - if self._returned == wx.ID_OK or self._returned == wx.ID_YES : - self._accepted = 1 - # KEA don't destroy until after we get the results - # so self._destroy() added to each dialog class below - #self._destroy() - self.result = {'accepted':self._accepted, 'returned':self.returned()} - - # KEA should these be getAccepted, getReturned? - def accepted( self ) : - return self._accepted - - # KEA added accessor for self._returned - # should we just return numeric values instead? - # should the the strings all be lowercase - # Ok is actually displayed as OK in dialogs - def returned( self ) : - ret = self._returned - if ret == RETURNED_OK: - return "Ok" - elif ret == RETURNED_CANCEL: - return "Cancel" - elif ret == RETURNED_YES: - return "Yes" - elif ret == RETURNED_NO: - return "No" - - def _destroy( self ) : - self._dialog.Destroy() ! class FindDialog(ModalDialog): ! ! def __init__(self, aParent, searchText='', wholeWordsOnly=0, caseSensitive=0): ! ModalDialog.__init__( self, aParent ) ! ! dlg = wx.Dialog(aParent, -1, "Find", wx.DefaultPosition, wx.Size(370, 120)) ! ! wx.StaticText(dlg, -1, 'Find what:', wx.Point(7, 10)) ! wSearchText = wx.TextCtrl(dlg, -1, searchText, ! wx.Point(70, 7), wx.Size(195, -1)) ! wSearchText.SetValue(searchText) ! wx.Button(dlg, wx.ID_OK, "Find Next", wx.Point(280, 5), wx.DefaultSize).SetDefault() ! wx.Button(dlg, wx.ID_CANCEL, "Cancel", wx.Point(280, 35), wx.DefaultSize) ! wWholeWord = wx.CheckBox(dlg, -1, 'Match whole word only', ! wx.Point(7, 35), wx.DefaultSize, wx.NO_BORDER) ! if wholeWordsOnly: ! wWholeWord.SetValue(1) ! wCase = wx.CheckBox(dlg, -1, 'Match case', ! wx.Point(7, 55), wx.DefaultSize, wx.NO_BORDER) ! if caseSensitive: ! wCase.SetValue(1) ! wSearchText.SetSelection(0, len(wSearchText.GetValue())) ! wSearchText.SetFocus() ! ! self._setDialog( dlg ) ! self._showModal() ! self._text = wSearchText.GetValue() ! self._wholeWord = wWholeWord.GetValue() ! self._caseSensitive = wCase.GetValue() ! self._destroy() ! self.result['text'] = self._text ! self.result['wholeword'] = self._wholeWord ! self.result['casesensitive'] = self._caseSensitive ! ! def getText( self ) : ! return self._text ! ! def getWholeWord( self ) : ! return self._wholeWord ! ! def getCaseSensitive( self ) : ! return self._caseSensitive ! ! def findDialog(parent, searchText='', wholeWordsOnly=0, caseSensitive=0): ! dialog = FindDialog(parent, searchText, wholeWordsOnly, caseSensitive) ! result = {'accepted':dialog.accepted(), ! 'searchText': dialog.getText(), ! 'wholeWordsOnly': dialog.getWholeWord(), ! 'caseSensitive': dialog.getCaseSensitive()} ! return result ! ! ! class ColorDialog( ModalDialog ) : ! ! def __init__( self, aParent ) : ! self._color = None ! ModalDialog.__init__( self, aParent ) ! dialog = wx.ColourDialog( self._parent ) # add color data support later ! dialog.GetColourData().SetChooseFull(1) ! self._setDialog( dialog ) ! self._showModal() ! # KEA why does this work? the dialog should already be destroyed ! # by _showModal() ! self._colorData = dialog.GetColourData() ! self._color = self._colorData.GetColour().Get() ! self._destroy() ! self.result['color'] = self._color ! ! def getColor( self ) : ! return self._color ! ! # should we just return numeric values instead? ! # should the the strings all be lowercase ! # Ok is actually displayed as OK in dialogs ! def returnedString(ret): ! if ret == RETURNED_OK: ! return "Ok" ! elif ret == RETURNED_CANCEL: ! return "Cancel" ! elif ret == RETURNED_YES: ! return "Yes" ! elif ret == RETURNED_NO: ! return "No" ! ! def colorDialog(parent): ! dialog = wx.ColourDialog(parent) ! dialog.GetColourData().SetChooseFull(1) ! returned = dialog.ShowModal() ! if returned == wx.ID_OK or returned == wx.ID_YES: ! accepted = 1 ! else: ! accepted = 0 ! colorData = dialog.GetColourData() ! color = colorData.GetColour().Get() ! dialog.Destroy() ! return {'accepted':accepted, 'returned':returnedString(returned), 'color':color} ! ! # do not rely on the return value of getFont ! # I just added this today 2001-07-28 and haven't ! # done enough with fonts to know what I need to use and ignore ! class FontDialog( ModalDialog ) : ! ! def __init__( self, aParent, aFont=None) : ! self._color = None ! self._font = None ! self._fontDescription = None ! ModalDialog.__init__( self, aParent ) ! # RDS: You have to pass a wxFontData instance below, ! # None causes a seg fault. ! aFontData = wx.FontData() ! # 2004-07-21 ! # Mac needs the color set ! aFontData.SetColour(wx.BLACK) ! if aFont is not None: ! aFontData.SetInitialFont(aFont._getFont()) ! ! dialog = wx.FontDialog( self._parent, aFontData ) # add font data support later ! self._setDialog( dialog ) ! self._showModal() ! # KEA why does this work? the dialog should already be destroyed ! # by _showModal() ! if self.accepted(): ! fontData = dialog.GetFontData() ! self._color = fontData.GetColour().Get() ! fontWx = fontData.GetChosenFont() ! self._fontDescription = font.fontDescription(fontWx) ! self._font = font.Font(self._fontDescription) ! #self._font = (font.GetFamily(), font.GetFaceName(), font.GetPointSize(), font.GetStyle()) ! #self._font = (font.GetFaceName(), font.GetPointSize()) ! self._destroy() ! self.result['color'] = self._color ! self.result['font'] = self._font ! def getColor( self ) : ! return self._color ! def getFont( self ) : ! return self._font def fontDialog(parent, aFont=None): ! return FontDialog(parent, aFont).result ! ! class TextEntryDialog( ModalDialog ) : ! ! def __init__( self, aParent, aWindowTitle, aMessage, aDefaultText, aStyle=0 ) : ! self._text = None ! ModalDialog.__init__( self, aParent ) ! dialog = wx.TextEntryDialog( self._parent, ! aMessage, ! aWindowTitle, ! aDefaultText, ! aStyle | wx.OK | wx.CANCEL ) ! self._setDialog( dialog ) ! self._showModal() ! # KEA why does this work? the dialog should already be destroyed ! # by _showModal() ! self._text = dialog.GetValue() ! self._destroy() ! self.result['text'] = self._text ! ! def getText( self ) : ! return self._text ! ! def textEntryDialog(aParent, aWindowTitle, aMessage, aDefaultText, aStyle=0): ! return TextEntryDialog(aParent, aWindowTitle, aMessage, aDefaultText, aStyle).result ! ! ! class MessageDialog( ModalDialog ) : ! ! def __init__( self, aParent, aMessage, aTitle, ! aIcon = ICON_INFORMATION, ! aButtons = BUTTON_OK | BUTTON_CANCEL) : ! ModalDialog.__init__( self, aParent ) ! dialog = wx.MessageDialog(self._parent, ! aMessage, ! aTitle, ! aIcon | aButtons ) ! self._setDialog( dialog ) ! self._showModal() ! self._destroy() ! ! def messageDialog(aParent, aMessage, aTitle, ! aIcon = ICON_INFORMATION, ! aButtons = BUTTON_OK | BUTTON_CANCEL): ! return MessageDialog(aParent, aMessage, aTitle, aIcon, aButtons).result ! ! ! # KEA this class should go away ! # it does the exact same thing as the default for MessageDialog ! """ ! class ConfirmationDialog( ModalDialog ) : ! ! def __init__( self, aParent, aMessage, aTitle ) : ! ModalDialog.__init__( self, aParent ) ! dialog = wxMessageDialog( self._parent, ! aMessage, ! aTitle, ! ICON_INFORMATION | BUTTON_OK | BUTTON_CANCEL ) ! self._setDialog( dialog ) ! self._showModal() ! """ ! ! # KEA alerts are common, so providing a class rather than requiring the user code ! # to set up the right icons and buttons with MessageDialog ! class AlertDialog(MessageDialog) : ! def __init__(self, aParent, aMessage, aTitle) : ! MessageDialog.__init__(self, aParent, aMessage, aTitle, ICON_EXCLAMATION, BUTTON_OK) ! ! def alertDialog(aParent, aMessage, aTitle): ! return AlertDialog(aParent, aMessage, aTitle).result ! ! class ScrolledMessageDialog( ModalDialog ) : ! ! def __init__( self, aParent, aMessage, aTitle ) : ! ModalDialog.__init__( self, aParent ) ! dialog = dialogs.ScrolledMessageDialog( self._parent, ! aMessage, ! aTitle) ! self._setDialog( dialog ) ! self._showModal() ! self._destroy() ! ! def scrolledMessageDialog(aParent, aMessage, aTitle): ! return ScrolledMessageDialog(aParent, aMessage, aTitle).result ! ! ! class FileDialog( ModalDialog ) : ! ! def __init__(self, aParent, aMessage, aPath, aFileName, aFilter, ! aStyle=FILE_OPEN | FILE_MULTIPLE): ! ModalDialog.__init__( self, aParent ) ! self._message = aMessage ! self._path = aPath ! self._fileName = aFileName ! self._filter = aFilter ! self._value = None ! self._paths = None ! ! dialog = wx.FileDialog( self._parent, ! aMessage, ! aPath, ! aFileName, ! aFilter, ! aStyle ) ! ! self._setDialog( dialog ) ! ! # KEA changed to self, was: ! # ModalDialog._showModal( self ) ! self._showModal() ! ! if self.accepted() : ! self._paths = self._dialog.GetPaths() ! self._destroy() ! self.result['paths'] = self._paths ! ! def getPaths( self ) : ! return self._paths ! ! def fileDialog(aParent, aMessage, aPath, aFileName, aFilter, aStyle=FILE_OPEN | FILE_MULTIPLE): ! return FileDialog(aParent, aMessage, aPath, aFileName, aFilter, aStyle).result ! ! def openFileDialog(parent=None, title='Open', directory='', filename='', wildcard='All Files (*.*)|*.*', style=FILE_OPEN | FILE_MULTIPLE): ! return FileDialog(parent, title, directory, filename, wildcard, style).result ! ! def saveFileDialog(parent=None, title='Save', directory='', filename='', wildcard='All Files (*.*)|*.*', style=FILE_SAVE | FILE_HIDE_READONLY | FILE_OVERWRITE_PROMPT): ! return FileDialog(parent, title, directory, filename, wildcard, style).result ! ! class DirectoryDialog( ModalDialog ) : ! ! def __init__( self, aParent, aMessage, aPath, aStyle=DIR_NEWDIR_BUTTON ) : ! ModalDialog.__init__( self, aParent ) ! self._message = aMessage ! self._path = aPath ! self._value = None ! self._setDialog( wx.DirDialog( self._parent, aMessage, aPath, aStyle ) ) ! ! if self._message is not None : ! self._dialog.SetMessage( self._message ) ! ! if self._path is not None : ! self._dialog.SetPath( self._path ) ! ! # KEA changed to self, was: ! # ModalDialog._showModal( self ) ! self._showModal() ! ! if self.accepted() : ! self._value = self._dialog.GetPath() ! self._destroy() ! self.result['path'] = self._value ! ! def getPath( self ) : ! return self._value ! ! def directoryDialog(aParent, aMessage, aPath, aStyle=DIR_NEWDIR_BUTTON): ! return DirectoryDialog(aParent, aMessage, aPath, aStyle).result ! ! ! class SingleChoiceDialog( ModalDialog ) : ! ! def __init__( self, aParent, aWindowTitle, aMessage, aList, ! aStyle=wx.OK | wx.CANCEL | wx.CENTRE) : ! self._text = None ! ModalDialog.__init__( self, aParent ) ! # KEA 2003-07-30 ! # added wx.DEFAULT_DIALOG_STYLE below ! # to workaround wxPython 2.4.1.2 bug ! dialog = wx.SingleChoiceDialog( self._parent, ! aMessage, ! aWindowTitle, ! aList, ! style=aStyle | wx.DEFAULT_DIALOG_STYLE ) ! self._setDialog( dialog ) ! self._showModal() ! # KEA why does this work? the dialog should already be destroyed ! # by _showModal() ! self._text = dialog.GetStringSelection() ! self._destroy() ! self.result['selection'] = self._text ! ! def getSelection( self ) : ! return self._text ! ! def singleChoiceDialog(aParent, aWindowTitle, aMessage, aList, ! aStyle=wx.OK | wx.CANCEL | wx.CENTRE): ! return SingleChoiceDialog(aParent, aWindowTitle, aMessage, aList, aStyle).result ! ! class MultipleChoiceDialog( ModalDialog ) : ! ! def __init__( self, aParent, aWindowTitle, aMessage, aList) : ! self._list = None ! ModalDialog.__init__( self, aParent ) ! dialog = dialogs.MultipleChoiceDialog( self._parent, ! aMessage, ! aWindowTitle, ! aList) ! self._setDialog( dialog ) ! self._showModal() ! # KEA why does this work? the dialog should already be destroyed ! # by _showModal() ! self._list = dialog.GetValueString() ! self._destroy() ! self.result['selection'] = self._list ! ! def getSelection( self ) : ! return self._list - def multipleChoiceDialog(aParent, aWindowTitle, aMessage, aList): - return MultipleChoiceDialog(aParent, aWindowTitle, aMessage, aList).result --- 9,39 ---- import font ! DialogResults = dialogs.DialogResults ! findDialog = dialogs.findDialog ! colorDialog = dialogs.colorDialog def fontDialog(parent, aFont=None): ! result = dialogs.fontDialog(aFont) ! if result.accepted: ! fontData = result.fontData ! result.color = result.fontData.GetColour().Get() ! fontWx = result.fontData.GetChosenFont() ! result.fontDescription = font.fontDescription(fontWx) ! fontWx = None ! result.font = font.Font(result.fontDescription) ! return result ! textEntryDialog = dialogs.textEntryDialog ! messageDialog = dialogs.messageDialog ! alertDialog = dialogs.alertDialog ! scrolledMessageDialog = dialogs.scrolledMessageDialog ! fileDialog = dialogs.fileDialog ! openFileDialog = dialogs.openFileDialog ! saveFileDialog = dialogs.saveFileDialog ! directoryDialog = dialogs.directoryDialog ! singleChoiceDialog = dialogs.singleChoiceDialog ! multipleChoiceDialog = dialogs.multipleChoiceDialog |