Controlling scrolling and selection in an HtmlWindow

I am using an HtmlWindow as a console to display text content that is
frequently appended at the end. Everything works great, except that I
can't seem to get enough control over scrolling and selection. In
particular I need the following:

   1. Stable selection while content is being added.

This may or may not be fixed if #2 is fixed...

   2. Stable scroll position while content is being added.

I've included a potential fix for this below.

#add content
whtml.Scroll(*pos)

Unfortunately, adding content using AppendToPage automatically scrolls
to the top. I can add code to scroll to the bottom, but unfortunately
the page gets painted briefly while scrolled to the top before the
Scroll to bottom occurs.

def f():
    for x in range(10):
        whtml.AppendToPage('added line %d<br>'%x)
        whtml.Scroll(0,100000) # scroll to bottom (is there a better way
to do this?)

    as_you_go = 0

    def f():
        pos = whtml.GetScrollStart()
        if not as_you_go:
            whtml.Freeze()
        
        for i in xrange(10):
            if as_you_go:
                whtml.Freeze()
            
            whtml.AppendToPage(...)
            if as_you_go:
                whtml.Scroll(*pos)
                whtml.Thaw()
        
        if not as_you_go:
            whtml.Scroll(*pos)
            whtml.Thaw()

I think I can stabilize selection by temporarily stalling new content
while selection is in progress and the mouse or shift key are down, but
I'd like to have a way to record the position of the selection, add
content, then restore the selection position. I don't see any way to do
that with HtmlWindow.

I'm not seeing information about getting or setting the selection in the
documentation. It may not have that functionality from methods.

- Josiah

···

Ken Seehart <ken@seehart.com> wrote:

Thanks. That was quite helpful. The key ingredient was
Freeze()/Thaw().

My new code:

`class HtmlConsole(html.HtmlWindow):

def add(self, s):

    pos = self.GetScrollPos(wx.VERTICAL)

    at_bottom = (pos >=

self.GetScrollRange(wx.VERTICAL)-self.GetScrollPageSize(wx.VERTICAL)-2)

    self.Freeze()

    self.AppendToPage(s+'<br>\n')

    if at_bottom:

        self.Scroll(0,self.GetScrollRange(wx.VERTICAL))

    else:

        self.Scroll(0,pos)

    self.Thaw()

`

Josiah Carlson wrote:

···

ken@seehart.comwxPython-users-unsubscribe@lists.wxwidgets.orgwxPython-users-help@lists.wxwidgets.org

I got scrolling working just fine, but selection seems to be a harder problem.

It seems that HtmlWindow doesn't have any methods for getting/setting the selection range. Of course there is SelectionToText, but that's not much help. SelectWord and SelectLine are also useless because they are based on screen coordinates, and in any case are arbitrary and not general enough.

It's hard to believe that there is no way to access selection based on character offset in the html source. Am I missing something? Perhaps a message based interface? The desired functionality is missing from wxWidgets.

- Ken

Okay, that's what I thought. There doesn't seem to be any way to get

···

at that functionality. https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1696116&group_id=9863 Robin Dunn wrote:

Ken Seehart wrote:

I got scrolling working just fine, but selection seems to be a harder problem.

It seems that HtmlWindow doesn't have any methods for getting/setting the selection range. Of course there is SelectionToText, but that's not much help. SelectWord and SelectLine are also useless because they are based on screen coordinates, and in any case are arbitrary and not general enough.

It's hard to believe that there is no way to access selection based on character offset in the html source. Am I missing something? Perhaps a message based interface? The desired functionality is missing from wxWidgets.

I don't see anything in the current API for this. There is some cell-based information on the current selection, but it appears to be available only when rendering the content. Please file a bug report or feature request about this.