PageRenderTime 42ms CodeModel.GetById 20ms app.highlight 5ms RepoModel.GetById 15ms app.codeStats 1ms

/script_binding/lua/demo_file_browser.lua

http://ftk.googlecode.com/
Lua | 90 lines | 72 code | 18 blank | 0 comment | 0 complexity | adba3e3d90f01828c3741f0b0bb440fc 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 OnChoosed(index, str)
18	local info=FtkFileInfo.Create();
19	FtkFile.GetInfo(str, info);
20	print(info.name .. " mime:" .. FtkFile.GetMimeType(str));
21
22end
23
24function CreateSingle()
25	s=FtkFileBrowser.Create(FTK_FILE_BROWER_SINGLE_CHOOSER)
26	s:SetChoosedHandler("OnChoosed")
27	s:SetPath("/")
28	s:Load()
29	FtkWidget.ShowAll(s, 1)
30end
31
32function CreateMulti()
33	s=FtkFileBrowser.Create(FTK_FILE_BROWER_MULTI_CHOOSER)
34	s:SetChoosedHandler("OnChoosed")
35	s:SetPath("/")
36	s:Load()
37	FtkWidget.ShowAll(s, 1)
38end
39
40function OnNormal(button)
41	CreateSingle()
42	return RET_OK
43end
44
45function OnModal(button)
46	CreateMulti();
47	return RET_OK
48end
49
50function AppInit()
51	win=FtkAppWindow.Create()
52	win:SetText("Demo dialog")
53	win:SetAttr(FTK_ATTR_QUIT_WHEN_CLOSE)
54
55	local width=win:Width()
56	local height=win:Height()
57
58	button=FtkButton.Create(win, 0, height/6, width/3, 50)
59	button:SetText("Norma")
60	button:SetClickedListener("OnNormal")
61
62	button=FtkButton.Create(win, 2*width/3, height/6, width/3, 50)
63	button:SetText("Model")
64	button:SetClickedListener("OnModal")
65
66	button=FtkButton.Create(win, width/4, height/2, width/2, 60)
67	button:SetText("quit")
68	button:SetClickedListener("OnQuit")
69	
70	win:SetFocus(button)
71	win:ShowAll(1)
72
73	local dir=FtkDir.Open("/");
74	local info=FtkFileInfo.Create();
75	FtkDir.Read(dir, info);
76	print(info.name);
77	FtkDir.Read(dir, info);
78	print(info.name);
79	FtkDir.Read(dir, info);
80	print(info.name);
81	dir.Close()
82	
83	FtkFs.CreateDir("./testa");
84	return 1
85end
86
87Ftk.Init(1, {"dialog"})
88AppInit()
89Ftk.Run()
90