简体   繁体   English

在glade中使用filechooser对话框

[英]using the filechooser dialog with glade

I would like to ask if anyone knows how to use the filechooser dialog in glade and pygtk. 我想问问是否有人知道如何在Glade和pygtk中使用filechooser对话框。 (It should be very similar in any of the language bindings, and that is why I didn't specify the language.) Basically, the filechooser now looks like this: there are two columns, one for the folders (left), and one for the files (right). (在任何语言绑定中,它都应该非常相似,这就是为什么我没有指定语言。)基本上,文件选择器现在看起来像这样:有两列,一列用于文件夹(左),一列用于文件(右)。 Then at the bottom of the dialog, there are two empty slots for two buttons, so I just dropped a cancel and an OK button there. 然后,在对话框的底部,有两个按钮的两个空白插槽,因此我只在其中放置了一个cancel和OK按钮。 But then my question is what does the dialog return? 但是,我的问题是对话框返回了什么? My code looks like this: 我的代码如下所示:

    filename = None
    response = self.widget('filechooserdialog').run()
    print response
    #if response == Gtk.RESPONSE_OK: 
    filename = self.widget('filechooserdialog').get_filename()
    self.widget('filechooserdialog').hide()

and at the moment, the callback to 'Cancel' and 'OK' just hides the dialog. 目前,“取消”和“确定”的回调仅隐藏对话框。 But I can't find out what the dialog is supposed to return. 但是我找不到对话框应该返回什么。 In other words, how can I specify in the response whether the 'Cancel', or the 'OK' button was pressed? 换句话说,如何在响应中指定是否按下了“取消”或“确定”按钮?

Thanks, 谢谢,

v923z v923z

PS: Here is an image to illustrate the situation: PS:这是说明情况的图像:

在此处输入图片说明

Dialog with buttons returns the response id which is associated with the button pressed. 带按钮的对话框返回与按下的按钮关联的响应ID。 In your case, when you create your "Cancel" & "Ok" buttons in glade & drop them into empty slot available in the file chooser dialog, in the edit box (right bottom of the screen which will have heading like "Button Properties ...") you can see Response ID: option (its a spin button with default value as 0) under General tab. 在您的情况下,当您在林间空地中创建“取消”和“确定”按钮并将它们放到文件选择器对话框中可用的空白位置时,在编辑框中(屏幕右下角的标题为“按钮属性”)。 ..”),您可以在“ General标签下看到“ Response ID:选项(默认值为0的旋转按钮)。 Just set that to a value you want to receive when that button is pressed. 只需将其设置为要在按下该按钮时要接收的值即可。 Set this as different values for your different buttons. 将此设置为不同按钮的不同值。 Now when you run the dialog and the button is pressed you will get the response id value which you had set. 现在,当您运行对话框并按下按钮时,您将获得已设置的响应ID值。 Based on this you can take your actions. 基于此,您可以采取措施。
Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM