Re: [Vala] Genie, subclassing and some help!



On 29/06/10 12:58, Harry Van Haaren wrote:
Hey!

    2) Perhaps related, in the main.gs <http://main.gs> file, I have:

    init
       Gtk.init(ref args)
       create_indicator()
       Gtk.main()

    However, if I don;t put the Gtk.main() in the function above (rather
    than the init), it doesn't work. Why is this/is this on purpose?


Maybe you understand this already, just in case though:
Gtk needs to be "initialized" before you can use it (display any widgets
or even create them).
The function that does this is *Gtk.init()

*Then you create some widgets, ie *Gtk.Button.with_label("Hello"); *,
add this to a window etc...

And then to hand control over to Gtk, we call *Gtk.main()*. This
function lets Gtk actually *DRAW* the
window on the screen, and its is only now that the window is actually
SHOWN to the user. (Despite that
it was created long beforehand).

Hence that these 3 steps are nessisary in your main() function.

The reason that its a very good idea to put *Gtk.init()  *and 
*Gtk.main()  *in your *main()*, is this:
If you want to show 2 toplevel windows, and you've got *Gtk.main()* in
your class' init function, Gtk
is going to create your class, and then show the window. (ie: pass
control of the thread to Gtk.)
This is going to halt the program exectution until this window is
destroyed, and then your program
gets control of the thread back, and the next class' init will be
called, and that window shown.

Don't think I explained that 100%, but hope you understand me anyway.
Cheers, -Harry


Thanks Harry for the explanation, it makes it a bit clearer, but it
doesn't seem to solve the problem :-(

Perhaps it is easier for Abderrahim and Harry if I just put my code
online and tell you what is not happening.

The file that are concerned are main.gs and indicator.gs

The problem is that the wAppIndicator class defined in indicator.gs and
created in main.gs does not show.

However if I take the functions in the wAppIndicator class, put them
into a function and just apply the functions to an instance of Indicator
(the class from which wAppIndicator is subclassed from) and add
Gtk.main() on the end (which means I have two overall), it then works.

The problem is really why it doesn't work in the first place :-(

BZR branch with code in (if you need it in other form, please don't
hesitate to ask):
https://code.launchpad.net/~and471/+junk/not-working

-- 
Andrew



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]