example6.e 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. class EXAMPLE6
  2. -- This example show how use a progress bar with a sequencer.
  3. insert
  4. IUP_INTERFACE
  5. create {ANY}
  6. make
  7. feature {ANY}
  8. pb: IUP_PROGRESS_BAR
  9. counter: INTEGER
  10. lm: LOOP_STACK
  11. time: MICROSECOND_TIME
  12. make
  13. local
  14. bt: IUP_BUTTON
  15. a: ARRAY[IUP_WIDGET]
  16. vb: IUP_VBOX
  17. i: STRING
  18. w: IUP_DIALOG
  19. gui: IUP
  20. do
  21. gui := iup_open
  22. create pb.progress_bar
  23. create bt.button("Starts")
  24. bt.set_cb_action(agent bar(?))
  25. a := {ARRAY[IUP_WIDGET] 1, << pb, bt >>}
  26. create vb.vbox(a)
  27. vb.set_alignment("ACENTER")
  28. vb.set_gap(10)
  29. vb.set_margin(10, 10)
  30. create w.dialog(vb)
  31. w.set_title("Progress bar")
  32. i := w.show
  33. gui.main_loop
  34. gui.close
  35. end
  36. bar (widget: IUP_BUTTON): STRING
  37. local
  38. ls: STRING
  39. do
  40. -- These three lines are used to return the progress bar to
  41. -- 0, if the user press the button again. But of course,
  42. -- these are not always necessary.
  43. counter := 0
  44. pb.set_value(0.to_real_64)
  45. ls := iup_open.loop_step
  46. time.update
  47. create lm.make
  48. lm.add_job(create {SIMPLE_PERIODIC_JOB}.set_work(agent progress_bar,
  49. Void, 0, 1))
  50. lm.run
  51. Result := "IUP_DEFAULT"
  52. end
  53. progress_bar: BOOLEAN
  54. local
  55. r: REAL_64
  56. ls: STRING
  57. do
  58. ls := iup_open.loop_step -- Update the interface.
  59. r := counter.to_real_64 / 10.to_real_64
  60. io.put_real(r)
  61. io.put_string("%N")
  62. pb.set_value(r)
  63. ls := iup_open.loop_step -- Update the interface again.
  64. counter := counter + 1 -- Update the counter.
  65. if counter > 10 then
  66. Result := False
  67. else
  68. Result := True
  69. end
  70. end
  71. end