将文件选择器对话框与glade一起使用

发布于 2024-12-19 09:51:33 字数 660 浏览 2 评论 0原文

我想问是否有人知道如何在glade和pygtk中使用文件选择器对话框。 (它在任何语言绑定中都应该非常相似,这就是为什么我没有指定语言。)基本上,文件选择器现在看起来像这样:有两列,一列用于文件夹(左),一列用于文件夹对于文件(右)。然后在对话框的底部,有两个空插槽可容纳两个按钮,所以我只是在那里放置了一个取消按钮和一个确定按钮。但我的问题是对话框返回什么?我的代码如下所示:

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

目前,对“取消”和“确定”的回调只是隐藏对话框。但我无法找出对话框应该返回什么。换句话说,如何在响应中指定是否按下了“取消”或“确定”按钮?

谢谢,

v923z

PS:这是一张图片来说明情况:

在此处输入图片描述

I would like to ask if anyone knows how to use the filechooser dialog in glade and pygtk. (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. 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

PS: Here is an image to illustrate the situation:

enter image description here

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

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

发布评论

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

评论(1

浅紫色的梦幻 2024-12-26 09:51:33

带有按钮的对话框返回与按下的按钮关联的响应 ID。就您而言,当您创建“取消”时林间空地和花园中的“确定”按钮将它们放入文件选择器对话框中可用的空槽中,在编辑框(屏幕右下角,标题为“按钮属性...”)中,您可以看到响应 ID: 常规选项卡下的选项(其默认值为 0 的旋转按钮)。只需将其设置为按下该按钮时您想要接收的值即可。为不同的按钮设置不同的值。现在,当您运行对话框并按下按钮时,您将获得您设置的响应 ID 值。在此基础上您可以采取行动。
希望这有帮助!

Dialog with buttons returns the response id which is associated with the button pressed. 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. 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. Based on this you can take your actions.
Hope this helps!

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