在 wx.ComboBox 小部件上禁用鼠标滚轮事件

Disable mousewheel events on wx.ComboBox widget

我有一个带有组合框的 wx.Frame。在组合框中进行选择时,将调用特定函数。

我对 ComboBox 产生了不良影响。 当 ComboBox 有焦点时,鼠标滚轮的任何移动都会改变选择,因此会触发不同的功能。

在实践中,很难记住您必须将小部件置于 'save' 原始选择的焦点之外,因此,由于触发的功能需要几秒钟才能完成,因此 GUI 的可用性不好。

我尝试使用

捕捉鼠标事件但无济于事

self.Bind(wx.EVT_MOUSEWHEEL, self.donothing, self.mycombobox)

防止鼠标信号影响组合框的最佳程序是什么?

编辑
如果你想玩代码,这里有一些你可以执行和测试。 只需执行,用鼠标进行选择,然后播放鼠标滚轮。我不想改变选择。我无法捕捉到鼠标滚轮发出的事件,无论它是什么。

import wx

class Myframe(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        pan = wx.Panel(self)

        self.cbx = wx.ComboBox(pan, -1, pos=(10,30),
                            choices=["SEARCH", "SELECT", "PASS"],
                            style=wx.CB_DROPDOWN )

        self.cbx_2 = wx.ComboBox(pan, -1, pos=(10,60),
                            choices=["LOOK", "GO", "FILL"],
                            style=wx.CB_DROPDOWN )

        self.Bind(wx.EVT_MOUSEWHEEL, self.do_nothing)  # to no avail
        self.Bind(wx.EVT_COMBOBOX, self.on_selection, self.cbx)
        self.Bind(wx.EVT_COMBOBOX, self.on_selection_2, self.cbx_2)

    def on_selection(self, evt):
        """I do not want this to be executed inadvertently when 
         moving mousewheel"""
        print self.cbx.GetStringSelection()
        #evt.Skip(False)  # this is the default behavior anyway

    def on_selection_2(self, evt):
        """this is another combobox. dont mind if mouse move it or not"""
        print self.cbx.GetStringSelection()

    def do_nothing(self, evt):
        ""
        print 'on events pit' # never catched !!!        
        #evt.Skip(False)  # this is the default behavior anyway


if __name__ == "__main__":  
    App = wx.PySimpleApp()
    Myframe().Show()
    App.MainLoop()

我很确定这就是 event.Veto() 选项的用途。
我可以在这里找到简单的例子:
http://zetcode.com/wxpython/events/

只需要另一双眼睛。

import wx

class Myframe(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        pan = wx.Panel(self)
        self.cbx = wx.ComboBox(pan, -1, pos=(10,30),
                                choices=["SEARCH", "SELECT",
                                         "PASS", "LOG", "DATABASE"],
                                style=wx.CB_DROPDOWN )
        self.cbx_2 = wx.ComboBox(pan, -1, pos=(10,60),
                            choices=["LOOK", "GO", "FILL"],
                            style=wx.CB_DROPDOWN )

        self.cbx.Bind(wx.EVT_MOUSEWHEEL, self.do_nothing)
        self.cbx.Bind(wx.EVT_COMBOBOX, self.on_selection)
        self.cbx_2.Bind(wx.EVT_MOUSEWHEEL, self.do_nothing)
        self.cbx_2.Bind(wx.EVT_COMBOBOX, self.on_selection_2)

    def on_selection(self, evt):
        """I do not want this to be executed inadvertently when 
         moving mousewheel"""
        print self.cbx.GetStringSelection()

    def on_selection_2(self, evt):
        """this is another combobox. dont mind if mouse move it or not"""
        print self.cbx.GetStringSelection()

    def do_nothing(self, evt):
        print 'on events pit'

if __name__ == "__main__":  
    App = wx.PySimpleApp()
    Myframe().Show()
    App.MainLoop()

self.Bindself.widget.Bind 区别是 explained in the wxPyWiki