iup_progress_dialog.e 6.2 KB

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