Rename REAMDE to README.md
[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 quit_gtk
37 else if sender == but_cancel then
38 print "cancel!"
39 quit_gtk
40 else
41 print sender
42 end
43
44 end
45
46 init
47 do
48 init_gtk
49
50 win = new GtkWindow(new GtkWindowType.toplevel)
51 win.connect_destroy_signal_to_quit
52
53 container = new GtkGrid
54 win.add( container )
55
56 lbl = new GtkLabel( "Hello world" )
57 container.add( lbl )
58
59 but_ok = new GtkButton.from_stock( "OK" )
60 but_ok.signal_connect( "clicked", self, "ok" )
61 container.add( but_ok )
62
63 but_cancel = new GtkButton.from_stock( "Cancel" )
64 but_cancel.signal_connect( "clicked", self, null )
65 container.add( but_cancel )
66
67 win.show_all
68 end
69 end
70
71 if "NIT_TESTING".environ != "true" then
72 var app = new MyApp
73 run_gtk
74 end