wxHtmlWindow - scrolling, link underlining/colors

Hello,

I've got two questions regarding wxHtmlWindow, which I'm trying to convince
to do something it probably wasn't meant to do (behave like a rather fancy
tree control). I've run into two problems.

1. I'm trying to reload a page when a link is clicked and scroll back to
the same position (line) that was visible before the link was clicked.
Sample code:

    def OnLinkClicked(self, linkinfo):
        self.scroll = self.GetScrollPos(wx.wxVERTICAL)
        openbranch(self.tree, int(linkinfo.GetHref()))
        self.SetPage(htmltree(self.tree))
        self.SetScrollPos(wx.wxVERTICAL, self.scroll)

This sets the scrollbar position correctly as far as I can tell, but the
wxHtmlWindow is actually *not* scrolled (it just goes back to the top of
the page). What should I do instead?

2. I'd like to have black, non-underlined links. The link color can be set
in the <body> tag, but how can underlining be disabled? I'd also like to
know whether it's possible to have links with different colors inside the
same window.

···

--
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5@bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
ernq gur yvfg, fb gurer'f ab arrq gb PP.

Andrei wrote:

Hello,

I've got two questions regarding wxHtmlWindow, which I'm trying to convince
to do something it probably wasn't meant to do

Yep.

(behave like a rather fancy
tree control). I've run into two problems.

1. I'm trying to reload a page when a link is clicked and scroll back to
the same position (line) that was visible before the link was clicked.
Sample code:

    def OnLinkClicked(self, linkinfo):
        self.scroll = self.GetScrollPos(wx.wxVERTICAL)
        openbranch(self.tree, int(linkinfo.GetHref()))
        self.SetPage(htmltree(self.tree))
        self.SetScrollPos(wx.wxVERTICAL, self.scroll)

This sets the scrollbar position correctly as far as I can tell, but the
wxHtmlWindow is actually *not* scrolled (it just goes back to the top of
the page). What should I do instead?

Try something like this:

  ppux, ppuy = self.GetScrollPixelsPerUnit()
  psx = self.GetScrollPageSize(wxHORIZONTAL)
  psy = self.GetScrollPageSize(wxVERTICAL)
  vsx, vsy = self.GetViewStart()

  # Do whatever

  self.SetScrollbars(ppux, ppuy, psx, psy, vsx, vsy)

Or maybe doing the last line via wxCallAfter.

2. I'd like to have black, non-underlined links. The link color can be set
in the <body> tag, but how can underlining be disabled? I'd also like to
know whether it's possible to have links with different colors inside the
same window.

No.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I've got two questions regarding wxHtmlWindow, which I'm trying to convince
to do something it probably wasn't meant to do

Yep.

(behave like a rather fancy
tree control). I've run into two problems.

The standard TreeView control isn't pretty or versatile enough as far as I
can tell. I'd need something comparable to the VirtualTreeview for Delphi
(http://www.delphi-gems.com/VirtualTreeview/VTGallery.php), which can look
like this (http://images.delphi-gems.com/XMLEdit.png) - which is close to
what I want
(http://project5.freezope.org/pears/img/future-selectedfolder.png).

1. I'm trying to reload a page when a link is clicked and scroll back to
the same position (line) that was visible before the link was clicked.
Sample code:

<snip>

Try something like this:

  ppux, ppuy = self.GetScrollPixelsPerUnit()
  psx = self.GetScrollPageSize(wxHORIZONTAL)
  psy = self.GetScrollPageSize(wxVERTICAL)
  vsx, vsy = self.GetViewStart()

  # Do whatever

  self.SetScrollbars(ppux, ppuy, psx, psy, vsx, vsy)

That doesn't do anything (tried both with and without wxCallAfter for the
SetScrollbars method, on wxPy 2.4.1.2). The page and the scrollbar just
scroll back to the top after I #Do whatever.

2. I'd like to have black, non-underlined links. The link color can be set
in the <body> tag, but how can underlining be disabled? I'd also like to
know whether it's possible to have links with different colors inside the
same window.

No.

Looking in the docs, I came across some text regarding Tag Handlers. These
and the related wxHtmlWinParser/wxHtmlTagsModule and the HandleTag method
are just black magic to me (I don't understand how they're supposed to fit
into each other and there's way too much C++ magic in there for my limited
abilities), but they do leave the impression that custom parsing should be
possible. Am I mistaken or is it something that isn't available in wxPy (or
is it just way too hard to do)?
Anyway, I think I might have found a workaround for this using
OnCellClicked, GetNext(), SetCursor() and invisible links, which can make
any text behave like a link. This part seems to work ok, so my main issue
is still that scrolling which is of paramount importance to the whole idea.

···

Robin Dunn wrote on Mon, 27 Oct 2003 16:35:10 -0800:

--
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5@bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
ernq gur yvfg, fb gurer'f ab arrq gb PP.

Andrei wrote:

<snip>

Try something like this:

ppux, ppuy = self.GetScrollPixelsPerUnit()
psx = self.GetScrollPageSize(wxHORIZONTAL)
psy = self.GetScrollPageSize(wxVERTICAL)
vsx, vsy = self.GetViewStart()

# Do whatever

self.SetScrollbars(ppux, ppuy, psx, psy, vsx, vsy)

That doesn't do anything (tried both with and without wxCallAfter for the
SetScrollbars method, on wxPy 2.4.1.2). The page and the scrollbar just
scroll back to the top after I #Do whatever.

Try this (it uses a timer instead of excuting it ASAP.) Maybe there is some internal idle handler that is happening after the one wxCallAfter uses:

  wxFutureCall(100, self.SetScrollbars,
                      ppux, ppuy, psx, psy, vsx, vsy)

Looking in the docs, I came across some text regarding Tag Handlers. These
and the related wxHtmlWinParser/wxHtmlTagsModule and the HandleTag method
are just black magic to me (I don't understand how they're supposed to fit
into each other and there's way too much C++ magic in there for my limited
abilities), but they do leave the impression that custom parsing should be
possible. Am I mistaken or is it something that isn't available in wxPy (or
is it just way too hard to do)?

I forgot about the tag handlers. Look in wxpTag.py for an example.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!