开发者

How to preserve page position in the wx.html.HtmlWindow after link clicked?

开发者 https://www.devze.com 2023-02-19 09:19 出处:网络
I have a wx python application with wx.html.HtmlWindow window: class MyHtmlWindow(wx.html.HtmlWindow):

I have a wx python application with wx.html.HtmlWindow window:

class MyHtmlWindow(wx.html.HtmlWindow):

Method SetPage is used to update html content on the window:

def OpenURL(self, url, save_scroll_pos=True)开发者_JS百科:
    def callback(src, url, save_scroll_pos):
        pos = self.GetViewStart()[1]
        self.SetPage(src)
        if save_scroll_pos:
            self.Scroll(0, pos)
    def errback(err): 
        self.SetPage('<html>Failed:<br>%s</html>' % err.getErrorMessage())

    d = self.DownloadURL(url)
    d.addCallback(callback, url, save_scroll_pos)
    d.addErrback(errback)

I want to save the current scroll position of the page after opening and this code is working. Only one problem, and this is big problem for me: it is rendering html page twice. First after self.SetPage and second after self.Scroll.

So each time I call self.OpenURL I see the page is blinking. It scrolls to the top and right after to the needed position.

I was trying to fix it by handling EVT_PAINT:

    self.Bind(wx.EVT_PAINT, self.OnPaintEvt)        

But self.OnPaintEvt is calling after self.Scroll - so this way not for me.

Any Ideas?


Great Thanks to Wx Developers. They provide very usefull methods: Freeze and Thaw. This is very easy solution:

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

    def errback(err): 
        self.SetPage('<html>Failed:<br>%s</html>' % err.getErrorMessage())

    d = self.DownloadURL(url)
    d.addCallback(callback, url, save_scroll_pos)
    d.addErrback(errback)

No blinking at all! :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消