
require 'MasterFrame.rb'

require 'FiltrationState.rb'




def main
   
    idle        = QuadState.new("idle")
    prep_filter = QuadState.new("prep")
    prime       = QuadState.new("prime")
    recirculate = QuadState.new("recirculate")
    treatment   = QuadState.new("treatment")
    
    idle.all_events = [
        ["done", proc{|x| p "Now in IDLE DONE handler\n"; prep_filter}],
        ["pause", proc{|x| print "pausing #{idle.name}\n"; nil}]
    ]
    prep_filter.all_events = [
        ["done",  proc{|x| idle}],
        ["pause", proc{|x| print "pausing\n"; nil}]
    ]
   
    Thread.abort_on_exception = true

    machine = StateMachine.new([idle, prep_filter, prime, recirculate, treatment])

    root = TkRoot.new { title "Nephros H2H" }
    top = MasterFrame.new(root)
    Tk.pack(top)
    print "Hello!\n"
    
    top.forw_button.command proc{ machine.on_event("start") }
    top.ok_button.  command proc{ machine.on_event("pause") }
    top.back_button.command proc{ Thread.list.each{|t| p t.status } }
    
    machine.run
    Tk.mainloop
    
    print "Hello"

end


main