重新打开窗口引发Gtk-CRITICAL **:gtk_widget_get_window:断言'GTK_IS_WIDGET(widget)'失败 [英] Reopen window throws Gtk-CRITICAL **: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed

查看:111
本文介绍了重新打开窗口引发Gtk-CRITICAL **:gtk_widget_get_window:断言'GTK_IS_WIDGET(widget)'失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的python3 + gtk3代码,该代码连接到dbus并监听所有事件.当用户单击托盘中的图标时,他必须看到所有显示的较早事件的窗口.代码(我不知道问题在哪里,代码大小> 100行): L117

  • 单击任务栏中的应用程序图标-将打开一个窗口,该窗口可以为空或包含一些项目,如果运行后显示任何通知. L83
  • 关闭窗口. L93
  • 重试步骤2,您会看到一个空窗口(在任何情况下都没有任何元素,是的,这是bug,但对这个问题无关紧要)
  • 单击窗口主体,应用将崩溃:

    (gui.py:4882):Gtk-CRITICAL **:gtk_widget_get_window:断言'GTK_IS_WIDGET(widget)'失败 [1] 4882分段错误(核心已转储)python gui.py

  • 在第一个windowOpen事件和第二个windowOpen事件上, self.window 对象是< __ main __.Window对象位于0x7f98b1dcd7e0(__ main __ + Window位于0x1502260)>

    gdb结果:

     (main.py:17310):Gtk-CRITICAL **:gtk_widget_get_window:断言'GTK_IS_WIDGET(widget)'失败线程1"python"收到信号SIGSEGV,分段错误.来自/usr/lib/libgtk-3.so.0的gtk_widget_translate_coordinates()中的0x00007fffea5cd0b8 

    请向我解释如何调试和解决此问题.

    PS:我是Python的新手,这就是为什么这个问题可能很愚蠢的原因.

    解决方案

    第1课:永远不要认为bug无关

    第2课:GTK事件令人困惑.

    出现此错误的原因是,在第3步中将其关闭后,实际上已删除了该窗口,因此窗口中的所有小部件都变成孤立的(它们没有父级)并且因此被清除.第二次在步骤4中打开窗口时,该窗口仅包含对导致细分错误的已删除小部件的引用.

    该解决方案非常简单,只需在 closeWindow 中添加 return True 即可,这将使GTK知道该事件已得到处理,并且不应执行关闭该事件的默认操作.窗口(您已经隐藏).

    I have simple python3 + gtk3 code, which connects to dbus and listen for all events. When user click on icon in tray, he must see window with all showed earlier events. Code(I don't know where is problem and code size > 100 lines): https://github.com/rakshazi/notify-feed/blob/master/main.py

    How to reproduce:

    1. Run python main.py L117
    2. Click on app icon in tray - will be opened window, it can be empty or with some items if any notifications was shown after run. L83
    3. Close window. L93
    4. Retry step #2, you will see empty window (without any element in all cases, yes, it is bug, but doesn't matter for this question)
    5. Click on window body and app will be crashed:

      (gui.py:4882): Gtk-CRITICAL **: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed [1] 4882 segmentation fault (core dumped) python gui.py

    On first windowOpen event and on second windowOpen event self.window object is <__main__.Window object at 0x7f98b1dcd7e0 (__main__+Window at 0x1502260)>

    gdb result:

    (main.py:17310): Gtk-CRITICAL **: gtk_widget_get_window: assertion 'GTK_IS_WIDGET (widget)' failed
    
    Thread 1 "python" received signal SIGSEGV, Segmentation fault.
    0x00007fffea5cd0b8 in gtk_widget_translate_coordinates () from /usr/lib/libgtk-3.so.0
    

    Please, explain to me how to debug and fix this problem.

    PS: I'm new to Python, that's why this problem may be stupid.

    解决方案

    Lesson 1: Never assume bugs are unrelated

    Lesson 2: GTK events are confusing.

    The reason you get this error is because the window is actually deleted in you close it in step 3, therefor all the widgets in the window become orphans (they have no parent) and are therefor cleaned. The second time you open the window in step 4 the window only contains references to deleted widgets causing your segmentation fault.

    The solution is surprisingly simple just add return True to closeWindow this will let GTK know the event has been handle and that it should not perform the default action of closing the window (that you already hide).

    这篇关于重新打开窗口引发Gtk-CRITICAL **:gtk_widget_get_window:断言'GTK_IS_WIDGET(widget)'失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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