wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.29k stars 516 forks source link

Disabled wx.StaticBitmap generates unexpected events Ubuntu 16.04 #819

Open Erriez opened 6 years ago

Erriez commented 6 years ago

Operating system: Ubuntu 16.04 64-bit wxPython version: wxPython 4.0.1 Stock or custom build: Build via pip Python version: 3.5 Stock or custom build: Stock

Description of the problem: wx.EVT_LEFT_DOWN event is generated on a disabled wx.StaticBitmap.

Note: No events are generated on Windows which is correct behavior.

Fully reproducible testcase:

events_on_disabled_wx_staticbitmap

import wx
import wx.xrc

from wx.lib.embeddedimage import PyEmbeddedImage

# Question image generated with wx.tools.img2py
Question = PyEmbeddedImage(
    b'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAIAAAC0Ujn1AAAAAXNSR0IArs4c6QAAAARnQU1B'
    b'AACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAANeSURBVEhLjZXPThNRFIfvMHQsvoD4'
    b'BvoE+gAmCCIqUhCIGLC05a9E4srYhYgikYWWoCZiE1jIQhPEaoQYhEoLgguNWxZuTFypCQnb'
    b'+t2543RK7wyc/BbtzL3fnPmdc+6Ign/82dmdeb8ZG39Rc33q8KlhV/zlIrdY4CzVhR7NHjYf'
    b'PXczXH8n1JY2u98aA3lxbQsZ/Tkzmgm1psP1Iyxgmd8DNOjUy1X2WJFJo29VDG1J2VBbm2Lw'
    b'vwY2jcSydTHFYrY4mz1RglbJVtUlzdg7MfQlmCsGPiuZXZmq2mR5+kU0N07GJ3DAGMxruRWx'
    b'Jawwr2aMvjWXK/qljJ5P4TMjbPfSi2geq+UavStW0+SxjvHY+NzozCJqSabDDfcruhcVV/Rv'
    b'iL4NRQfi4Fw0ZuFDObcivnSiN5X9uq2WufHj12+u23TJVTISWZxxfZdo3oJSaP3FAdJkzd+d'
    b'3YXcd35/2/5pb5RXqiN3Xa7oXUdm5wIoZYtE8xb0g9ZfhQZaHblX2T6L0VbzU5yx4YUbU/Nm'
    b'5xuXq2Q1ppQtQqXs12egj7eP0mHeukFXuWNU6NJzL1f0rBvRDypxwVBRPS1XokmzlIvAKfcl'
    b'umXay7WVp55gBckzb1ouKu8z6hZuGKOMoPEKc/dwUah5GqzgQGCOtVzvXLjcystzWAyXoCPp'
    b'ij1ckcibV16DFRw37vmwP7dt1q3h5Kus40YpFxmxVbASfUAuFrvc2cWtQ+cntFypeM6L3odL'
    b'kzGEXq4Rz/pxi2jOyWAunUufqNLR43RuQL7I6F6RaFnGaCaYi+gKlXLN8FRwvsjssMsom681'
    b'Hcz1ounZYK6I5UKRZ7L57JEZCeby+kdaHjjos2PBXBSuuy1Hxhn0xHIAF5E1UGQ1PgrmGl1L'
    b'zqCTCMk70+zDRVbkiYNuehzAFbE168JDgGA9h2pXxo+LgEo7lCH+XLNjXqXMSs+noDbJl0LL'
    b'xVwNuoxrRD9Wnb5V8ilQwVtQfYdeykX4ABRJQ3y4VE9ZoaKI5i3kZxe6OnE83OC6uVzfzy7B'
    b'DR6LM85ReTAu/uIDG71cogStArMoBdPM9yKYS5/RDyx2/fWGBk2o9NmDP5zrnL+ckwrK+cAc'
    b'M284wILyZN3Qo1Wwh6FiMwcCx40r/nKRW35QGYXCP5FzpTG3q/yFAAAAAElFTkSuQmCC')

class MyDialog(wx.Dialog):
    def __init__(self, parent):
        wx.Dialog.__init__(self, parent, id=wx.ID_ANY, title='Image click', pos=wx.DefaultPosition,
                           size= wx.Size(200, 100), style=wx.DEFAULT_DIALOG_STYLE)

        self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
        self.SetBackgroundColour(wx.Colour(240, 240, 240))

        bSizer = wx.BoxSizer(wx.VERTICAL)

        self.m_bitmap = wx.StaticBitmap(self, wx.ID_ANY, Question.Bitmap, wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_bitmap.SetToolTip(u"Click me!")

        bSizer.Add(self.m_bitmap, 0, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL, 5)

        self.m_checkBox = wx.CheckBox(self, wx.ID_ANY, u"Enable image", wx.DefaultPosition, wx.DefaultSize, 0)
        self.m_checkBox.SetValue(True)
        bSizer.Add(self.m_checkBox, 0, wx.ALL, 5)

        self.SetSizer(bSizer)
        self.Layout()

        self.Centre(wx.BOTH)

        # Connect Events
        self.m_bitmap.Bind(wx.EVT_LEFT_DOWN, self.OnBmpLeftDown)
        self.m_checkBox.Bind(wx.EVT_LEFT_DOWN, self.OnChkLeftDown)

    def OnBmpLeftDown(self, event):
        if self.m_bitmap.IsEnabled():
            msg = 'OK: Image was enabled'
        else:
            msg = 'FAILURE: Image is disabled and unexpected OnLeftDown() generated!'
        wx.MessageBox(msg, 'Clicked on image')

    def OnChkLeftDown(self, event):
        chk = event.GetEventObject()
        if chk.IsChecked():
            self.m_bitmap.Enable(False)
            # Disable() does not make sense:
            # self.m_bitmap.Disable()
        else:
            self.m_bitmap.Enable(True)
        event.Skip()

def main():
    app = wx.App(False)
    dlg = MyDialog(None)
    dlg.ShowModal()
    app.MainLoop()

if __name__ == "__main__":
    main()

Any idea what's wrong?

RobinD42 commented 6 years ago

When native widgets are involved the notion of "correct behavior" is a bit of a moving target, and subject to various interpretations and platform standards. You can try raising this issue in wxWidgets Trac and see if anything will be done about it, but I suspect that it won't be considered a bug, just differing native behavior.

For the record, on OSX the events are also sent for the disabled statbmp.

infinity77 commented 3 weeks ago

@swt2c : my recollection of stuff is that things like wx.StaticText and wx.StaticBitmap are not “real” widgets on Linux (possibly Mac as well?) but they are drawn by the OS on top of their parents.

My recollection may be wrong. But if it isn’t, then I’m not sure there’s much wxPython can do about this.