[Gtk-sharp-list] GTK# App with multiple windows, where does Application.Init() and Application.Run() go?

Timothy Parez timothyparez@linux.be
Sat, 26 Mar 2005 12:12:29 +0100


Thnx, this really helps :)


-----Oorspronkelijk bericht-----
Van: Anset [mailto:Anset@anset.org] 
Verzonden: zaterdag 26 maart 2005 11:01
Aan: Timothy Parez
CC: gtk-sharp-list@lists.ximian.com
Onderwerp: Re: [Gtk-sharp-list] GTK# App with multiple windows, where does
Application.Init() and Application.Run() go?

Hi,

First of all, when you create a "MyWndow" class, make it enherit 
Gtk.Window. Makes your life easier:

Class MyWindow : Gtk.Window
{
...
}

Secondly, you call the Application.Init method only once, at the start 
of your application. This will initialise the necesary GDK stuff. (Try 
playing with a GDK.Pixbuf before calling Init. You'll get the point.)

The Application.Run method you can call as often as you like.
A second invocation will be nested inside the first. To get out of a 
"Run" you must call "Quit".

Applocation.Run()
	Application.Run()
	Application.Quit()
Application.Quit()

Now, most applications get by with just one Run call.

You write the Run method in you main window class. The program starts.
Lets say you want to open a second window when the user clicks a button? 
Well, in the ButtonClicked eventhandler, just call the constructor for 
that window class. MySecondWindow().

If you make sure that at the end of the construcor, the entire (second) 
window is defined and that you call "show()" or "ShowAll()" then the 
window will be displayed, your original window is still on the screen 
too, the Application.Run() method is still running and will keep on 
capturing and forewarding events to both windows.

Take care, calling Application.Quit once will, since only 1 Run was 
called, close both windows and end the program.

There are moments when you would want to nest two Run calls. A good 
example are the gtk.Dialogwindows. If you look at them, you'll see that 
you first create them with a call to "dialogwindowinstancename = 
dialogwindowclassname.New()" and then "launch" them with 
"dialogwinowinstance.Run().

This call will only return when the dialog is closed, That is because a 
new Application.Run() call is placed in the dialogwinowinstance.Run() call.

Hope this helps a bit.

By the way, ditch glade. I started out with it, got frustrated as hell 
and am now happely coding along without glade or libglade. You WILL hit 
a brick wall at some time. Better start steering away as soon as possible.

Wkr,

Anset

Timothy Parez wrote:
> Hi,
> 
>  
> 
> I get the basic idea behind GTK#, and managed to create an app with a 
> single window.
> 
> But now I would like to take the following approach.
> 
>  
> 
> Let's say I have 2 windows defined in my glade file (or perhaps 2 glade 
> files whatever).
> 
> And I define a c# class for each window, something like:
> 
>  
> 
> public class ContactWindow
> 
> {
> 
>             public ContactWindow()
> 
>             {
> 
>                         Glade.XML gXml = new Glade.XML(..);
>                         gXml.AutoConnect(this);
> 
> }
> 
> }
> 
>  
> 
> public class OtherWindow
> 
> {
> 
>             public OtherWindow()
> 
>             {
> 
>                         Glade.XML gXml = new Glade.XML(...);
>                         gXml.AutoConnect(this);
> 
> }
> 
> }
> 
>  
> 
> And then somewhere I have the entry point
> 
>  
> 
> public static void Main(string[] args)
> 
> {
> 
>             Application.Init();
> 
>  
> 
>             Application.Run();
> 
> }
> 
>  
> 
>  
> 
> At what point do I create new Windows?
> 
> As the first window to be created should be the ContactWindow,
> 
> All other windows will be created from this window, or perhaps another 
> window will be created just like that.
> 
>  
> 
> Thnx.
> 
> 
> ------------------------------------------------------------------------
> 
> Internal Virus Database is out-of-date.
> Checked by AVG Anti-Virus.
> Version: 7.0.308 / Virus Database: 266.7.4 - Release Date: 18/03/2005


-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.3 - Release Date: 25/03/2005




-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.3 - Release Date: 25/03/2005