/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

  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 CreateDialog(modal)
  15. dialog=FtkDialog.Create(0, 40, 320, 240)
  16. dialog:SetAnimationHint("dialog")
  17. width=dialog:Width()
  18. height=dialog:Height()
  19. theme=Ftk.DefaultTheme()
  20. icon=theme:LoadImage("info.png")
  21. dialog:SetIcon(icon)
  22. label=FtkLabel.Create(dialog, width/6, height/4, 5*width/6, 20)
  23. label:SetText("Are you sure to quit?")
  24. button=FtkButton.Create(dialog, width/6, height/2, width/3, 50)
  25. button:SetText("yes")
  26. if modal==1 then
  27. button:SetClickedListener("OnModalQuit")
  28. else
  29. button:SetClickedListener("OnNormalQuit")
  30. end
  31. button=FtkButton.Create(dialog, width/2, height/2, width/3, 50)
  32. button:SetText("no")
  33. if modal==1 then
  34. button:SetClickedListener("OnModalQuit")
  35. else
  36. button:SetClickedListener("OnNormalQuit")
  37. end
  38. dialog:ShowAll(1)
  39. if modal==1 then
  40. dialog:Run()
  41. dialog:Unref()
  42. print("DialogQuit");
  43. end
  44. end
  45. function OnNormal(button)
  46. CreateDialog(0)
  47. return RET_OK
  48. end
  49. function OnModal(button)
  50. CreateDialog(1)
  51. return RET_OK
  52. end
  53. function AppInit()
  54. win=FtkAppWindow.Create()
  55. win:SetText("Demo dialog")
  56. win:SetAttr(FTK_ATTR_QUIT_WHEN_CLOSE)
  57. local width=win:Width()
  58. local height=win:Height()
  59. button=FtkButton.Create(win, 0, height/6, width/3, 50)
  60. button:SetText("Norma")
  61. button:SetClickedListener("OnNormal")
  62. button=FtkButton.Create(win, 2*width/3, height/6, width/3, 50)
  63. button:SetText("Model")
  64. button:SetClickedListener("OnModal")
  65. button=FtkButton.Create(win, width/4, height/2, width/2, 60)
  66. button:SetText("quit")
  67. button:SetClickedListener("OnQuit")
  68. win:SetFocus(button)
  69. win:ShowAll(1)
  70. return 1
  71. end
  72. Ftk.Init(1, {"dialog"})
  73. AppInit()
  74. Ftk.Run()