通过ESC关闭后再次ÇGTK无法打开对话框 [英] C GTK can't open Dialog again after closing via ESC

查看:337
本文介绍了通过ESC关闭后再次ÇGTK无法打开对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话框,叫 dlg_open btn_cancel_open 按钮。
这个对话框是在布敦,事件和对话框的关闭事件被映射:

I have a Dialog called dlg_open with an btn_cancel_open Button. This dialog is mapped at the Buton-Event and the close Event of the dialog to:

void on_btn_cancel_clicked (GtkWidget *widget, signal_map_data *smd) {
  #ifdef debug
    g_print ("-> on_btn_cancel_clicked\n");
  #endif
  gtk_widget_hide (gtk_widget_get_toplevel (widget) );
  gtk_widget_set_sensitive (smd->widg.wmw.wnd, 1);
}

void on_dlg_close (GtkWidget *widget, signal_map_data *smd) {
  #ifdef debug
    g_print ("-> on_dlg_close\n");
  #endif
  gtk_widget_hide (widget);
  gtk_widget_set_sensitive (smd->widg.wmw.wnd, 1);
}

这工作正常。这里是我打开的对话​​框:

This works fine. And here is how I open the dialog:

void on_btn_open_clicked (GtkWidget *widget, signal_map_data *smd) {
  #ifdef debug
    g_print ("-> on_btn_open_clicked\n");
  #endif
  gtk_widget_set_sensitive (smd->widg.wmw.wnd, 0);
  gtk_widget_show (smd->widg.wdow.dlg_open);
}

我的问题是,当我通过按键 ESC ,我不能再次打开它关闭对话框,在主窗口失去其灵敏度,但该对话框不会出现,并在控制台打印出一个错误信息:

My problem is, that when I close the Dialog via keystroke ESC, I can't open it again, the main window looses its sensitivity, but the dialog doesn't appear, and at the console is a error message printed out:

Gtk-CRITICAL **: gtk_widget_show: assertion 'GTK_IS_WIDGET (widget)' failed

当我通过取消按钮关闭对话框 ITT工作正常,我可以重新打开对话窗口。

When I close the dialog via the cancel-button itt works fine and I can reopen the dialog window.

只是一个问题的 ESC

但是,在/为什么?

编辑根据 andlabs 的答案:(!!已更新!!)

EDIT ACCORDING TO andlabs ANSWER: (!!UPDATED!!)

我从 on_dlg_close 函数改为响应管理​​功能:

I changed from a on_dlg_close function to a response management function:

void on_dlg_response (GtkDialog *dlg, gint r_id, signal_map_data *smd) {
  #ifdef debug
    g_print ("-> on_dlg_response\n");
  #endif
  switch (r_id) {
    case GTK_RESPONSE_DELETE_EVENT: {
      gtk_widget_hide (dlg);
      gtk_widget_set_sensitive (smd->widg.wmw.wnd, 1);
    }
  }
}

我还添加了删除事件

gboolean on_dlg_delete (GtkWidget *widget, GdkEvent *event, signal_map_data *smd) {
  #ifdef debug
    g_print ("-> on_dlg_delete\n");
  #endif
  return FALSE;
}

这里

这也适用于关闭与ESC对话框。但是,仍然有,当我通过 ESC 按钮具有同样的错误关闭它,我不能重新打开的对话​​框中同样的问题:

This also works to close the dialog with ESC. But there is still the same problem that I can't reopen the dialog when I closed it via ESC Button with same error:

- > on_dlg_response

-> on_dlg_response

- > on_dlg_delete

-> on_dlg_delete

- > on_btn_add_clicked

-> on_btn_add_clicked

(主:16478):GLib的-的GObject-WARNING **:在投给GtkLabel的无效unclassed指针

(main:16478): GLib-GObject-WARNING **: invalid unclassed pointer in cast to 'GtkLabel'

(主:16478):GTK的CRITICAL **:gtk_label_set_text:断言GTK_IS_LABEL(标签)'失败

(main:16478): Gtk-CRITICAL **: gtk_label_set_text: assertion 'GTK_IS_LABEL (label)' failed

(主:16478):GTK的CRITICAL **:gtk_widget_show:断言GTK_IS_WIDGET(部件)'失败

(main:16478): Gtk-CRITICAL **: gtk_widget_show: assertion 'GTK_IS_WIDGET (widget)' failed

如何解决这个问题呢?

推荐答案

您不想连接到关闭;这就是 Escape键的存在pressed。相反,连接到响应,并检查已知的响应。

You don't want to connect to close; that's only for the Escape key being pressed. Instead, connect to response and check for known responses.

一个GtkDialog是的GtkWindow;默认情况下,当您单击关闭按钮,它被摧毁。您将需要连接到删除事件来规避这种行为。 ( gtk_dialog_run()可以实现这个要求,这就是为什么点击与功能,而不是手动不会破坏小部件一个对话框,运行的关闭按钮。当然了,重写只需要在呼叫的持续时间的效果。)

A GtkDialog is a GtkWindow; by default, when you click the Close button, it is destroyed. You will need to connect to delete-event to circumvent this behavior. (gtk_dialog_run() does this for you, which is why clicking the Close button on a dialog run with that function instead of manually doesn't destroy the widget. Of course, the override only takes effect for the duration of the call.)

当然,这意味着你将需要特殊处理的其他地方关闭对话框。 GtkDialog将安装发出响应 GTK_RESPONSE_DELETE_EVENT 之前删除走在前面自己的信号处理程序。如果只是用 g_signal_connect(),您的code将在此之前,人会得到一个机会都跑,你就需要有对话闭幕逻辑在两个地方。我不知道是否可以使用 g_signal_connect_after()来把自己在GtkDialog的处理程序,默认之间,但它是值得一试。如果实际执行的工作,那么你的删除事件可能仅仅是一个返回TRUE; ,你做你的回应在处理响应代替。

Of course this means you'll need special handling for closing the dialog elsewhere. GtkDialog installs its own signal handler that issues a response with GTK_RESPONSE_DELETE_EVENT before going ahead with the deletion. If you just use g_signal_connect(), your code will run before that one will ever get a chance to run, and you'll need to have the dialog closing logic in two places. I don't know if you can use g_signal_connect_after() to put yourself in between GtkDialog's handler and the default, but it's worth trying. If that actually does work, then your delete-event could just be a return TRUE; and you do all your response handling in response instead.

这篇关于通过ESC关闭后再次ÇGTK无法打开对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆