Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 010-TimerDemo.rbw
# K:\_Projects\Ruby\_Ruby_Technologies\FX-Ruby\002-FxRubySimpleExamples
# Source: Item 2 @ http://groups.google.com/group/fxruby-google/tree/browse_frm/thread/40a67540b556c044/07dc2fc50395968f?rnum=1&q=FXRuby&_done=%2Fgroup%2Ffxruby-google%2Fbrowse_frm%2Fthread%2F40a67540b556c044%2F07dc2fc50395968f%3Ftvc%3D1%26q%3DFXRuby%26#doc_c1255c247cc60a1e

# NOTE: As written, FXRuby.rbw:
#  presents a "TimerDemo" taskbar entry
#  presnts a static progress bar centered on the screen
#  and loops apparently infinitely.

# require/include's added: RLM
require 'fox16'
include Fox

class ProgressDlg < FXMainWindow
  def initialize(app, caption, text)
    @app = app
    super(@app, caption, :opts => DECOR_NONE, :width => 520, :height => 40)

    FXLabel.new(self, text, :opts => LAYOUT_FILL_X | JUSTIFY_CENTER_X)
    @bar = FXProgressBar.new(self, :opts => PROGRESSBAR_NORMAL | LAYOUT_FILL_X)
  end

  def create
    super
    show(PLACEMENT_SCREEN)
  end

  def run(limit = 100)
    @bar.setTotal(limit)
    @bar.setProgress(0)

    @app.addTimeout(1000, method(:progress_update))
  end

  def progress_update(sender, selector, data)
    @bar.increment(1)

    if @bar.progress == @bar.total
      self.close(true)
    else
      @app.addTimeout(1000, method(:progress_update))
    end
  end
end 

# Startup code added # RLM
if __FILE__ == $0
  FXApp.new() do |theApp|
    ProgressDlg.new(theApp, "TimerDemo", "1234567890abcdefghijklmnopqrstuvwxyz")
    theApp.create
    theApp.run
  end
end