wxPython;右键单击任何文本字段中的上下文菜单是否可以使程序崩溃并显示错误“ m_menuDepth> 0”?

时间:2018-09-10 12:31:57

标签: python python-3.x windows-10 wxpython wxpython-phoenix

我注意到,右键单击wxPython小部件中的文本字段时,如果用户选择Insert Unicode control character选项并插入任何这些字符example image,程序将抛出此错误;

wx._core.wxAssertionError: C++ assertion "m_menuDepth > 0" failed at ..\..\src\msw\toplevel.cpp(1545) in wxTopLevelWindowMSW::DoSendMenuOpenCloseEvent(): No open menus?

The above exception was the direct cause of the following exception:

SystemError: <class 'wx._core.CommandEvent'> returned a result with an error set

这是将引发错误的示例代码;

import wx


class Program(wx.Frame):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.panel = wx.Panel(self)
        self.sizer = wx.GridBagSizer(0, 0)
        self.panel.SetSizer(self.sizer)

        self.text_ctrl = wx.TextCtrl(self.panel)
        self.sizer.Add(self.text_ctrl, wx.GBPosition(0, 0))

        # Needed, because there probably has to be some events which
        # can be processed for the error to show before closing the program.
        # Without this the error only appears after exiting.
        self.text_ctrl.Bind(wx.EVT_TEXT, lambda e: print("text changed"))

        self.sizer.Layout()
        self.Show()


app = wx.App()
program = Program(parent=None)
app.MainLoop()

如何避免从头开始重做上下文菜单,没有完全禁用它,也没有在try-except中包装很多东西(捕获wx._core.wxAssertionError确实是个坏习惯,因为通常是致命的,这是错误的) )?

编辑:

该错误可在以下位置重现:

操作系统::Win 10 Enterprise 2016 LTSB / Win 10 Pro(均经过测试)

wxPython版本和来源:来自pip3的4.0.2 / 4.0.3(均经过测试)

Python版本和来源:Python 3.6.5版本

1 个答案:

答案 0 :(得分:0)

这是wxPython的错误,将在以后的版本中修复。

可以在此处跟踪问题:https://github.com/wxWidgets/Phoenix/issues/992