An On/Off button alternative to CheckBox

Pleae take a look at onoffbuttonbox.py and actually click the damned thing.

Note the difference between my mod witch is a ButtonBox, compared to a standard RadioBox, which could have numerous possibilities…

Have you correctly assembled all the switches and keys that a (micro)PyBoard would consume(inhales)…

What about the TUX key? poor peguins.

Whose description. Yours?
My description, found at the top of the source code is:

used to select one of a number of mutually exclusive choices.

Which as far as I am concerned it does.

I’m not sure how much more explicit I can be, you’ll find the following code in onoffbutton.py function def OnOff

            # if this button is already the selected item in a group or buttonbox setfocus, ignore the selection
            if self == selected:
                selected.SetFocus()
                return

Which clearly sets the Focus and nothing more.
N.B. This happens at the onoffbutton level, meaning that the onoffbuttonbox never receives the event that would cause it to fire its own event.

Why didn’t I think of that?
You’re right of course, I really should try testing the code, rather than randomly throwing together keywords and crossing my fingers.
How I ever earnt a living from coding and systems analysis beats me. Let’s put it down to decades of pure luck. :wink:

Find attached Version 3.1.0 of OnOffButton
Personally I blame Georg @da-dada. It was he that toyed with me over the hybrid nature of the Radiobutton demo program, which led me to introduce Groups to the onoffbuttons.
That introduced a certain degree of chaos into the keyboard navigation.
Version 3.1.0 attempts to resolve much of that and I trust, I have not broken anything else. :slight_smile:

onoff-3.1.0.zip (591.1 KB)

The changelog:

3.1.0
Resolves losing the Focus indicator within an OnOffRadioBox after selecting an item

Introduces group membership to each button in the group.
Each button in a group becomes aware of every other button in the same group.
Why should you know or care?
Because when using the group option outside of a onoffbuttonbox, such as a hybrid control, the order that you declare the widgets in, becomes very important, to determine which widget is next when using key navigation.
This feature allows us to ignore the wx.Windows NextSibling/PrevSibling method to make that decision
and use only those items in the group membership.
Membership is decided automatically and set for each member of the group. This is also true when Adding or Inserting new buttons to the group i.e. having the same oob_group_id.
hybriddemo3.py and hybriddemo3a.py demonstrate the ability to mix up the widget definition order.

Allows an onoffbuttonbox to use arrow keys to navigate Focus without selecting the focused item,
this is reserved for Spacebar and Mouse Click

Alters the way that onoffbuttonlist and onoffbuttonbox decide on Focus and Tabbing when using
keyboard navigation

Added function GetGroupSelected() - returns the selected item in the current oob_group_id
This maintains some sanity when tabbing in a hybrid setup, from an onoffbuttonlist into a group by passing focus to the selected item in the group

Added GetGroupSelectedIndex() - returns the index of the selected item in the current oob_group_id

Clean up of text in onoffbuttonlist.py

Adds hybriddemo4, to provide a hybrid control example, without using a StaticBox but simply placing the widgets directly onto the panel.

Adds hybriddemo5, to provide a hybrid control example, with 3 levels of controls, merely to prove the ability to do so.

An example of multi-level hybrid onoffbutton - see hybriddemo5.py

Regards,
Rolf

Hopefully the final version 3.2.0
onoff-3.2.0.zip (592.3 KB)

Changelog:
3.2.0

  • Finally nails down tabbing In and Out of an onoffbuttonlist
    rather than tabbing through the buttons in the list until it reaches the end, before finally moving on
    to the next window, which it had tendency to do beforehand.
  • OnOffButtonList and OnOffButtonBox both have GetColumnCount and GetRowCount functions added
  • OnOffButtonList has a new parameter: max_select
    0 = All, otherwise a maximum number of items that may be selected from the list of choices
    Allows a restriction to a subset of the choices available e.g. pick no more than x number
  • OnOffButtonList has a new function:
    GetSelectedOrder() returns a list of the index order in which items were chosen,
    in effect, offering a way of ranking choices.

Thank you for the changlog/changelog2 it really helps.

Is the columncount features for those of us that can’t column count …

:rofl:
Indeed! 1…2…3…Lots!

In fact the wx.RadioBox offers these functions and as they are free, coming from the sizer, I thought I would add them.
I assume they are there because whilst you assign x many rows or columns, you don’t necessarily know the number of the other dimension but as I said, they’re free, so they were thrown in.

Regards,
Rolf.

I like your humor :wink: