Re: [Vala] Accessing some widget's properties which is declared in the "main" function from out side function.
- From: Frederik <scumm_fredo gmx net>
- To: vala-list <vala-list gnome org>
- Subject: Re: [Vala] Accessing some widget's properties which is declared in the "main" function from out side function.
- Date: Thu, 30 Jul 2009 22:09:36 +0200
Arkadi Viner wrote:
I want to access "txtKey" which is declared in the "main" function....
Maybe for you guys it is a very simple task, but I am very new to VALA...
Thanks alot...
You should wrap your app into a class, store 'txtKey' as instance
variable and make 'on_btnProc_clicked' non-static. Make sure that you
change the name of the callback function to 'my_app_on_btnProc_clicked'
in Glade. And don't forget the [CCode ...] attribute, otherwise it won't
work:
-----------------------------------------
using Gtk;
public class MyApp {
private Window window;
private TextView txtKey;
public MyApp () throws Error {
var builder = new Builder ();
builder.add_from_file ("Repositor.ui");
builder.connect_signals (this);
this.window = builder.get_object ("win_main") as Window;
this.txtKey = builder.get_object ("txtKey") as TextView;
this.window.destroy += Gtk.main_quit;
}
public void run () {
this.window.show_all ();
Gtk.main ();
}
[CCode (instance_pos = -1)]
public void on_btnProc_clicked (Button source) {
source.label = "Thank you!";
// Gtk.main_quit ();
this.txtKey.hide ();
}
}
int main (string[] args) {
Gtk.init (ref args);
try {
var app = new MyApp ();
app.run ();
} catch (Error e) {
stderr.printf ("Could not load UI: %s\n", e.message);
return 1;
}
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]