/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

  1. function OnQuit(button)
  2. Ftk.Quit()
  3. return RET_OK
  4. end
  5. function OnNormalQuit(button)
  6. print("OnNormalQuit")
  7. button:Toplevel():Unref();
  8. return RET_OK;
  9. end
  10. function OnModalQuit(button)
  11. print("OnModalQuit")
  12. return RET_QUIT;
  13. end
  14. function OnChoosed(index, str)
  15. local info=FtkFileInfo.Create();
  16. FtkFile.GetInfo(str, info);
  17. print(info.name .. " mime:" .. FtkFile.GetMimeType(str));
  18. end
  19. function CreateSingle()
  20. s=FtkFileBrowser.Create(FTK_FILE_BROWER_SINGLE_CHOOSER)
  21. s:SetChoosedHandler("OnChoosed")
  22. s:SetPath("/")
  23. s:Load()
  24. FtkWidget.ShowAll(s, 1)
  25. end
  26. function CreateMulti()
  27. s=FtkFileBrowser.Create(FTK_FILE_BROWER_MULTI_CHOOSER)
  28. s:SetChoosedHandler("OnChoosed")
  29. s:SetPath("/")
  30. s:Load()
  31. FtkWidget.ShowAll(s, 1)
  32. end
  33. function OnNormal(button)
  34. CreateSingle()
  35. return RET_OK
  36. end
  37. function OnModal(button)
  38. CreateMulti();
  39. return RET_OK
  40. end
  41. function AppInit()
  42. win=FtkAppWindow.Create()
  43. win:SetText("Demo dialog")
  44. win:SetAttr(FTK_ATTR_QUIT_WHEN_CLOSE)
  45. local width=win:Width()
  46. local height=win:Height()
  47. button=FtkButton.Create(win, 0, height/6, width/3, 50)
  48. button:SetText("Norma")
  49. button:SetClickedListener("OnNormal")
  50. button=FtkButton.Create(win, 2*width/3, height/6, width/3, 50)
  51. button:SetText("Model")
  52. button:SetClickedListener("OnModal")
  53. button=FtkButton.Create(win, width/4, height/2, width/2, 60)
  54. button:SetText("quit")
  55. button:SetClickedListener("OnQuit")
  56. win:SetFocus(button)
  57. win:ShowAll(1)
  58. local dir=FtkDir.Open("/");
  59. local info=FtkFileInfo.Create();
  60. FtkDir.Read(dir, info);
  61. print(info.name);
  62. FtkDir.Read(dir, info);
  63. print(info.name);
  64. FtkDir.Read(dir, info);
  65. print(info.name);
  66. dir.Close()
  67. FtkFs.CreateDir("./testa");
  68. return 1
  69. end
  70. Ftk.Init(1, {"dialog"})
  71. AppInit()
  72. Ftk.Run()