From: Bryan M. <bmu...@gm...> - 2005-06-15 19:18:26
|
Hello, 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? Also, while we're on the subject of CustomDialogs, is there a nice way to copy the text from all TextField components of the CustomDialog into result, other than listing each one out, like so? result.FirstName =3D dlg.components.FirstNameTextField.text result.LastName =3D dlg.components.LastNameTextField.text etc. etc. Thanks, Bryan |
From: Alex T. <al...@tw...> - 2005-06-15 20:16:40
|
Bryan Murdock wrote: >Hello, > >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). from PythonCard import model, dialog class MyDialog(model.CustomDialog): def __init__(self, parent, txt=''): model.CustomDialog.__init__(self, parent) def myDialog(parent): dlg = MyDialog(parent) while True: result = dlg.showModal() if not result.accepted: #can always cancel break if dlg.components.TextField1.text == "Done": break ## 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 This keeps the dialog on-screen - but unfortunately it doesn't provide any helpful feedback to the user. I tried changing it to provide an alert box - and when you do that, the original dialog disappears while the new dialog is there. Changed section of code: while True: result = dlg.showModal() if not result.accepted: #can always cancel break if dlg.components.TextField1.text == "Done": break else: result = dialog.alertDialog(parent, 'Must set field 1 to "Done"', 'some title') You could experiment with this - e.g. add a "status/error" component (static text) to the dialog, and try setting it rather than the alert dialog - see if that allows you to give helpful feedback while avoiding the visual distraction of having the dialog disappear and reappear. >Also, while we're on the subject of CustomDialogs, is there a nice way >to copy the text from all TextField components of the CustomDialog >into result, other than listing each one out, like so? > >result.FirstName = dlg.components.FirstNameTextField.text >result.LastName = dlg.components.LastNameTextField.text >etc. >etc. > > > you can do it using a dictionary as I did above (a dictionary called "texts" within the overall "result" dictionary). It makes it easy to get them into "result" - but it means that back in the background app where you invoked the dialog, you need to access them via the dictionary, as in def on_Button1_mouseClick(self, event): result = custDialog.myDialog(self) print result.texts["TextField1"] print result.texts["TextField2"] -- 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 |
From: Alex T. <al...@tw...> - 2005-06-15 22:29:40
|
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 |
From: Bryan M. <bmu...@gm...> - 2005-06-16 18:01:25
|
On 6/15/05, Alex Tweedly <al...@tw...> wrote: > 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 ... That works beautifully, thanks! Thanks for the sample code too, I hadn't seen or heard of event.skip() before. Bryan |