ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> pythoncard
pythoncard
Re: [Pythoncard-users] dialog form processing
by Alex Tweedly other posts by this author
Jun 15 2005 3:30PM messages near this date
Re: [Pythoncard-users] dialog form processing | Re: [Pythoncard-users] dialog form processing
Alex Tweedly wrote:

>  Bryan Murdock wrote:
> 
> > I'm writing an app that will open up a CustomDialog asking the user to
> > fill in a number of TextFields.  I'm trying to figure out a good
> > design for validating the fields and prompting the user to try again
> > if they left one blank, or entered something invalid.  It looks to me
> > like it can only be done after the user clicks OK and I get the result
> > back.  I'm having my Background create an alert dialog telling the
> > user what they did wrong, and then go back and redisplay the dialog,
> > which is kind OK, I guess.  Any suggestions for improvement?
> 
>  You can do it in the custom dialog function. This simple example will 
>  keep the dialog on-screen until it gets a satisfactory value for one 
>  of the fields (or the "Cancel" button is clicked).


which is true - but there's a better (and more obvious !!) way .... put 
in your own handler for the OK button within the dialog, validate any 
fields there - if they're good, do an event.skip(), if they're bad, pop 
up an alert (or whatever else you want) to inform the user ...

from PythonCard import model, dialog

class MyDialog(model.CustomDialog):
    def __init__(self, parent, txt=''):
        model.CustomDialog.__init__(self, parent)
       
    def on_btnOK_mouseClick(self, event):
        if self.components.TextField1.text == "Done":
            event.skip()
        else:
            result = dialog.alertDialog(self, 'Field 1 must be "Done"', 
'title')
       

def myDialog(parent):
    dlg = MyDialog(parent)
    result = dlg.showModal()

##    result.TextField1 = dlg.components.TextField1.text
##    result.TextField2 = dlg.components.TextField2.text
    result.texts = {}
    for name in ["TextField1", "TextField2"]:
        result.texts[name] = dlg.components[name].text
    dlg.destroy()
    return result


-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.7.3/15 - Release Date: 14/06/2005



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Pythoncard-users mailing list
Pythoncard-users@[...].net
https://lists.sourceforge.net/lists/listinfo/pythoncard-users
Thread:
Bryan Murdock
Alex Tweedly
Alex Tweedly
Bryan Murdock

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved