nvaccess / nvda

NVDA, the free and open source Screen Reader for Microsoft Windows
Other
2.08k stars 628 forks source link

Problems with wx.stc.StyledTextCtrl (Contol based on Scintilla) #13976

Open Tomez81 opened 2 years ago

Tomez81 commented 2 years ago

Steps to reproduce:

Execute the script below (I've tested it with python 3.7 and wxPython==4.1.1)

# -*- coding: utf-8 -*-
"""Test styled text ctrl module."""

from typing import Optional
from wx import App, BoxSizer, SizerFlags, Frame, Window
from wx.stc import StyledTextCtrl

class CustomFrame(Frame):
    """Custom frame."""

    def __init__(self, parent: Optional[Window], title: str):
        """Init.

        :param parent: Parent.
        :param title: Title.
        """

        super(CustomFrame, self).__init__(parent, title=title, size=(800, 600))

        # Initialize sizer
        sizer = BoxSizer()
        self.SetSizer(sizer)

        # Initialize styled_text_ctrl
        styled_text_ctrl = StyledTextCtrl(self)
        sizer.Add(styled_text_ctrl, SizerFlags(1).Expand())

def main():
    """Main."""

    # Initialize application
    app = App()

    # Make frame
    frame = CustomFrame(None, title='Test StyledTextCtrl')
    frame.Show()

    # Main loop
    app.MainLoop()

if __name__ == '__main__':
    main()

Write some text ex. "Hello world" on the first row then press Enter On the second row write "Hi"

Actual behavior:

In NVDA braille viewer the content with the cursor on the second row is: " Hi llo world"

It seems in general that after the end of the row it concatenates the remaining characters from the longest row of the control.

Expected behavior:

In NVDA braille viewer the content with the cursor on the second row should be: "Hi"

In Notepad++ (Also derived from Scintilla) the same test works fine.

NVDA logs, crash dumps and other attachments:

Not applicable

System configuration

NVDA installed/portable/running from source:

Installed

NVDA version:

2022.2

Windows version:

Windows 10 Pro Version: 21H2 Build: 19044.1826

Name and version of other software in use when reproducing the issue:

Not applicable

Other information about your system:

Not applicable

Other questions

Does the issue still occur after restarting your computer?

Yes

Have you tried any other versions of NVDA? If so, please report their behaviors.

No

If NVDA add-ons are disabled, is your problem still occurring?

Yes

Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?

Yes

seanbudd commented 2 years ago

Can you confirm that this is an issue with a real braille display, not just braille viewer?

Tomez81 commented 2 years ago

Yes I've tested it with a real braille display too

lukaszgo1 commented 2 years ago

This is a WX issue reported in https://github.com/wxWidgets/wxWidgets/issues/10771 and in https://github.com/wxWidgets/wxWidgets/issues/18683

Note that this affects all screen readers for Windows.

Tomez81 commented 2 years ago

Thanks for the response, I had't check wxPython in depth because, until now, we had used a ctrl derived from wxStyledTextCtrl in our software with JAWS and it hadn't show any issues. I've just double checked the script above with JAWS 2022 and all works on the braille display.

I've also checked the script with "Accessibility Inside For Windows" and, even if the result is not equal to notepad++ it seems to give a bunch of informations to MSAA. Are you sure that there is no problem within the internal management of NVDA?

lukaszgo1 commented 2 years ago

I had't check wxPython in depth because, until now, we had used a ctrl derived from wxStyledTextCtrl in our software with JAWS and it hadn't show any issues. I've just double checked the script above with JAWS 2022 and all works on the braille display.

Sorry for not being clear enough in my previous comment. What I wanted to say was that none of the screen readers for Windows are able to access the styled text control from WX the same way in which other Scintilla controls are accessed. JAWS works better in this case because its screen scraping code is better, ,more mature, so the control is accessed either via the mirror display driver on older versions of Windows, or via GDI hooks when the newer version of Windows is in use.

I've also checked the script with "Accessibility Inside For Windows" and, even if the result is not equal to notepad++ it seems to give a bunch of informations to MSAA.

Assuming you mend Accessibility Insights last time I looked it only supports UIA, and Scintilla has to be accessed via mix of MSAA and the custom code which sends windows messages to the control.

Are you sure that there is no problem within the internal management of NVDA?

It is probably possible to improve the NVDA's GDI hooks to provide the same level of access JAWS offers here, but more reasonable course of action would b to fix the issue in WX.

hwf1324 commented 8 months ago

but more reasonable course of action would b to fix the issue in WX.

Hi, can you elaborate? Like what needs to be done? Or what knowledge is needed. Or can give some advice or information.

Thanks.

hwf1324 commented 7 months ago

This seems to be fixed in the stc sample built with wxWidgets/master. I wonder if this will be fixed when the wxWidgets used by wxPython are updated?

hwf1324 commented 7 months ago
styled_text_ctrl.SetBufferedDraw(False)

The problem can be solved manually with this method. But it is not generic. Until the wxWidgets used by wxPython are updated to 3.2.4, we need a generic way to solve such problems.

lukaszgo1 commented 7 months ago

Is this really a fix making this control fully operational? In particular is selection announced? There is no way to solve this generically, someone has to spend their time understanding why this control falls back to the display model, despite being Scintilla based.

hwf1324 commented 7 months ago

It doesn't seem to, it only solves the speech confusion problem.

hwf1324 commented 7 months ago

Maybe something else to look at. Is the wxStyledTextCtrl correctly identified as Scintilla control? Spy++ says the classname of wxStyledTextCtrl will be wxWindow with window caption stcwindow.

https://github.com/nvaccess/nvda/blob/6d97c5a8b74bc423c13a218b7575b2b7be8858e9/source/NVDAObjects/window/__init__.py#L121-L122

elif windowClassName in ("Scintilla","TScintilla"):
    from .scintilla import Scintilla as newCls

That may be one of the reasons.

hwf1324 commented 7 months ago

After adding the windowClassName of wx.stc.StyledTextCtrl to judge the use of the Scintilla NVDAObject. wx.stc.StyledTextCtrl becomes inaccessible, NVDA doesn't speak or is blank.

name:
stcwindow

role:
EDITABLETEXT (8)

states:
FOCUSED, MULTILINE, FOCUSABLE (2, 1048576, 16777216)

value:
None

windowClassName:
wxWindowNR

windowControlID:
-31911

windowHandle:
1839760

location:
left: 244,
top: 287,
width: 763,
height: 212

pythonClass:
<class 'NVDAObjects.Dynamic_EditableTextLogContainerIAccessibleScintillaWindowNVDAObject'>

pythonClassMRO:
class 'NVDAObjects.Dynamic_EditableTextLogContainerIAccessibleScintillaWindowNVDAObject',
class 'globalPlugins.ndtt.logReader.EditableTextLogContainer',
class 'globalPlugins.ndtt.logReader.LogContainer',
class 'NVDAObjects.IAccessible.IAccessible',
class 'NVDAObjects.window.scintilla.Scintilla',
class 'NVDAObjects.behaviors.EditableTextWithAutoSelectDetection',
class 'NVDAObjects.behaviors.EditableText',
class 'NVDAObjects.behaviors.EditableTextWithSuggestions',
class 'NVDAObjects.behaviors.InputFieldWithSuggestions',
class 'NVDAObjects.behaviors.EditableTextBase',
class 'editableText.EditableText',
class 'NVDAObjects.window.Window',
class 'NVDAObjects.NVDAObject',
class 'documentBase.TextContainerObject',
class 'baseObject.ScriptableObject',
class 'baseObject.AutoPropertyObject',
class 'garbageHandler.TrackedObject',
class 'object'