keyboard movement in wx.html.htmlwindow

26 views
Skip to first unread message

Nathan smith

unread,
May 30, 2019, 5:38:00 PM5/30/19
to wxpytho...@googlegroups.com
Hi there,

So here's what I'm trying to do:

I'm trying to create a window that pops up, processes basic html, and
behaves like an HTML window.

Think wx.textctrl, but multiline and with HTML processing capabilities.

Now here's my problem.

I wrote what I thought was a working html window, and it might be I'm
not sure.

I tried to access it with my screen reader and... It reads nothing.

So then I had a look around the web and found the example program at the
end of this email.

When it loads, my screen reader reads out all the text at once, and then
refuses to allow me to view it otherwise.


For clarification: I am using arrow keys to move about the window, to
very little success.

Is this just an accessibility barrier? Or are the arrow keys being
blocked from moving around or...

Any help is appreciated.

Nathan


Example program:

import wx
import wx.html as html


class MainFrame(wx.Frame):
    """Create MainFrame class."""
    def __init__(self):
        """Initialise the class."""
        wx.Frame.__init__(self, None, -1, 'Demonstrate wxPython Html')
        self.panel = MainPanel(self)
        self.Centre()
        self.html_display.SetPage(self.raw_html())

    @staticmethod
    def raw_html():
        html = ('<p><font color="#4C4C4C", size=2>What do we want: '
                    '<font color="#FF0000">all</font>'
                '</p><h1>Hi</h1>This is a test')
        return html


class MainPanel(wx.Panel):
    """Create a panel class to contain screen widgets."""
    def __init__(self, frame):
        """Initialise the class."""
        wx.Panel.__init__(self, frame)
        html_sizer = self._create_html_control(frame)
        main_sizer = wx.BoxSizer(wx.HORIZONTAL)
        main_sizer.Add(html_sizer, flag=wx.ALL, border=10)
        self.SetSizerAndFit(main_sizer)

    def _create_html_control(self, frame):
        txt_style = wx.VSCROLL|wx.HSCROLL|wx.BORDER_SIMPLE|wx.WANTS_CHARS
        frame.html_display = html.HtmlWindow(self, -1,
                                                size=(400, 200),
name="This sucks.",
                                                style=txt_style)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(frame.html_display)
        return sizer


if __name__ == '__main__':
    """Run the application."""
    screen_app = wx.App()
    main_frame = MainFrame()
    main_frame.Show(True)
    screen_app.MainLoop()

Tim Roberts

unread,
May 31, 2019, 12:56:43 PM5/31/19
to wxpytho...@googlegroups.com
Nathan smith wrote:
>
>
> So here's what I'm trying to do:
> I'm trying to create a window that pops up, processes basic html, and
> behaves like an HTML window.
> Think wx.textctrl, but multiline and with HTML processing capabilities.

Are you thinking of a wx.stc.StyledTextCtrl?


> Now here's my problem.
> I wrote what I thought was a working html window, and it might be I'm
> not sure.
> I tried to access it with my screen reader and... It reads nothing.

On what did you base your code?  Was it a plain TextCtrl?  I admit that
I know little about screen readers, but in order to be read, there has
to be a way for the reader to fetch the contents of your control from code.


> So then I had a look around the web and found the example program at
> the end of this email.
> When it loads, my screen reader reads out all the text at once, and
> then refuses to allow me to view it otherwise.
> For clarification: I am using arrow keys to move about the window, to
> very little success.

Right.  HTML windows are read-only.  They are, essentially, web
browsers.  They don't accept keyboard focus, so you can't navigate with
arrow keys.

And by the way, that sample code shows terrible programming style.  The
frame and the panel are tightly integrated, so that each one pokes
around in the other's insides.  Don't use this as an example of good
Python coding...

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.


Reply all
Reply to author
Forward
0 new messages