Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / test_gtk.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2011-2013 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 import gtk
18
19 class MyApp
20 super GtkCallable
21
22 var win : GtkWindow is noinit
23
24 var container : GtkContainer is noinit
25
26 var lbl : GtkLabel is noinit
27 var but_ok : GtkButton is noinit
28 var but_cancel : GtkButton is noinit
29
30 redef fun signal( sender, user_data )
31 do
32 if user_data != null then print "Userdata: {user_data}"
33
34 if sender == but_ok then
35 print "ok!"
36 gtk_main_quit
37 else if sender == but_cancel then
38 print "cancel!"
39 gtk_main_quit
40 else
41 print sender
42 end
43 end
44
45 init
46 do
47 gtk_init
48
49 win = new GtkWindow(new GtkWindowType.toplevel)
50 win.connect_destroy_signal_to_quit
51
52 container = new GtkGrid
53 win.add( container )
54
55 lbl = new GtkLabel( "Hello world" )
56 container.add( lbl )
57
58 but_ok = new GtkButton.from_stock( "OK" )
59 but_ok.signal_connect( "clicked", self, "ok" )
60 container.add( but_ok )
61
62 but_cancel = new GtkButton.from_stock( "Cancel" )
63 but_cancel.signal_connect( "clicked", self, null )
64 container.add( but_cancel )
65
66 win.show_all
67 end
68 end
69
70 if "NIT_TESTING".environ != "true" then
71 var app = new MyApp
72 gtk_main
73 end