2008-09-03 63 views

回答

1

這裏是一個非常懶惰的方式做到這一點:

#!/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 

這依賴於你是在* nix框(或具有$ HOME環境變量設置)。那具體回答你的問題的範圍有:

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

在這裏,第一個參數是擁有對話框的窗口,第二個是窗口的標題,第三個是開始在默認路徑(你最後需要「/」,否則它會在用戶的主文件夾被選中時啓動一個更高的目錄)。查看this link瞭解關於FXFileDialog的更多信息。