FXRuby FXFile对话框默认目录

发布于 2024-07-04 20:41:31 字数 62 浏览 8 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪菊怪哟 2024-07-11 20:41:32

这是一种非常懒惰的方法:

#!/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 的更多信息,请查看此链接

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文