Skip to content

Support CreateAccessible in all wxWindow subclasses#2874

Merged
swt2c merged 1 commit intowxWidgets:masterfrom
swt2c:accessibility_wip
Apr 1, 2026
Merged

Support CreateAccessible in all wxWindow subclasses#2874
swt2c merged 1 commit intowxWidgets:masterfrom
swt2c:accessibility_wip

Conversation

@swt2c
Copy link
Copy Markdown
Collaborator

@swt2c swt2c commented Mar 31, 2026

In order to do this, had to provide a C++ implementation of CreateAccessible in all classes, and make wxAccessible visible in all modules. This was previously done in 5279c3c by Dietmar, but this didn't work in our CI system where the sdist is built on a Linux system.

Fixes #2851.

@swt2c swt2c marked this pull request as draft March 31, 2026 23:47
In order to do this, had to provide a C++ implementation of
CreateAccessible in all classes, and make wxAccessible visible in all
modules.  This was previously done in 5279c3c by Dietmar, but this
didn't work in our CI system where the sdist is built on a Linux system.
@swt2c swt2c force-pushed the accessibility_wip branch from 552d55e to 6c28d45 Compare April 1, 2026 00:54
@swt2c swt2c marked this pull request as ready for review April 1, 2026 13:10
@swt2c
Copy link
Copy Markdown
Collaborator Author

swt2c commented Apr 1, 2026

Hey @DietmarSchwertberger, I think this should finally resolve the issue with CreateAccessible. Do you mind checking? Sorry for the long delay.

@DietmarSchwertberger
Copy link
Copy Markdown
Contributor

I have just downloaded (4, 3, 0, 'a16049+8d28af9e'), but unfortunately it does not work.
GetOrCreateAccessible() still returns None.

@swt2c
Copy link
Copy Markdown
Collaborator Author

swt2c commented Apr 1, 2026

This change hasn't been merged yet, so isn't in a snapshot build yet. I'll go ahead and merge it now.

@swt2c swt2c merged commit 1a5e2cf into wxWidgets:master Apr 1, 2026
14 checks passed
@swt2c swt2c deleted the accessibility_wip branch April 1, 2026 18:42
@DietmarSchwertberger
Copy link
Copy Markdown
Contributor

I did download (4, 3, 0, 'a16049+8d28af9e') from the PR wheel, but will check again once the snapshot is built.

@swt2c
Copy link
Copy Markdown
Collaborator Author

swt2c commented Apr 1, 2026

Oh. That version didn't make sense as being from the PR, that's why I thought you had downloaded from the snapshot builds server.

However, I noticed you mentioned GetOrCreateAccessible. I only fixed CreateAccessible.

Do you have a code snippet you can share, so I can make sure it works? Not that I'll be able to test it, but just wanting to see how it is supposed to work.

@swt2c
Copy link
Copy Markdown
Collaborator Author

swt2c commented Apr 1, 2026

Never mind about the code snippet. I see you provided that in one of the linked issues. I need to double check but it is possible my solution might not work in this case. Need to see compare the generated code with what gets generated just when you add a virtual method.

@DietmarSchwertberger
Copy link
Copy Markdown
Contributor

DietmarSchwertberger commented Apr 2, 2026

Thanks for your support.

Yes, it's two steps:
GetOrCreateAccessible() needs to call GetAccessible() if accessibility is implemented / wxUSE_ACCESSIBILITY is defined.
(In wxWidgets, GetOrCreateAccessible is not implemented at all if wxUSE_ACCESSIBILITY is not defined.)
Then GetAccessible needs to be virtual, such that it can be implemented in Python. Otherwise only the empty implementation from C++ would be called.

sip_corewxWindow.cpp looks reasonable, IMHO, but means that on wxPython now GetOrCreateAccessible() is always defined?

    wxAccessible * _wxWindow_GetOrCreateAccessible(wxWindow* self)
    {
        #if wxUSE_ACCESSIBILITY
            return self->GetOrCreateAccessible();
        #else
            wxPyRaiseNotImplemented();
            return NULL;
        #endif
    }

When I install the current snapshot on Windows:

>>> import wx
>>> wx.VERSION
(4, 3, 0, 'a16051+1a5e2cf2')
>>> app = wx.App()
>>> frame = wx.Frame()
>>> frame.GetOrCreateAccessible()
>>>

That means it was compiled with wxUSE_ACCESSIBILITY, right? Otherwise there would be an exception?

On Ubuntu, a build from the master branch shows that both methods are there, while previously the build would not have had them:

>>> import wx
>>> wx.VERSION
(4, 3, 0, 'a1')
>>> app = wx.App()
>>> frame = wx.Frame()
>>> frame.GetOrCreateAccessible()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NotImplementedError
>>> frame.CreateAccessible()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NotImplementedError

For comparison, an old version on Ubuntu, where GetOrCreateAccessible is not available at all:

>>> import wx
>>> wx.VERSION
(4, 2, 1, '')
>>> app = wx.App()
>>> frame = wx.Frame()
>>> frame.GetOrCreateAccessible()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Frame' object has no attribute 'GetOrCreateAccessible'

So, to summarize: contrary to wxWidgets, we now always have both methods, no matter whether wxUSE_ACCESSIBILITY is defined or not. I hope that this does not cause any problems.
A program can check for accessibility support instead of checking these methods:

>>> wx.USE_ACCESSIBILITY
1

The problem is that CreateAccessible is not virtual.

May initial approach from https://github.com/wxWidgets/Phoenix/pull/2618/changes was this change to tweaker_tools.py:

    if isWindows:
        # does not compile on GTK and macOS.
        publicWindowVirtuals.append( ('CreateAccessible', 'wxAccessible* CreateAccessible()') )

Now we have

    if klass.name not in ['wxWindow', 'wxProgressDialog', 'wxRichTextCtrl']:
        klass.addCppMethod('wxAccessible*', 'CreateAccessible', '()', """\
            #if wxUSE_ACCESSIBILITY
                return self->CreateAccessible();
            #else
                wxPyRaiseNotImplemented();
                return NULL;
            #endif
            """, factory=True)

I don't see where this creates the virtuality, but I'm not a C++ guy.

I will only be online after Easter again. Happy Easter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CreateAccessible not virtual in latest snapshot

2 participants