FileSelect widget with Tk?

I’m writing a simple little ruby application to munge some files.
I’ve got a command-line version that works like a charm, but I want to
port it over to windows and have it run in a GUI.

I figured I’d use ruby-tk to get it to work. But, I’m running into a
roadblock. In perl/tk, I’m accustomed to using the FileSelect widget
to bring up a file selection dialog. I can’t seem to find a
corresponding widget in the ruby-tk sources.

Could somebody please point me in the right direction?

Thanks,
Samuel

Samuel Tesla wrote:

I’m writing a simple little ruby application to munge some files.
I’ve got a command-line version that works like a charm, but I want to
port it over to windows and have it run in a GUI.

I figured I’d use ruby-tk to get it to work. But, I’m running into a
roadblock. In perl/tk, I’m accustomed to using the FileSelect widget
to bring up a file selection dialog. I can’t seem to find a
corresponding widget in the ruby-tk sources.

Could somebody please point me in the right direction?

Thanks,
Samuel

Hi,

Try something on the lines of…

def fileDialog(op,dir,ext,window)

  ftypes = [
       ["Currently", ext],
       ["Text files", '*txt'],
       ["Midi files", '*mid'],
       ["Backup files", '*~'],
       ["All files", '*']
  ]
 if op == 'open'
   fname = Tk.getOpenFile('filetypes'=> ftypes, 'parent'=> window,
                          'initialdir' => dir
                          )
 else
   fname = Tk.getSaveFile('filetypes' => ftypes,'parent'=> window,
                           'initialdir' => dir,
                           'initialfile' => Composer.new.title,
                           'defaultextension' => ext
                          )
 end
 return fname

Call similar this

file_box = TkFrame.new
dir - directory
ext = file extension required

ftmp = fileDialog(‘open’, dir, ext, file_box)

ftmp is your returned filename

Its from a working application,

Hope this is helpful.

Fraktur

fraktur unc@bogusaddy.org writes:

def fileDialog(op,dir,ext,window)

That code worked beautifully! Thank you very much!

– Samuel