1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
// valac -X -w --pkg gtk+-3.0 n.vala
using Gtk;
public class ong {
public Gtk.Button btn { get; set; }
public Gtk.Label lab { get; set; }
public string str { get; set; }
public void cre(int valeur,Gtk.Notebook ou) {
this.str=valeur.to_string();
this.btn=new Gtk.Button.with_label("button "+this.str);
this.btn.clicked.connect( (b)=> { print(b.get_label()+"\n"); } );
this.lab=new Gtk.Label("page "+str);
ou.append_page(this.btn,this.lab);
}
public void aff(Gtk.Notebook ou) {
print( "page "+ou.get_current_page().to_string()+
" "+this.btn.get_label()+
" "+btn.get_label()+
" str "+this.str+"\n" );
}
}
int main(string[] args) {
Gtk.init(ref args);
Gtk.Window win=new Gtk.Window();
win.set_default_size(640,320);
win.destroy.connect(() => { Gtk.main_quit(); });
Gtk.Grid grid=new Gtk.Grid();
Gtk.Notebook ntb=new Gtk.Notebook();
ntb.switch_page.connect( ( w,np ) => {
print( "page "+np.to_string()+
" from "+ntb.get_current_page().to_string()+"\n" );
});
ong ntab=new ong();
for ( int n=0;n<3;n++ ) { ntab.cre(n,ntb); }
grid.attach(ntb,0,0,1,1);
Gtk.Button cde=new Gtk.Button.with_label("view");
cde.clicked.connect( () => { ntab.aff(ntb); });
grid.attach(cde,0,1,1,1);
win.add(grid);
win.show_all();
Gtk.main();
return 0;
} |
Partager