How to scroll the wxPython wx.html.HtmlWindow back to where it was when the user clicked on the link?

I am using wxPython wx.html.HtmlWindow to display part of my interface. The user can scroll through the list of links in a window smaller than the list. When they click on the link, I need to redraw the webpage, but I want to re-position the page to where they clicked it.

I tried MouseEvent.GetLogicalPosition () on an event, but it wants a DC and the best I could do is get the same information as GetPosition (), so I don't have to feed it alone correctly.

I also tried HtmlWindow.CalcScrolledPosition (), but apparently this is not available in the HtmlWindow because I am getting NotImplementedError ...

What I would like is the scroll position, which can be obtained from MouseEvent or OnLinkClicked information.

I know about HtmlWindow.ScrollToAnchor (), but it's jagged and unaesthetic - I'd rather get around it if possible so that I can scroll back to exactly where the user clicked.

Thank!

+2


source to share


4 answers


how about looking at the source of wxHtmlWindow for inspiration? eg wxHtmlWindow::LoadPage()

: it

// store[s the current] scroll position into history item:
int x, y;
GetViewStart(&x, &y);
(*m_History)[m_HistoryPos].SetPos(y);

      

this saved scroll position is used in wxHtmlWindow::HistoryBack()

:



Scroll(0, (*m_History)[m_HistoryPos].GetPos());
Refresh();

      

to return to the saved position.

I would guess that this built-in "last position in the window" handling is not the most "flaky and unaesthetic". could something like this work for you too?

+2


source


Maybe a little late, but with some ax tips and some tips here , I think the call is:

scrollpos = wx.html.HtmlWindow.GetViewStart()[1]

      

and save it and then make the call:



wx.html.HtmlWindow.Scroll(0, scrollpos)

      

works for me. Of course, you need to change wx.html.HtmlWindow to the actual reference to the instance.

+1


source


This is what I do to scroll the page to the previous position. I do this to keep from blinking.

        pos = self.GetViewStart()[1]
        self.Freeze()
        self.SetPage(src)
        if save_scroll_pos:
            self.Scroll(0, pos)
        self.Thaw()

      

+1


source


Typically MouseUp events are fired when events are clicked. If you keep track of the mouse position by capturing any MouseDown events, you will know where the last click (MouseUp) occurred and that should allow you to recover things.

For this particular problem, you might have to do a little bit of work in MouseDown, such as checking if they are in the wxHtmlWindow control, and if so, store something like the line number.

0


source







All Articles