gtk - 在 GtkBuilder XML 的 GtkDialog 中使用预定义的响应 ID?

标签 gtk glade

有没有办法在 GTK_RESPONSE_OK 中使用预定义的响应(例如, GtkDialog ) ,没有对 ID 进行硬编码? Glade 默认生成带有“0”的 XML,并给我一个数字条目。虽然我想我可以输入 -5,但这似乎违背了拥有常数的意义。

Glade XML 如下所示:

<action-widgets>
  <action-widget response="0">cancel-button</action-widget>
  <action-widget response="0">connect-button</action-widget>
</action-widgets>

the example in the docs :
<action-widgets>
  <action-widget response="3">button_ok</action-widget>
  <action-widget response="-5">button_cancel</action-widget>
</action-widgets>

(这有点搞笑,因为他们使用 -5 ( GTK_RESPONSE_OK ) 来表示“button_cancel ”……)

最佳答案

从 GTK 3.12 开始,您可以使用 nck-names 作为响应。

commit baa471ec130c360a5c4ae314769bc7b858814219
Author: Jasper St. Pierre <jstpierre@mecheye.net>
Date:   Mon Oct 28 11:19:43 2013 -0400

  gtkdialog: Allow specifying response IDs by nick in <action-widgets>

  This makes it a lot more convenient for developers, as they don't
  have to look up the numeric value of response IDs.

所以你现在可以做
<action-widgets>
  <action-widget response="ok">button_ok</action-widget>
  <action-widget response="cancel">button_cancel</action-widget>
</action-widgets>

关于gtk - 在 GtkBuilder XML 的 GtkDialog 中使用预定义的响应 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18297382/

相关文章:

c - 如何 "check"GtkCellRendererToggle?

python-3.x - 如何在 GTK 中创建带有弹出菜单的 "HeaderMenu"?

linux - 我修改了GTK源码,重新编译: No effect

python - 如何在自定义 Gtk 小部件中设置最小/首选大小

c - 使用 gtk 的多线程进度条控制

python - 空地或没有空地 : What is the best way to use PyGtk?

c - 在 GTK2 中调整握把大小

python - 将 "primary toolbar"样式类添加到 gtk.Builder 对象后,工具栏中的 gtk.ToolButtons 不是主主题

python - 如何使用glade GUI分发python应用程序?

c - Glade 3 和 C,按钮和文本框的信号处理