【发布时间】:2016-01-16 00:37:14
【问题描述】:
当我将 selection_changed 连接到 FileChooserButton 中的函数。在...的帮助下 SO 用户我现在了解 selection_changed 语法。但奇怪的是 当我在同一个程序中第二次使用它时发生。
上下文
我的目标是创建一个带有两个 FileChooserButtons 和一个 Entry 文本的窗口 在窗口的结束位置。第一个 FileChooserButton 帮助 用户选择目录并导致第二个 FileChooserButton 打开 用户在第一个目录中选择的目录。到目前为止,代码 工作正常。该条目也被正确绘制并显示“Here go 文件名”。预期的行为是在 检查后在第二个 FileChooserButton 中选择文件名 文件是否可写。
我使用的策略是将 selection_changed 连接到一个函数 负责检查文件是否可写以及文件的更改 条目的文本。
问题是该函数从未被调用。我添加了一个调试笨蛋 代码如下:
stdout.printf("Checking whether this function is actually called")
它永远不会被打印出来,因此我想这个函数永远不会被调用。有问题的函数是下面的file_changed。
[indent=4]
uses
Gtk
class TestWindow:Window
_file_chooser:FileChooserButton
_entry:Gtk.Entry
construct()
title = "File chooser"
window_position = WindowPosition.CENTER
destroy.connect( Gtk.main_quit )
var folder_chooser = new FileChooserButton("Choose a Folder",FileChooserAction.SELECT_FOLDER)
folder_chooser.set_current_folder( Environment.get_home_dir() )
folder_chooser.selection_changed.connect( folder_changed )
_file_chooser = new FileChooserButton("Choose a File",FileChooserAction.OPEN)
_file_chooser.set_current_folder( Environment.get_home_dir() )
_file_chooser.selection_changed.connect( file_changed )
var _entry = new Gtk.Entry()
_entry.set_text("Here the file name")
var box = new Box( Orientation.VERTICAL, 0 )
box.pack_start( folder_chooser, true, true, 0 )
box.pack_start( _file_chooser, true, true, 0 )
box.pack_start( _entry, true, true, 0 )
add( box )
def folder_changed( folder_chooser_widget:FileChooser )
folder:string = folder_chooser_widget.get_uri()
_file_chooser.set_current_folder_uri( folder )
def file_changed ( file_chooser_widget: FileChooser )
stdout.printf(file_chooser_widget.get_filename())
stdout.printf("Checking whether this function is actually called")
file:File = File.new_for_uri(file_chooser_widget.get_filename())
stdout.printf(file_chooser_widget.get_filename())
info:FileInfo = file.query_info (FileAttribute.ACCESS_CAN_WRITE, FileQueryInfoFlags.NONE, null)
writable:bool = info.get_attribute_boolean (FileAttribute.ACCESS_CAN_WRITE)
stdout.printf(writable.to_string())
if writable is true
_entry.set_sensitive(false)
init
Gtk.init( ref args )
var test = new TestWindow()
test.show_all()
Gtk.main()
问题
- 为什么第二个 selection_changed 调用不起作用?是否 带有 Action.OPEN 的 FileChooserButton 与带有 Action.OPEN 的行为不同 SELECT_FOLDER 操作?
【问题讨论】:
-
您希望何时发送信号,当用户单击文件列表中的某个项目但仍在按钮打开的对话框中工作时,或者当用户单击按钮时关闭选择器对话框?
-
当他点击按钮关闭它时。
-
那么你不想使用
selection-changed信号;那是在更改列表中的选择时。相反,您需要file-set信号(特定于 GtkFileChooserButton)。