FXRuby FXFileDialog框默认目录

时间:2020-03-05 18:46:51  来源:igfitidea点击:

在FXRuby中;打开时,如何将FXFileDialog设置在主目录中?

解决方案

回答

这是一种极其懒惰的方法:

#!/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的更多信息。