[Gtk-sharp-list] How to validate input on Gtk.Dialog?
Rafael Teixeira
monoman at gmail.com
Thu Sep 8 09:42:28 EDT 2005
Small clarification:
I use Glade and a wrapping class generator and windowWidget is of type
Gtk.Dialog.
:)
On 9/8/05, Rafael Teixeira <monoman at gmail.com> wrote:
> I normally design a common form (window) and create a Run method somewhat like
>
> private string password;
>
> public string Run()
> {
> try {
> windowWidget.ShowAll();
> while (true) {
> ResponseType response = (ResponseType)windowWidget.Run();
> if (response == ResponseType.Ok && validate(password))
> break;
> if (response == ResponseType.Cancel) {
> password = null;
> break;
> }
> }
> } catch (Exception ex) {
> password = null;
> }
> windowWidget.Hide();
> return password;
> }
>
> some event/signal is catched to update the 'password' variable as
> needed, or some code like:
>
> password = entryPassword.Text;
>
> can be put before the first 'if'
>
> :)
>
> On 9/5/05, Paul Wallimann <pwallimann at hotmail.com> wrote:
> > I am still rather new to GTK# and currently struggling with the following:
> > I want to implement a (modal) Login Dialog that only returns to the calling
> > method when the user either hits Cancel or enters the correct password and
> > hits OK. When the user enters the wrong password and hits OK the dialog
> > should remain open.
> >
> > I thought I could implement this by simply subclassing from Gtk.Dialog.
> > Unfortunately, the dialog gets closed immediately after either of the 2
> > buttons is hit and I have not found a way to execute the validation and
> > keep the dialog open when the password is wrong. Following is my code
> > (using gtk-sharp, Version=2.4.0.0):
> >
> > using System;
> > using Gtk;
> >
> > namespace Testing
> > {
> > public class LoginDialog : Dialog
> > {
> > public static void Main (string[] args)
> > {
> > Application.Init();
> >
> > LoginDialog dlg = new LoginDialog();
> > dlg.Modal = true;
> > int response = dlg.Run();
> > Console.WriteLine("Main: Response was {0}", (ResponseType)response);
> > dlg.Destroy();
> > }
> >
> > public LoginDialog()
> > : base()
> > {
> > this.AddButton(Stock.Cancel, ResponseType.Cancel);
> > this.AddButton(Stock.Ok, ResponseType.Ok);
> > this.Response += new ResponseHandler(On_dialog_response);
> > }
> > private void On_dialog_response (object obj, ResponseArgs args)
> > {
> > Console.WriteLine ("On_dialog_response: args.ResponseId = {0}",
> > args.ResponseId);
> > if (args.ResponseId == ResponseType.Ok)
> > args.RetVal = false; // keep dialog open
> > }
> > protected override bool OnDeleteEvent(Gdk.Event e)
> > {
> > // This method is not called. Why?
> > Console.WriteLine("OnDeleteEvent: called");
> > return false;
> > }
> > }
> > }
> >
> >
> > I would appreciate if someone could tell me how to do it correctly or point
> > me to an appropriate resource on the internet. Thanks in advance.
> >
> > Regards,
> > Paul Wallimann
> >
> > _______________________________________________
> > Gtk-sharp-list maillist - Gtk-sharp-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
> >
>
>
> --
> Rafael "Monoman" Teixeira
> ---------------------------------------
> I'm trying to become a "Rosh Gadol" before my own eyes.
> See http://www.joelonsoftware.com/items/2004/12/06.html for enlightment.
> It hurts!
>
--
Rafael "Monoman" Teixeira
---------------------------------------
I'm trying to become a "Rosh Gadol" before my own eyes.
See http://www.joelonsoftware.com/items/2004/12/06.html for enlightment.
It hurts!
More information about the Gtk-sharp-list
mailing list