mail-archives/gtk-sharp-list/2005-September/006380.html

209 строки
9.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Gtk-sharp-list] Re: How to validate input on Gtk.Dialog?
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20Re%3A%20How%20to%20validate%20input%20on%20Gtk.Dialog%3F&In-Reply-To=">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="006377.html">
<LINK REL="Next" HREF="006372.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Gtk-sharp-list] Re: How to validate input on Gtk.Dialog?</H1>
<B>Paul Wallimann</B>
<A HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20Re%3A%20How%20to%20validate%20input%20on%20Gtk.Dialog%3F&In-Reply-To="
TITLE="[Gtk-sharp-list] Re: How to validate input on Gtk.Dialog?">pwallimann at hotmail.com
</A><BR>
<I>Fri Sep 9 12:46:45 EDT 2005</I>
<P><UL>
<LI>Previous message: <A HREF="006377.html">[Gtk-sharp-list] How to validate input on Gtk.Dialog?
</A></li>
<LI>Next message: <A HREF="006372.html">[Gtk-sharp-list] Windows installer for .NET
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#6380">[ date ]</a>
<a href="thread.html#6380">[ thread ]</a>
<a href="subject.html#6380">[ subject ]</a>
<a href="author.html#6380">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>Hi Rafael,
Thanks for sharing your solution. Before I got to read your solution I have
found a way to accomplish the required functionality. What I do now is
Button b = new Button(Stock.Ok);
this.ActionArea.Add(b);
b.Clicked += OnButtonOKClicked;
b.Show(); //Required to make button visible. Why not automatically?
instead of
this.AddButton(Stock.Ok, ResponseType.Ok);
In the handler OnButtonOKClicked I first do the input validation and if it
succeeds then I call
this.Respond(ResponseType.Ok);
which closes the dialog and returns to the caller.
Regards,
Paul
Rafael Teixeira wrote:
&gt;<i> Small clarification:
</I>&gt;<i>
</I>&gt;<i> I use Glade and a wrapping class generator and windowWidget is of type
</I>&gt;<i> Gtk.Dialog.
</I>&gt;<i>
</I>&gt;<i> :)
</I>&gt;<i>
</I>&gt;<i>
</I>&gt;<i> On 9/8/05, Rafael Teixeira &lt;<A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">monoman at gmail.com</A>&gt; wrote:
</I>&gt;&gt;<i> I normally design a common form (window) and create a Run method somewhat
</I>&gt;&gt;<i> like
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> private string password;
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> public string Run()
</I>&gt;&gt;<i> {
</I>&gt;&gt;<i> try {
</I>&gt;&gt;<i> windowWidget.ShowAll();
</I>&gt;&gt;<i> while (true) {
</I>&gt;&gt;<i> ResponseType response = (ResponseType)windowWidget.Run();
</I>&gt;&gt;<i> if (response == ResponseType.Ok &amp;&amp; validate(password))
</I>&gt;&gt;<i> break;
</I>&gt;&gt;<i> if (response == ResponseType.Cancel) {
</I>&gt;&gt;<i> password = null;
</I>&gt;&gt;<i> break;
</I>&gt;&gt;<i> }
</I>&gt;&gt;<i> }
</I>&gt;&gt;<i> } catch (Exception ex) {
</I>&gt;&gt;<i> password = null;
</I>&gt;&gt;<i> }
</I>&gt;&gt;<i> windowWidget.Hide();
</I>&gt;&gt;<i> return password;
</I>&gt;&gt;<i> }
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> some event/signal is catched to update the 'password' variable as
</I>&gt;&gt;<i> needed, or some code like:
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> password = entryPassword.Text;
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> can be put before the first 'if'
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> :)
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> On 9/5/05, Paul Wallimann &lt;<A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">pwallimann at hotmail.com</A>&gt; wrote:
</I>&gt;&gt;<i> &gt; I am still rather new to GTK# and currently struggling with the
</I>&gt;&gt;<i> &gt; following: I want to implement a (modal) Login Dialog that only returns
</I>&gt;&gt;<i> &gt; to the calling method when the user either hits Cancel or enters the
</I>&gt;&gt;<i> &gt; correct password and hits OK. When the user enters the wrong password
</I>&gt;&gt;<i> &gt; and hits OK the dialog should remain open.
</I>&gt;&gt;<i> &gt;
</I>&gt;&gt;<i> &gt; I thought I could implement this by simply subclassing from Gtk.Dialog.
</I>&gt;&gt;<i> &gt; Unfortunately, the dialog gets closed immediately after either of the 2
</I>&gt;&gt;<i> &gt; buttons is hit and I have not found a way to execute the validation and
</I>&gt;&gt;<i> &gt; keep the dialog open when the password is wrong. Following is my code
</I>&gt;&gt;<i> &gt; (using gtk-sharp, Version=2.4.0.0):
</I>&gt;&gt;<i> &gt;
</I>&gt;&gt;<i> &gt; using System;
</I>&gt;&gt;<i> &gt; using Gtk;
</I>&gt;&gt;<i> &gt;
</I>&gt;&gt;<i> &gt; namespace Testing
</I>&gt;&gt;<i> &gt; {
</I>&gt;&gt;<i> &gt; public class LoginDialog : Dialog
</I>&gt;&gt;<i> &gt; {
</I>&gt;&gt;<i> &gt; public static void Main (string[] args)
</I>&gt;&gt;<i> &gt; {
</I>&gt;&gt;<i> &gt; Application.Init();
</I>&gt;&gt;<i> &gt;
</I>&gt;&gt;<i> &gt; LoginDialog dlg = new LoginDialog();
</I>&gt;&gt;<i> &gt; dlg.Modal = true;
</I>&gt;&gt;<i> &gt; int response = dlg.Run();
</I>&gt;&gt;<i> &gt; Console.WriteLine(&quot;Main: Response was {0}&quot;,
</I>&gt;&gt;<i> &gt; (ResponseType)response); dlg.Destroy();
</I>&gt;&gt;<i> &gt; }
</I>&gt;&gt;<i> &gt;
</I>&gt;&gt;<i> &gt; public LoginDialog()
</I>&gt;&gt;<i> &gt; : base()
</I>&gt;&gt;<i> &gt; {
</I>&gt;&gt;<i> &gt; this.AddButton(Stock.Cancel,
</I>&gt;&gt;<i> &gt; ResponseType.Cancel); this.AddButton(Stock.Ok,
</I>&gt;&gt;<i> &gt; ResponseType.Ok); this.Response += new
</I>&gt;&gt;<i> &gt; ResponseHandler(On_dialog_response);
</I>&gt;&gt;<i> &gt; }
</I>&gt;&gt;<i> &gt; private void On_dialog_response (object obj,
</I>&gt;&gt;<i> &gt; ResponseArgs args)
</I>&gt;&gt;<i> &gt; {
</I>&gt;&gt;<i> &gt; Console.WriteLine (&quot;On_dialog_response: args.ResponseId =
</I>&gt;&gt;<i> &gt; {0}&quot;,
</I>&gt;&gt;<i> &gt; args.ResponseId);
</I>&gt;&gt;<i> &gt; if (args.ResponseId == ResponseType.Ok)
</I>&gt;&gt;<i> &gt; args.RetVal = false; // keep dialog open
</I>&gt;&gt;<i> &gt; }
</I>&gt;&gt;<i> &gt; protected override bool OnDeleteEvent(Gdk.Event e)
</I>&gt;&gt;<i> &gt; {
</I>&gt;&gt;<i> &gt; // This method is not called. Why?
</I>&gt;&gt;<i> &gt; Console.WriteLine(&quot;OnDeleteEvent: called&quot;);
</I>&gt;&gt;<i> &gt; return false;
</I>&gt;&gt;<i> &gt; }
</I>&gt;&gt;<i> &gt; }
</I>&gt;&gt;<i> &gt; }
</I>&gt;&gt;<i> &gt;
</I>&gt;&gt;<i> &gt;
</I>&gt;&gt;<i> &gt; I would appreciate if someone could tell me how to do it correctly or
</I>&gt;&gt;<i> &gt; point me to an appropriate resource on the internet. Thanks in advance.
</I>&gt;&gt;<i> &gt;
</I>&gt;&gt;<i> &gt; Regards,
</I>&gt;&gt;<i> &gt; Paul Wallimann
</I>&gt;&gt;<i> &gt;
</I>&gt;&gt;<i> &gt; _______________________________________________
</I>&gt;&gt;<i> &gt; Gtk-sharp-list maillist - <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">Gtk-sharp-list at lists.ximian.com</A>
</I>&gt;&gt;<i> &gt; <A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">http://lists.ximian.com/mailman/listinfo/gtk-sharp-list</A>
</I>&gt;&gt;<i> &gt;
</I>&gt;&gt;<i>
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> --
</I>&gt;&gt;<i> Rafael &quot;Monoman&quot; Teixeira
</I>&gt;&gt;<i> ---------------------------------------
</I>&gt;&gt;<i> I'm trying to become a &quot;Rosh Gadol&quot; before my own eyes.
</I>&gt;&gt;<i> See <A HREF="http://www.joelonsoftware.com/items/2004/12/06.html">http://www.joelonsoftware.com/items/2004/12/06.html</A> for enlightment.
</I>&gt;&gt;<i> It hurts!
</I>&gt;&gt;<i>
</I>&gt;<i>
</I>&gt;<i>
</I>
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="006377.html">[Gtk-sharp-list] How to validate input on Gtk.Dialog?
</A></li>
<LI>Next message: <A HREF="006372.html">[Gtk-sharp-list] Windows installer for .NET
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#6380">[ date ]</a>
<a href="thread.html#6380">[ thread ]</a>
<a href="subject.html#6380">[ subject ]</a>
<a href="author.html#6380">[ author ]</a>
</LI>
</UL>
<hr>
<a href="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">More information about the Gtk-sharp-list
mailing list</a><br>
</body></html>