Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

rebuilding wx widgets with accessible addons

44 views
Skip to first unread message

Nathan smith

unread,
Nov 16, 2024, 9:07:48 AM11/16/24
to wxpytho...@googlegroups.com
Hello,


I'm aware, peripherally that this issue crops up from time to time but
hopefully my question is a simple one.

for the longest time (until now in fact) I've been happily running
4.0.7post2 for the fact that widget.SetName works mostly to give the
widget a label for screen readers.


however, other modules are forcing my hand and I can no longer linger
happily on this, because distutils has been retired in modern python, so
I can't rebuild 4.0.7post2 in order to be able to use it on python 3.13.


I'm happy to maintain and build wx python versions that implement an
accessibility hack (from conversations I remember before, I think Robbin
mentioned something to do with wx core or wx widgets needing to be
compiled with an accessibility flag or something similar)?

So I'm not arguing for the main library to be edited or antying as I
understand this is probably not a huge concern.


It would be fantastic to be able to use the latest wx, if I can tweak it
to where .setName works nicely with readers, and am happy to do those
tweaks and compile/build as required.

My question is: How do I go about doing this. Where should I be looking?


Thanks in advance

Nathan

Dietmar Schwertberger

unread,
Nov 16, 2024, 3:24:48 PM11/16/24
to wxpytho...@googlegroups.com
Hi Nathan,

first: the wxPython-users list is almost dead.
Most of the discussions are now on https://discuss.wxpython.org/ or on
Github.
Fortunately, Discuss has a better email option than other forum software
has.

I'm not sure what the modification is that you're talking about.
Did you try the current wxPython version? In the past there were
versions which had problems with the accessibility interface.
I think that 4.0.4 to 4.0.7 had problems with Windows 32 bit builds.
Others had problems related to 64 vs. 32 bit.
I think that the latest version should behave better.

In one of the next wxPython releases, you should be able to override the
CreateAccessible method in Python for more customized screen reader support.
The pull requests have been merged.

There are more improvements coming once wxPython is updated to the
latest wxWidgets version.
The grid should then provide at least some basic screen reader support.

In case you are wondering:
I'm the maintainer of the wxGlade GUI builder and I have some users with
screen readers. I try to support this as much as possible. The
application has some options to improve accessibility, but I hope these
will not be required any more with the next wxPython versions.

Regards,

Dietmar

Nathan smith

unread,
Nov 16, 2024, 6:50:10 PM11/16/24
to wxpytho...@googlegroups.com, Dietmar Schwertberger
Hi Dietmar


Thanks for the information and update! :)


So, as it stands, a lot of my code runs SetName to give the widgets an
identifiable name, for instance:

listctrl.SetName("Files.")


for a wx.ListCtrl  containing a list of files.


In wx python 4.0.7, this worked to give the control an identifiable name
that the screen reader picked up on, but in the latest install of wx
python, it does not.

Same result if you pass name as an argument to the __init__


I vaguely thought I remember someone mentioning that setting the
accessibility flag at compile time fixed this? But maybe my memory is
faulty, as having spent the day looking at wx widgets, it looks like the
accessibility flag is set by default?


My wx version: '4.2.2 msw (phoenix) wxWidgets 3.2.6'


That's good news about the grid! I had to catch key down events and run
my own logic with a speech library for that.


Thanks in advance for any ideas, this is a big bummer right now as I
can't do anything until I figure this out, and I can't even role back to
python 3.8 get around things that way because another library has locked
itself out of 3.8.

Nathan

Dietmar Schwertberger

unread,
Nov 17, 2024, 5:15:39 PM11/17/24
to wxpytho...@googlegroups.com
Hi Nathan,

the accessibility flag should be set by default for wxPython on Windows.
For basic accessibility of standard Windows controls, this probably does
not have an influence, as this is handled by Windows.

Could you please try whether a call to SetLabel does work for you?
It seems that wxListCtrl is calling MSWCreateControl with an empty
argument for the label.
For other controls like checkboxes, the label is supplied.
SetLabel is calling the Windows function SetWindowText, which modifies
this label property.
SetName on the other hand does seem to set only the internal name property.

I have checked the sources for 4.0.7post2, but could not find where
SetName would do anything else than setting the wx internal name property.

Regards,

Dietmar

Nathan smith

unread,
Nov 18, 2024, 11:25:58 AM11/18/24
to wxpytho...@googlegroups.com, Dietmar Schwertberger
Good afternoon Dietmar


SetLabel does indeed work for wx.Listctrl, though if I use it on
wx.TextCtrl it sets the value, as well..

Oddly, SetName still works for textctrl.


I am left with sliders currently being the biggest barrier to upgrading
as neither SetName or SetLabel seem to provide a valid screen reader label.

I've not come across SetWindowText so will look into that.


I can not emphasise enough my gratitude for your time on this, even
knowing there's someone else lending a hand to track this down is a huge
help

Nathan

Dietmar Schwertberger

unread,
Nov 18, 2024, 4:34:15 PM11/18/24
to wxpytho...@googlegroups.com
Hi Nathan,

I think the changed behaviour is related to this wxPython pull request:
https://github.com/wxWidgets/wxWidgets/pull/340
wxPython 4.0.7 has the old implementation where a wxWindowAccessible
would be created where the new implementation relies on the behaviour of
the Windows control.
I will check some things, e.g. why a slider gets the default name
'slider' instead of the argument provided to the wxSlider constructor.

Regards,
Dietmar

Dietmar Schwertberger

unread,
Nov 18, 2024, 6:02:21 PM11/18/24
to wxpytho...@googlegroups.com
P.S.: For slider, the name should be displayed if you create a
StaticText as label right before creating the wxSlider.

Nathan smith

unread,
Nov 19, 2024, 12:52:50 PM11/19/24
to wxpytho...@googlegroups.com, Dietmar Schwertberger
Dietmar


Can't thank you enough.

While the StaticLabel mention was a bust (I'd tried that already as
that's how I used to do things years ago), something about either the
way you wrote, or the git hub post, had me going down the route of
wx.Accessible, and writing this:


class AccessibleSlider(wx.Accessible):
    def __init__(self, widget, name="Custom Widget"):
        super().__init__()
        self.widget = widget
        self.name = name

    def GetName(self, childId):
        """Return the accessible name."""
        return (wx.ACC_OK, self.name)

    def GetValue(self, childId):
        """Return the accessible value."""
        return (wx.ACC_OK, str(self.widget.GetValue()))

    def GetRole(self, childId):
        """Return the accessible role (e.g., slider, button)."""
        return (wx.ACC_OK, wx.ROLE_SYSTEM_SLIDER)

    #def GetDescription(self, childId):
        #"""Return an additional description."""
        #return (wx.ACC_OK, "This is a custom accessible slider.")


Low and behold, sld.SetAccessible witht that, we have a gorgious slider
label.

I've commented out get description because it read that description out
every time and it got massively annoying very fast.

Combine that with using SetLabel on wx.listctrl, sticking to SetName for
wx.textctrl and I think. *think* I'm there! A happy upgrade.


Goign to feel weird running a modern wx python version for the firs
ttime in years :)


Course, this is where you mention wx.Accessible is being removed in the
next pull request :)


Thanks for sticking with me, and don't hesitate to let me know if you
want me to try something else.

Nathan

Dietmar Schwertberger

unread,
Nov 19, 2024, 1:21:35 PM11/19/24
to wxpytho...@googlegroups.com
Hi Nathan,

with the next wxPython release you should be able to override
CreateAccessible to create the wx.Accessible instance on demand only.
The related PRs are almost in 4.2.2, but are not yet active as there was
some interference with the build process on non-Window platforms.
https://github.com/wxWidgets/Phoenix/pull/2515
https://github.com/wxWidgets/wxWidgets/pull/24209

Anyway I will check next week why the default behaviour of e.g. slider
does ignore the control name. Maybe there is an easy fix.

Regards,
Dietmar
Reply all
Reply to author
Forward
0 new messages