On Oct 31, 2007, at 1:58 AM, Phil Edwards wrote:
> Aaron Stevens wrote:
>>
>> For example, when I used the FileDialog, the result has members
>> 'accepted' and paths -- but according to the documentation these are
>> supposed to be mapped in a dict. Any clarification expected.
>>
>> result = dialog.fileDialog(self, 'Open', '', '', '*' )
>>
>> if result.accepted == True:
>> filename = result.paths[0]
>>
>
> Hi Aaron:
>
> The documentation is simply out of date, that's all. The behaviour you
> describe is as expected - when version 0.8.2 (I think!) of PythonCard
> was released, the dialog components were changed so that they are
> sub-classes of wx.lib.dialogs.
>
> Where the documentation talks about a dictionary item, e.g.
> result['someName'], you just substitute result.someName.
>
> The change was designed to make some bits of PythonCard more
> 'pythonic'
> and to make it easier to hand-roll your own custom dialogs.
>
> --
>
> Regards
>
> Phil Edwards
> Brighton, UK
There is another crucial element missing from the documentation. When
we switched to using subclasses of wx.lib.dialogs, all dialogs ended
up with at least three values for the result: accepted, returned, and
returnedString. 'accepted' is a boolean, either True or False and
returnedString is the string value of the button clicked by the user,
which originally we just called 'returned'. 'returned' is the
numerical return value of the button clicked.
Most of the PythonCard samples and tools just use the returnedString
if they need something besides the boolean 'accepted', but that's
problematic if you want to internationalize your application. In that
case, you should use 'returned' and the wx constants for comparisons
as shown in the table below.
returnedString wx constant returned
=======================================
Ok wx.ID_OK 5100
Cancel wx.ID_CANCEL 5101
Yes wx.ID_YES 5103
No wx.ID_NO 5104
Depending on the dialog you can just check whether the dialog was
'accepted' or not and the 'returned' and 'returnedString' values
won't impact your code. Typically, the only time you'll need
'returned' or 'returnedString' would be for a message dialog or
custom dialog where you care about if the user clicked a particular
button like 'Yes', 'No', or 'Cancel'.
Note that the return value constants are not the same as the style
constants such as wx.OK (4) and wx.CANCEL (16) provided for setting
up the dialog. You can tell the return constants because they always
have an ID_ prefix. This is a wx-ism, so there isn't anything I can
do about it.
We'll need to add a few more tweaks to the dialog documentation in
cvs before I upload them to the main site.
ka
|