wx.html2.WebView 和屏幕阅读器 [英] wx.html2.WebView and screen readers

查看:27
本文介绍了wx.html2.WebView 和屏幕阅读器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 wxPython 4.0 Phoenix 中,我尝试将 wx.html2.WebView 与屏幕阅读器一起使用.

In wxPython 4.0 Phoenix, I'm trying to use wx.html2.WebView with a screen reader.

无论是使用 JAWS 还是 NVDA,我都必须在小部件上单击鼠标左键才能在可访问的 Web 界面中查看我的页面.

Whether with JAWS or NVDA, I have to make a left mouse click on the Widget to be able to see my page in an accessible Web interface.

这是我的代码,但我知道我在 LoadURL 方法上遇到了同样的问题.

Here is my code, but know that I'm having the same problem with the LoadURL method.

我是否应该添加一些内容,以便在 Widget 显示时焦点直接位于 Web 界面中?

Should I add something so that the focus is directly in the web interface as soon as the Widget is displayed?

预先感谢您的回答.

import wx
import wx.html2

class MyWebView (wx.Dialog):

    def __init__(self, parent):
        wx.Dialog.__init__(self, parent)
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.browser = wx.html2.WebView.New(self)
        self.changeBtn = wx.Button (self, -1, label="Change page")

        # The pages that I want to display disposed in a tuple.
        self.pages = (
        "<html><head><title>Hello everyone !</title></head><body><h1>We're testing wx.html2.WebView with a Screen Reader !</h1></body></html>",
        "<html><head><title>Second page !</title></head><body><h1>This is a second page</h1></body></html>",
        "<html><head><title>Third page !</title></head><body><h1>This is a third page</h1></body></html>"
        )

        self.index = 0
        self.display = self.pages[self.index]
        sizer.Add(self.browser, 1, wx.EXPAND, 10)
        sizer.Add(self.changeBtn)
        self.SetSizer(sizer)
        self.SetSize((700, 700))

    # Events.
        self.changeBtn.Bind (wx.EVT_BUTTON, self.onChangePage)

    def onChangePage (self, evt):
        self.index += 1
        if self.index == len (self.pages):
            self.index = 0
        self.display = self.pages[self.index]
        self.browser.SetPage(self.display, "")

if __name__ == '__main__':
    app = wx.App()
    dialog = MyWebView (None)
    dialog.browser.SetPage(dialog.display, "")
    dialog.Show ()
    app.MainLoop()

亲切的问候.

推荐答案

在 Windows 下,由于 Internet Explorer Server 的一个奇怪错误,您实际上需要单击小部件中的某处,以便屏幕阅读器可以与其交互.一旦进行了最初的点击,屏幕阅读器就可以完美地与小部件配合使用.

Under windows, due to a strange bug with Internet explorer Server, you effectively need to click somewhere in the widget so that the screen readers can interact with it. Once that initial click has been made, screen readers perfectly work with the widget.

请注意,在 C++ 中最新的 wxWidgets 3.1.3 仍然存在相同的问题.事实上,wxWidgets 和 wxPython 都不是这个 bug 的罪魁祸首.使用 ActiveX 和 Win32 API 直接嵌入 Internet Explorer 服务器时也会发生这种情况.

Note that the same problem still occurs with the latest wxWidgets 3.1.3 in C++. In fact, nor wxWidgets, nor wxPython are responsible for this bug. It also occurs when embedding Internet Explorer Server directly using ActiveX and Win32 API.

您可以生成所需的初始鼠标单击,以便通过以下方式访问小部件:

You can generate the required initial mouse click so that the widget becomes accessible with something like this:

robot = wx.UIActionSimulator() 
self.browser.SetFocus() 
position = self.browser.GetPosition() 
position = self.browser.ClientToScreen(position) 
robot.MouseMove(position) 
robot.MouseClick() 

wx.UIActionSimulator 是一个允许像机器人一样生成用户事件的类.通常它用于演示、UI 自动化测试或重放录制的宏.在这里,我们使用它来进行所需的鼠标单击.类似的解决方案也适用于 C++.

wx.UIActionSimulator is a class allowing to generate user events like a robot. Normally it is used for demos, UI automated tests, or replaying recorded macros. Here we use it to make the desired mouse click. A similar solution also works in C++.

  1. 我们将焦点设置在小部件上
  2. 我们得到它相对于窗口的左上角位置
  3. UIActionSimulator 需要绝对屏幕坐标,所以我们需要转换位置
  4. 我们移动鼠标并点击

通过点击小部件的最左上角,不太可能产生不想要的效果,但也并非完全不可能.

By clicking on the very top-left-most point of the widget, it's very unlikely to produce an undesired effect, while not totally impossible.

这篇关于wx.html2.WebView 和屏幕阅读器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆