I'm using Glade-3 for my GUI design, but I keep hitting this problem. I don't see anything in the GTK+ documentation mapping signals to events or in Glade-3 (3.4.5). Is there a place in the GTK+ source code to find this information?
我正在使用Glade-3进行GUI设计,但我一直在遇到这个问题。我没有看到GTK +文档中的任何信息将信号映射到事件或Glade-3(3.4.5)。 GTK +源代码中是否有地方可以找到这些信息?
Note: It is important in this question to recognize that events and signals are NOT the same thing in GTK.
注意:在这个问题中,重要的是要认识到事件和信号在GTK中并不相同。
Example:
I have an eventbox that requires the following events in order to receive the following signals. How do I determine what events are required by a given signal?
我有一个事件框,需要以下事件才能收到以下信号。如何确定给定信号所需的事件?
Events: GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK
Signals: leave_notify_event, enter_notify_event
3 个解决方案
#1
Ok, I think I know what you mean now, I found this table matching up the gtk signals and gdk events. Here it is.
好吧,我想我现在知道你的意思了,我发现这个表匹配了gtk信号和gdk事件。这里是。
#2
Assuming that I have interpreted your question correctly you are wanting to connect the signals you specified in the Glade file to the functions in the source code. How you do this depends if you are using libglade to load the files generate or GtkBuilder, both are similar but I will give samples in C just to be complete.
假设我已正确解释您的问题,您希望将您在Glade文件中指定的信号连接到源代码中的函数。如何执行此操作取决于您是否使用libglade加载文件generate或GtkBuilder,两者都相似,但我会在C中提供样本以便完成。
Using libglade you would do it like so:
使用libglade你会这样做:
GladeXml *xml = glade_xml_new(filename, NULL, NULL); // Load the file
glade_xml_signal_autoconnect(xml); // Connect the signals
Using GtkBuilder it would be like this:
使用GtkBuilder就像这样:
GtkBuilder *xml = gtk_builder_new();
gtk_builder_add_from_file(xml, filename, NULL); // Load the file
gtk_builder_connect_signals(xml, NULL); // Connect the signals
When using GtkBuilder the second parameter in signal connect function can be replaced with a pointer to data which will then be passed to the signal handlers.
使用GtkBuilder时,信号连接功能中的第二个参数可以用指向数据的指针替换,然后将数据传递给信号处理程序。
Going forward I would suggest using GtkBuilder as libglade is on its way to being deprecated.
展望未来我建议使用GtkBuilder,因为libglade正在被弃用。
Links
Here are the links to the relevent documentation about the two functions mentioned above
以下是有关上述两个功能的相关文档的链接
#3
You can capture the events with gdk_event_handler_set()
您可以使用gdk_event_handler_set()捕获事件
First register your own GDK event handler on startup:
首先在启动时注册您自己的GDK事件处理程序:
gdk_event_handler_set(my_gdk_event_handler, NULL, NULL);
... Then use it to print out any useful information, and don't forget to pass the event to GTK+ through gtk_main_do_event()
like here:
...然后使用它打印出任何有用的信息,不要忘记通过gtk_main_do_event()将事件传递给GTK +,如下所示:
void my_gdk_event_handler(GdkEvent *event, gpointer data)
{
printf("Received GdkEvent of type %d", event->type);
gtk_main_do_event(event); // Pass event to GTK+
}
#1
Ok, I think I know what you mean now, I found this table matching up the gtk signals and gdk events. Here it is.
好吧,我想我现在知道你的意思了,我发现这个表匹配了gtk信号和gdk事件。这里是。
#2
Assuming that I have interpreted your question correctly you are wanting to connect the signals you specified in the Glade file to the functions in the source code. How you do this depends if you are using libglade to load the files generate or GtkBuilder, both are similar but I will give samples in C just to be complete.
假设我已正确解释您的问题,您希望将您在Glade文件中指定的信号连接到源代码中的函数。如何执行此操作取决于您是否使用libglade加载文件generate或GtkBuilder,两者都相似,但我会在C中提供样本以便完成。
Using libglade you would do it like so:
使用libglade你会这样做:
GladeXml *xml = glade_xml_new(filename, NULL, NULL); // Load the file
glade_xml_signal_autoconnect(xml); // Connect the signals
Using GtkBuilder it would be like this:
使用GtkBuilder就像这样:
GtkBuilder *xml = gtk_builder_new();
gtk_builder_add_from_file(xml, filename, NULL); // Load the file
gtk_builder_connect_signals(xml, NULL); // Connect the signals
When using GtkBuilder the second parameter in signal connect function can be replaced with a pointer to data which will then be passed to the signal handlers.
使用GtkBuilder时,信号连接功能中的第二个参数可以用指向数据的指针替换,然后将数据传递给信号处理程序。
Going forward I would suggest using GtkBuilder as libglade is on its way to being deprecated.
展望未来我建议使用GtkBuilder,因为libglade正在被弃用。
Links
Here are the links to the relevent documentation about the two functions mentioned above
以下是有关上述两个功能的相关文档的链接
#3
You can capture the events with gdk_event_handler_set()
您可以使用gdk_event_handler_set()捕获事件
First register your own GDK event handler on startup:
首先在启动时注册您自己的GDK事件处理程序:
gdk_event_handler_set(my_gdk_event_handler, NULL, NULL);
... Then use it to print out any useful information, and don't forget to pass the event to GTK+ through gtk_main_do_event()
like here:
...然后使用它打印出任何有用的信息,不要忘记通过gtk_main_do_event()将事件传递给GTK +,如下所示:
void my_gdk_event_handler(GdkEvent *event, gpointer data)
{
printf("Received GdkEvent of type %d", event->type);
gtk_main_do_event(event); // Pass event to GTK+
}