iup_progress_dialog.e 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. class IUP_PROGRESS_DIALOG
  2. -- Creates a progress dialog element. It is a predefined dialog for displaying
  3. -- the progress of an operation. The dialog is meant to be shown with the show
  4. -- functions show or show_xy.
  5. --
  6. -- The IUP_PROGRESS_DIALOG will display the iteration state using a
  7. -- IUP_PROGRESS_BAR control.
  8. --
  9. -- The dialog is not automatically closed, the application must do that
  10. -- manually inside the CANCEL_CB callback or inside your processing loop by
  11. -- checking the STATE attribute.
  12. inherit
  13. IUP_DIALOG
  14. redefine
  15. execute_cancel
  16. end
  17. IUP_WIDGET_CUSTOM_ATTRIBUTES
  18. export
  19. {NONE} all
  20. end
  21. create {ANY}
  22. progress_dialog
  23. feature {ANY}
  24. progress_dialog
  25. local
  26. a_progress_dialog: POINTER
  27. do
  28. a_progress_dialog := int_progress_dialog
  29. set_widget(a_progress_dialog)
  30. end
  31. -- Operations
  32. exit_loop
  33. -- Close the loop.
  34. do
  35. iup_open.exit_loop
  36. end
  37. -- Attributes
  38. set_count (value: INTEGER)
  39. -- Set current count of iterations.
  40. do
  41. iup_open.set_attribute(Current, "COUNT", value.out)
  42. end
  43. get_count: INTEGER
  44. -- The current count of iterations.
  45. local
  46. str: STRING
  47. do
  48. str := iup_open.get_attribute(Current, "COUNT")
  49. if str.is_integer then
  50. Result := str.to_integer
  51. end
  52. end
  53. increment (value: INTEGER)
  54. -- (write-only): increment the current count by the given amount.
  55. do
  56. iup_open.set_attribute(Current, "INC", value.out)
  57. end
  58. increment_one
  59. -- (write-only): increment the current count by 1.
  60. do
  61. iup_open.set_attribute(Current, "INC", "1")
  62. end
  63. set_percent (value: INTEGER)
  64. -- Set current percent of iterations.
  65. do
  66. iup_open.set_attribute(Current, "PERCENT", value.out)
  67. end
  68. get_percent: INTEGER
  69. -- The current percent of iterations.
  70. local
  71. str: STRING
  72. do
  73. str := iup_open.get_attribute(Current, "PERCENT")
  74. if str.is_integer then
  75. Result := str.to_integer
  76. end
  77. end
  78. set_total_count (value: INTEGER)
  79. -- Set the total number of iterations.
  80. do
  81. iup_open.set_attribute(Current, "TOTALCOUNT", value.out)
  82. end
  83. set_state (state: STRING)
  84. -- Describe the state of the iteration. Can be: IDLE, PROCESSING,
  85. -- UNDEFINED or ABORTED. Default is IDLE. When INC, COUNT or PERCENT are
  86. -- set the state is changed to PROCESSING. If the user pressed the Cancel
  87. -- button the state is changed to ABORTED, but check the CANCEL_CB
  88. -- callback for other options. If the state is set to UNDEFINED by the
  89. -- application the progress bar will display an undefined state animation
  90. -- (same as setting MARQUEE=True in IUP_PROGRESS_BAR), to resume
  91. -- processing set the state attribute to PROCESSING.
  92. require
  93. is_valid_state(state)
  94. do
  95. iup_open.set_attribute(Current, "STATE", state)
  96. end
  97. get_state: STRING
  98. -- The current state.
  99. do
  100. Result := iup_open.get_attribute(Current, "STATE")
  101. end
  102. set_description (text: STRING)
  103. -- Text description to be shown at the dialog.
  104. do
  105. iup_open.set_attribute(Current, "DESCRIPTION", text)
  106. end
  107. set_progress_bar_height (height: INTEGER)
  108. -- Height in pixels of the progress bar. Default: 30
  109. require
  110. height > 0
  111. do
  112. iup_open.set_attribute(Current, "PROGRESSHEIGHT", height.out)
  113. end
  114. set_minimun_clock (value: INTEGER)
  115. -- Minimum time between counts to an actual screen update in
  116. -- milliseconds. So if each count increment is too fast this avoids
  117. -- updating the screen too often. Default: 250
  118. require
  119. value > 0
  120. do
  121. iup_open.set_attribute(Current, "MINCLOCK", value.out)
  122. end
  123. set_minimun_percent (value: INTEGER)
  124. -- Minimum percent between counts to an actual screen update. So if each
  125. -- count increment is too fast and the minimum clock has not reached yet,
  126. -- but the application would like to update the screen anyway after the
  127. -- percent of the total progress has passed this minimum value. So at
  128. -- least some screen updates will occur. Default: 10
  129. require
  130. value > 0
  131. do
  132. iup_open.set_attribute(Current, "MINPERCENT", value.out)
  133. end
  134. -- Callback
  135. set_cb_cancel (act: detachable FUNCTION[TUPLE[IUP_PROGRESS_DIALOG], STRING])
  136. -- Action generated when the user clicked on the Cancel button.
  137. -- Returns: if different from IUP_CONTINUE then STATE will be changed to
  138. -- ABORTED, same behavior as if the callback does not exist.
  139. local
  140. operation: INTEGER
  141. do
  142. cb_close_dialog := act
  143. if cb_close_dialog /= Void then
  144. operation := 1
  145. else
  146. operation := 0
  147. end
  148. iup_open.set_callback (Current, "CLOSE_CB", "NONEEDED", operation)
  149. end
  150. -- Validations
  151. is_valid_state (value: STRING): BOOLEAN
  152. do
  153. if value.is_equal("IDLE") or
  154. value.is_equal("PROCESSING") or
  155. value.is_equal("UNDEFINED") or
  156. value.is_equal("ABORTED") then
  157. Result := True
  158. else
  159. Result := False
  160. end
  161. end
  162. feature {IUP}
  163. execute_cancel: STRING
  164. do
  165. if attached cb_close_dialog as int_cb then
  166. Result := int_cb.item([Current])
  167. else
  168. Result := "IUP_DEFAULT"
  169. end
  170. end
  171. feature {NONE}
  172. -- Callback
  173. cb_close_dialog: detachable FUNCTION[TUPLE[IUP_PROGRESS_DIALOG], STRING]
  174. -- Internal
  175. int_progress_dialog: POINTER
  176. external
  177. "C inline use %"eiffel-iup.h%""
  178. alias
  179. "return IupProgressDlg ();"
  180. end
  181. end
  182. -- The MIT License (MIT)
  183. -- Copyright (c) 2016, 2017, 2019, 2020 by German A. Arias
  184. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  185. -- of this software and associated documentation files (the "Software"), to deal
  186. -- in the Software without restriction, including without limitation the rights
  187. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  188. -- copies of the Software, and to permit persons to whom the Software is
  189. -- furnished to do so, subject to the following conditions:
  190. --
  191. -- The above copyright notice and this permission notice shall be included in
  192. -- all copies or substantial portions of the Software.
  193. --
  194. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  195. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  196. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  197. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  198. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  199. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  200. -- SOFTWARE.