module Misc
  def Misc.get_text(title=nil)

     #debug caller

    #dialog=TkToplevel.new($root)
    dialog= GoWindow.new('get_text')
    dialog.title(tr(title)) if title
    #TkDefaults::GUI['get_text.top'].each_pair {|method,param| dialog.send(method,param) } 

    text= TkVariable.new
    opts=TkDefaults::GUI['get_text.entry'].update({'textvariable'=>text})
    input=TkEntry.new(dialog,opts).pack
    input.bind('Return', proc { yield(text.value);  dialog.destroy } )
    input.focus
  end

def Misc.get_double(one,two)
    dialog= GoWindow.new('get_double')
    vone=TkVariable.new
    vtwo=TkVariable.new
    fr=TkFrame.new(dialog)
    TkLabel.new(fr,'text'=>one).pack('side'=>'left')
    opts=TkDefaults::GUI['get_text.entry'].update({'textvariable'=>vone})
    input=TkEntry.new(fr,opts).pack('side'=>'left')
    input.bind('Return', proc { yield(vone.value,vtwo.value);  dialog.destroy } )
    input.focus
    fr.pack
    fr=TkFrame.new(dialog)
    TkLabel.new(fr,'text'=>two).pack('side'=>'left')
    opts=TkDefaults::GUI['get_text.entry'].update({'textvariable'=>vtwo})
    input=TkEntry.new(fr,opts).pack('side'=>'left')
    input.bind('Return', proc { yield(vone.value,vtwo.value);  dialog.destroy } )
    fr.pack
end

  def Misc.warning(message,type='ok')
#TODO: message should be translated
	$root.raise if $root
     Tk::messageBox( 'icon'=> 'warning', 'message'=> message, 'type'=>type)
  end
  def Misc.ask(message,type='okcancel')
$root.raise
     Tk::messageBox( 'icon'=> 'question', 'message'=> tr(message), 'type'=>type)
  end

  def Misc.info(message,title=nil)
    top= GoWindow.new('info')
    top.title(title) if title
    opts= TkDefaults::GUI['info.text'].update('text'=>message)
    #TkMessage.new(@top,opts).pack
    TkLabel.new(top,opts).pack('fill'=>'both','expand'=>'yes')
    opts= TkDefaults::GUI['info.button.close'].update('command'=>proc{top.destroy})
    TkButton.new(top,opts).pack
	top.raise
  end


=begin
  def Misc.message(message)
    top= GoWindow.new('message')
    opts= TkDefaults::GUI['message.text'].update('text'=>message)
    l=TkLabel.new(top,opts)
    l.pack('fill'=>'both','expand'=>'yes')
    Tk.update
    top
  end
=end



  def Misc.tr(str)
    s= TkDefaults::TR[str] 
    if s
      return s
    else 
#        debug str unless str.empty? 
      return str
    end
  end

end
