在FXRuby;如何在打开时将FXFileDialog
设置为主目录?
答案 0 :(得分: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 + "/")
}
这里,第一个参数是拥有对话框的窗口,第二个是窗口的标题,第三个是开始的默认路径(最后需要“/”,否则它会在选择用户的主文件夹的情况下启动更高的目录。有关FXFileDialog的更多信息,请查看this link。