disabling mouse clicks to ToggleButton

Very new to wxPython so still tons to learn.

I have a row of ToggleButtons all but one of which do exactly that, toggle something on and off. The last one however is really an indicator of state, I used a ToggleButton for consist look with the rest but I only want to set it programatically and don’t want it to be clickable. That of itself may be a horrible misuse.

If I disable it then it doesn’t receive events, however it also greys out … not what I wanted. Is there a way to turn of the ToggleButtons response to mouse clicks so it just ignores them entirely and I can use it like an indicator in this way? I could receive the click event, let the button toggle and then toggle it back again but that’s pretty horrible and it’ll probably flash and look nasty.

If not - is there something which looks pretty much exactly like a ToggleButton (so it looks like the other ones) but is better for a pure indicator?

Before an EVT_TOGGLEBUTTON is created and sent, a mouse event is sent.

Try registering a handler for mouse click events and then in the handler just do nothing. That should avoid the events to be processed further.

https://wxpython.org/Phoenix/docs/html/wx.MouseEvent.html

E.g. just to ignore a left mouse click:

     self\.button\_1\.Bind\(wx\.EVT\_LEFT\_DOWN, self\.ignore\)
 def ignore\(self, event\):
     pass

You may just register a handler for EVT_MOUSE_EVENTS to receive all kinds of mouse events and call event.Skip() except when event.ButtonDown() is True. Maybe you need to check some other methods/properties as well, e.g. |ButtonDClick|.

You can find more information about event handling here: Events and Event Handling — wxPython Phoenix 4.2.3a1 documentation

If you attach a small sample program, usually you will get quicker answers...

Regards,

Dietmar

···

On 5/28/2018 1:29 PM, rols@rols.org wrote:

If I disable it then it doesn't receive events, however it also greys out .. not what I wanted. Is there a way to turn of the ToggleButtons response to mouse clicks so it just ignores them entirely and I can use it like an indicator in this way? I could receive the click event, let the button toggle and then toggle it back again but that's pretty horrible and it'll probably flash and look nasty.

Thanks for that - I’d gotten fairly close to it myself last night but had subclassed and now I see the event system in wxWidgets is pretty dynamic so I don’t need to. Yes you do need to deal with double click too, but that was easily done.

Sure there will be more questions soon but at least I got started, now to hook this rudimentary UI up to the code which actually generates the events.

···

On 5/28/2018 1:29 PM, wrote:

rols@rols.org

    If I disable it then it doesn't receive events,

however it also greys out … not what I wanted. Is there a way
to turn of the ToggleButtons response to mouse clicks so it just
ignores them entirely and I can use it like an indicator in this
way? I could receive the click event, let the button toggle and
then toggle it back again but that’s pretty horrible and it’ll
probably flash and look nasty.

  Before an EVT_TOGGLEBUTTON is created and sent, a mouse event is

sent.

  Try registering a handler for mouse click events and then in the

handler just do nothing. That should avoid the events to be
processed further.

https://wxpython.org/Phoenix/docs/html/wx.MouseEvent.html
E.g. just to ignore a left mouse click:

self.button_1.Bind(wx.EVT_LEFT_DOWN, self.ignore)
def ignore(self, event):
pass

  You may just register a handler for EVT_MOUSE_EVENTS to receive

all kinds of mouse events and call event.Skip() except when
event.ButtonDown() is True. Maybe you need to check some other
methods/properties as well, e.g. ButtonDClick.

    You can find more information about event

handling here:

https://wxpython.org/Phoenix/docs/html/events_overview.html

  If you attach a small sample program, usually you will get

quicker answers…

Regards,

Dietmar