39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
global browserDoc
|
|
class browserDoc(QTextBrowser):
|
|
def __init__(self,*args,**kwargs):
|
|
super().__init__(*args,**kwargs)
|
|
self.setOpenLinks(False)
|
|
self.anchorClicked.connect(self.cAnchorClicked)
|
|
|
|
def cRenderHtml(self,html):
|
|
self.clear()
|
|
self.insertHtml(html.replace("<img","<dummy")) # half-assed slowdown fix
|
|
self.update()
|
|
|
|
def cAnchorClicked(self,url):
|
|
url = str(url.toEncoded(),"utf-8")
|
|
browserWindow = self.parent()
|
|
curUrl = browserWindow.cDocumentInfo["url"]
|
|
curUrlParsed = parseUrl(curUrl)
|
|
urlParsed = parseUrl(url)
|
|
#print("navigating from: " +curUrl)
|
|
#print("to: " +url)
|
|
if urlParsed["protocol"] == "": # is relative
|
|
if url[0] == "#":
|
|
curUrlParsed["anchor"] = url[1:]
|
|
url = unparseUrl(curUrlParsed)
|
|
elif url[:2] == "//":
|
|
url = curUrlParsed["protocol"] + ":" + url
|
|
elif url[0] == "/":
|
|
urlParsed["protocol"] = curUrlParsed["protocol"]
|
|
urlParsed["domain"] = curUrlParsed["domain"]
|
|
urlParsed["path"] = urlParsed["path"][1:]
|
|
url = unparseUrl(urlParsed)
|
|
else:
|
|
urlParsed["protocol"] = curUrlParsed["protocol"]
|
|
urlParsed["domain"] = curUrlParsed["domain"]
|
|
while len(curUrlParsed["path"]) > 0 and curUrlParsed["path"][-1] == "/": curUrlParsed["path"] = curUrlParsed["path"][:-1]
|
|
urlParsed["path"] = curUrlParsed["path"] + "/" + url
|
|
url = unparseUrl(urlParsed)
|
|
browserWindow.cUrlBar.setText(url)
|
|
browserWindow.cNavigate() |