tags:

views:

292

answers:

0

I'm trying to spawn a Tk window from ruby script using ruby's Tk module. It works, but I cannot figure out a way to focus the spawned window. It's frustrating. If I run this code from terminal, as in $ruby screenup.rb the window spawns behind the terminal window. If I run as a shell script in Quicksilver, two windows spawn. One is titled as expected, and another is titled 'tk'. Neither of them have focus.

My problem may be more general, in that I basically don't understand how windows are specified in Tk.

TIA for help.

def get_file_name
  require 'tk'
  root = TkRoot.new() { 
    title "Enter the file name"
    Tk.focus_to(@path, true)
    }

  filename = TkVariable.new
  entry = TkEntry.new(root, 'textvariable' => filename) {
    insert(0,"image#{EXT}")
  }
  entry.pack("side"=>"left", "fill"=>"x", "padx"=>5)
  entry.focus
  save = TkButton.new(root) { 
    text "save"
    pack("side"=>"right", "fill"=>"y")
    command proc { root.destroy()}
  }
  root.bind("Return") { root.destroy() }
  Tk.mainloop

  return filename.value
end