|
From: Kevin A. <al...@se...> - 2002-02-15 19:33:05
|
I forgot to mention that there is no particular reason why we couldn't just
use a result attribute (variable) instead of a method, so the code below
just becomes
self.result = {'accepted':self.accepted(),
'returned':self.returned()}
with no result() method. The user code call would look like:
>>> from PythonCardPrototype import dialog
>>> dialog.MessageDialog(None, 'a message', 'a title').result
{'accepted': 1, 'returned': 'Ok'}
ka
> -----Original Message-----
> From: pyt...@li...
> [mailto:pyt...@li...]On Behalf Of Kevin
> Altis
> Sent: Friday, February 15, 2002 11:25 AM
> To: pythoncard-Users
> Cc: Robin Dunn
> Subject: [Pythoncard-users] possible single line dialog calls solution
>
>
> The basic problem looks like a generic issue of classes versus
> functions in
> Python. In order to make dialogs single line calls in user code I
> need to be
> able to instantiate the class and get a result in the same line
> of code. If
> we provided a function wrapper around a dialog class then the user could
> just call the function, but that makes subclassing problematic.
>
> Here's what we want to do more or less:
> >>> from PythonCardPrototype import dialog
> >>> dialog.MessageDialog(None, 'a message', 'a title').result()
> {'accepted': 1, 'returned': 'Ok'}
>
> Below is the code snippet from dialog.py that I'm working on. The
> ModalDialog class is already wrapping some basic dialog code. The
> only thing
> I've added is the _result variable and the result method. I can't just
> return a result at the end of the __init__ because __init__
> expects a return
> result of None.
>
> class MessageDialog( ModalDialog ) :
>
> def __init__( self, aParent, aMessage, aTitle,
> aIcon = ICON_INFORMATION, aButtons = BUTTON_OK |
> BUTTON_CANCEL) :
> ModalDialog.__init__( self, aParent )
> dialog = wx.wxMessageDialog(self._parent,
> aMessage,
> aTitle,
> aIcon | aButtons )
> self._setDialog( dialog )
> self._showModal()
> self._destroy()
> self._result = {'accepted':self.accepted(),
> 'returned':self.returned()}
>
> def result(self):
> return self._result
>
> I thought about trying something like:
>
> def __repr__(self):
> return str(result)
>
> The __repr__ trick works as long as all the return values are strings, but
> that is going to be tricky even for the basic dialogs such as font and
> color, though it is possible. It is going to be impossible for
> GenericDialog
> where the results could contain any arbitrary objects. Of course,
> the value
> returned as a string has to be converted back into a dictionary,
> so __repr__
> doesn't look like a good solution.
>
> There might be a clever way in Python of avoiding the result() method call
> tacked onto the end of the dialog instantiation, so I'm posting this note
> just in case the code wizards have a better idea. Otherwise, I'll do the
> conversion using the result() strategy. It still looks like typical Python
> usage, so it doesn't bother me and all dialog calls will work exactly the
> same way.
>
> ka
>
>
> _______________________________________________
> Pythoncard-users mailing list
> Pyt...@li...
> https://lists.sourceforge.net/lists/listinfo/pythoncard-users
>
|