Compare commits
3 Commits
b9815f4976
...
25d141d7f8
Author | SHA1 | Date |
---|---|---|
Fierelier | 25d141d7f8 | |
Fierelier | c3f71086d1 | |
Fierelier | d468d76b54 |
21
BirdyNet.py
21
BirdyNet.py
|
@ -26,6 +26,7 @@ from qtpy.QtCore import *
|
|||
from qtpy.QtMultimedia import QSound
|
||||
import configparser
|
||||
import json
|
||||
import time
|
||||
|
||||
os.chdir(sp)
|
||||
distro = os.path.splitext(s.rsplit(os.path.sep)[-1])[0]
|
||||
|
@ -97,6 +98,8 @@ class browserWindow(QMainWindow):
|
|||
|
||||
self.cDoc = browserDoc(self)
|
||||
|
||||
self.cStatusBar = QStatusBar(self)
|
||||
|
||||
self.cResizeElements()
|
||||
self.show()
|
||||
self.cNavigate()
|
||||
|
@ -110,7 +113,11 @@ class browserWindow(QMainWindow):
|
|||
self.cButtonGo.resize(barSize,barSize)
|
||||
|
||||
self.cDoc.move(0,mb + barSize)
|
||||
self.cDoc.resize(self.cWidth,self.cHeight - barSize - mb)
|
||||
self.cDoc.resize(self.cWidth,self.cHeight - barSize - mb - mb)
|
||||
|
||||
self.cStatusBar.move(0,self.cHeight - mb)
|
||||
self.cStatusBar.resize(self.cWidth,mb)
|
||||
self.cStatusBar.showMessage("Status")
|
||||
|
||||
def resizeEvent(self,event):
|
||||
self.cWidth = self.width()
|
||||
|
@ -119,12 +126,20 @@ class browserWindow(QMainWindow):
|
|||
|
||||
def cNavigate(self,event = None):
|
||||
try:
|
||||
print(prettyJson(parseUrl(self.cUrlBar.text())))
|
||||
#print(prettyJson(parseUrl(self.cUrlBar.text())))
|
||||
start = time.time()
|
||||
response = downloadPage(self.cUrlBar.text(),{"User-Agent": self.cUserAgent})
|
||||
end = time.time()
|
||||
print("Downloading page: " +str(end - start))
|
||||
|
||||
infoFetcher(response)
|
||||
self.cDocumentInfo = response
|
||||
|
||||
start = time.time()
|
||||
self.cDoc.cRenderHtml(response["body"].decode("utf-8",errors="ignore"))
|
||||
print(prettyJson(response["headers"]))
|
||||
end = time.time()
|
||||
print("Rendering page: " +str(end - start))
|
||||
#print(prettyJson(response["headers"]))
|
||||
except Exception as e:
|
||||
self.cDoc.cRenderHtml(str(e))
|
||||
raise
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
global HTMLParser
|
||||
from html.parser import HTMLParser
|
||||
|
||||
global html
|
||||
import html
|
||||
|
||||
global browserDoc
|
||||
class browserDoc(QTextBrowser):
|
||||
def __init__(self,*args,**kwargs):
|
||||
|
@ -13,9 +19,46 @@ class browserDoc(QTextBrowser):
|
|||
self.setStyleSheet("QTextBrowser { " +style+ " }")
|
||||
self.anchorClicked.connect(self.cAnchorClicked)
|
||||
|
||||
def cRenderHtml(self,html):
|
||||
class cHtmlParser(HTMLParser):
|
||||
def __init__(self):
|
||||
HTMLParser.__init__(self)
|
||||
self.output = ""
|
||||
|
||||
def handle_starttag(self,tag,attrs):
|
||||
if tag == "img":
|
||||
altText = False
|
||||
for attr in attrs:
|
||||
if attr[0] == "alt":
|
||||
altText = html.escape(attr[1])
|
||||
break
|
||||
|
||||
for attr in attrs:
|
||||
if attr[0] == "src":
|
||||
url = attr[1]
|
||||
if not altText: altText = url.rsplit("/")[-1]
|
||||
self.output += '<a href="' +html.escape(url)+ '">image: ' +html.escape(altText)+ '</a>'
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
self.output += "<" +tag
|
||||
for attr in attrs:
|
||||
self.output += ' ' +html.escape(attr[0])+ '="' +html.escape(attr[1])+ '"'
|
||||
self.output += ">"
|
||||
|
||||
def handle_endtag(self,tag):
|
||||
if tag in ["img"]: return
|
||||
self.output += "</" +html.escape(tag)+ ">"
|
||||
|
||||
def handle_data(self,data):
|
||||
self.output += data
|
||||
|
||||
def cRenderHtml(self,htm):
|
||||
parser = self.cHtmlParser()
|
||||
parser.feed(htm)
|
||||
|
||||
self.clear()
|
||||
self.insertHtml(html.replace("<img","<dummy")) # half-assed slowdown fix
|
||||
self.insertHtml(parser.output)
|
||||
self.update()
|
||||
|
||||
def cAnchorClicked(self,url):
|
||||
|
@ -24,8 +67,9 @@ class browserDoc(QTextBrowser):
|
|||
curUrl = browserWindow.cDocumentInfo["url"]
|
||||
curUrlParsed = parseUrl(curUrl)
|
||||
urlParsed = parseUrl(url)
|
||||
#print("navigating from: " +curUrl)
|
||||
#print("to: " +url)
|
||||
print("---")
|
||||
print("navigating from: " +curUrl)
|
||||
print("to: " +url)
|
||||
if urlParsed["protocol"] == "": # is relative
|
||||
if url[0] == "#":
|
||||
curUrlParsed["anchor"] = url[1:]
|
||||
|
|
Loading…
Reference in New Issue