tags:

views:

58

answers:

1

In FXRuby; how do I set the FXFileDialog to be at the home directory when it opens?

A: 

Here's an exceedingly lazy way to do it:

#!/usr/bin/ruby
require 'rubygems'
require 'fox16'
include Fox

theApp = FXApp.new

theMainWindow = FXMainWindow.new(theApp, "Hello")

theButton = FXButton.new(theMainWindow, "Hello, World!")
theButton.tipText = "Push Me!"

iconFile = File.open("icon.jpg", "rb")
theButton.icon = FXJPGIcon.new(theApp, iconFile.read)
theButton.iconPosition = ICON_ABOVE_TEXT
iconFile.close

theButton.connect(SEL_COMMAND) { 
fileToOpen = FXFileDialog.getOpenFilename(theMainWindow, "window name goes here", `echo $HOME`.chomp + "/")
}

FXToolTip.new(theApp)

theApp.create

theMainWindow.show

theApp.run

This relies on you being on a *nix box (or having the $HOME environment variable set). The lines that specifically answer your question are:

theButton.connect(SEL_COMMAND) { 
fileToOpen = FXFileDialog.getOpenFilename(theMainWindow, "window name goes here", `echo $HOME`.chomp + "/")
}

Here, the first argument is the window that owns the dialog box, the second is the title of the window, and the third is the default path to start at (you need the "/" at the end otherwise it'll start a directory higher with the user's home folder selected). Check out this link for more info on FXFileDialog.

Chris Bunch