I am trying to override wxHtmlWindow’s methods so that I can do some processing on html files before displaying them in the browser window. (My ultimate goal is to incorporate some simple css ability in my browser).
Here are the two main methods that I am overriding:
. def LoadFile(self, filename):
. if (not filename.endswith(’.htm.html’)) or
. (not filename_file.endswith(’.html.html’)):
. data = open(filename, ‘r’).read()
. #create a supplementary file in the same directory
. tmp_filename = filename+’.html’ #file will end by .htm[l].html
. tmp_file = open(tmp_filename, ‘w’)
. tmp_file.write(‘processed file’)
. tmp_file.write(data)
. tmp_file.close()
. filename = tmp_filename
. #load the processed file instead
. html.HtmlWindow.LoadFile(self, filename)
. def OnLinkClicked(self, linkinfo):
. target_file = linkinfo.GetHref()
. current = self.GetOpenedPage()
. print repr(current)
. path = os.path.dirname(current)
. print "path = ", path
. print "current = ", current
. print "target_file = ", target_file
. filename = os.path.join(path, target_file)
. print "filename = ", filename
. filename = filename.replace(’\’,’/’)
. print "filename: ", filename+’\n’
. self.LoadFile(filename)
···
=====
The first html file opened (and processed) displays just fine.
u’E:/Copy of rurple0.9.0.1b
/rurple0.9.0.1/html/en/rur.htm.html’
path = E:/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en
current = E:/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en/rur.htm.html
target_file = intro/repeat.htm
filename = E:/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en\intro/repeat.htm
filename: E:/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en/intro/repeat.htm
The second (when I click on a link) doesn’t.
u’/E%3A/Copy of rurple0.9.0.1b
/rurple0.9.0.1/html/en/intro/repeat.htm.html’
path = /E%3A/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en/intro
current = /E%3A/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en/intro/repeat.htm.html
target_file = if.htm
filename = /E%3A/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en/intro\if.htm
filename: /E%3A/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en/intro/if.htm
Traceback (most recent call last):
File “E:\Copy of rurple0.9.0.1b\rurple0.9.0.1\rur_py\browser.py”, line 79, in OnLinkClicked
self.LoadFile(filename)
File “E:\Copy of rurple0.9.0.1b\rurple0.9.0.1\rur_py\browser.py”, line 54, in LoadFile
data = open(filename, ‘r’).read()
IOError: [Errno 2] No such file or directory: u’/E%3A/Copy of rurple0.9.0.1b/rurple0.9.0.1/html/en/intro/if.htm’
===========
As you can see, “E:” gets replaced the second time by “/E%3A”.
Any suggestions?
André