
require 'MasterFrame.rb'
require 'StateMachine.rb'
require 'gui_states.rb'



def main

    init_system_settings()

    root = TkRoot.new { title "Nephros H2H" }
    top = MasterFrame.new(root)
    
    gui_states = create_gui_states(top)
    machine = GuiMachine.new( "Gui", gui_states )
    
    $error_state = TkVariable.new
    $error_msg   = TkVariable.new
    top.error_check.variable     $error_state
    top.error_msg  .textvariable $error_msg
    top.error_check.command{
        machine.on_event($error_state.value=="0" ? "error_cleared" : "error")
    }
    
    machine.run
    
    top.help_button.command{
        p 'Threads-----------------'
        Thread.list.each{|t| p t.to_s + " " + t.status}
        p ''
    }
    
    
    Tk.pack(top)
    Tk.mainloop
    
end

def error_state
    $error_state.value != "0"
end
def error_msg
    $error_msg.value
end

def init_system_settings
    Thread.abort_on_exception = true
end



main