PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/script_binding/lua/demo_dialog.lua

http://ftk.googlecode.com/
Lua | 92 lines | 74 code | 18 blank | 0 comment | 3 complexity | d07519a0b0573e26fa76e19501be1560 MD5 | raw file
 1function OnQuit(button)
 2	Ftk.Quit()
 3	return RET_OK
 4end
 5
 6function OnNormalQuit(button)
 7	print("OnNormalQuit")
 8	button:Toplevel():Unref();
 9	return RET_OK;
10end
11
12function OnModalQuit(button)
13	print("OnModalQuit")
14	return RET_QUIT;
15end
16
17function CreateDialog(modal)
18	dialog=FtkDialog.Create(0, 40, 320, 240)
19	dialog:SetAnimationHint("dialog")
20	width=dialog:Width()
21	height=dialog:Height()
22
23	theme=Ftk.DefaultTheme()
24	icon=theme:LoadImage("info.png")
25	dialog:SetIcon(icon)
26
27	label=FtkLabel.Create(dialog, width/6, height/4, 5*width/6, 20)
28	label:SetText("Are you sure to quit?")
29	
30	button=FtkButton.Create(dialog, width/6, height/2, width/3, 50)
31	button:SetText("yes")
32	if modal==1 then
33		button:SetClickedListener("OnModalQuit")
34	else
35		button:SetClickedListener("OnNormalQuit")
36	end
37	button=FtkButton.Create(dialog, width/2, height/2, width/3, 50)
38	button:SetText("no")
39	if modal==1 then
40		button:SetClickedListener("OnModalQuit")
41	else
42		button:SetClickedListener("OnNormalQuit")
43	end
44
45	dialog:ShowAll(1)
46	if modal==1 then
47		dialog:Run()
48		dialog:Unref()
49		print("DialogQuit");
50	end
51end
52
53function OnNormal(button)
54	CreateDialog(0)
55	return RET_OK
56end
57
58function OnModal(button)
59	CreateDialog(1)
60	return RET_OK
61end
62
63function AppInit()
64	win=FtkAppWindow.Create()
65	win:SetText("Demo dialog")
66	win:SetAttr(FTK_ATTR_QUIT_WHEN_CLOSE)
67
68	local width=win:Width()
69	local height=win:Height()
70
71	button=FtkButton.Create(win, 0, height/6, width/3, 50)
72	button:SetText("Norma")
73	button:SetClickedListener("OnNormal")
74
75	button=FtkButton.Create(win, 2*width/3, height/6, width/3, 50)
76	button:SetText("Model")
77	button:SetClickedListener("OnModal")
78
79	button=FtkButton.Create(win, width/4, height/2, width/2, 60)
80	button:SetText("quit")
81	button:SetClickedListener("OnQuit")
82	
83	win:SetFocus(button)
84	win:ShowAll(1)
85
86	return 1
87end
88
89Ftk.Init(1, {"dialog"})
90AppInit()
91Ftk.Run()
92