在FXRuby中,如何将FXFileDialog
设置为在打开时位于主目录中?
发布于 2008-09-03 02:26:42
这是一种非常懒惰的方式:
#!/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。
https://stackoverflow.com/questions/41024
复制相似问题