2021-03-18 15:22:56 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
|
|
|
|
oldexcepthook = sys.excepthook
|
|
|
|
def newexcepthook(type,value,traceback):
|
|
|
|
oldexcepthook(type,value,traceback)
|
|
|
|
#input("Press ENTER to quit.") # - this causes issues with Qt's input hook
|
|
|
|
sys.excepthook = newexcepthook
|
|
|
|
|
|
|
|
import os
|
|
|
|
p = os.path.join
|
|
|
|
pUp = os.path.dirname
|
|
|
|
s = False
|
|
|
|
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
|
|
|
|
s = os.path.realpath(sys.executable)
|
|
|
|
else:
|
|
|
|
s = os.path.realpath(__file__)
|
|
|
|
sp = pUp(s)
|
|
|
|
|
|
|
|
# script start
|
|
|
|
import qtpy
|
2021-03-18 16:57:02 +00:00
|
|
|
import qtpy.QtGui as QtGui
|
2021-03-18 15:22:56 +00:00
|
|
|
from qtpy.QtGui import *
|
|
|
|
from qtpy.QtWidgets import *
|
|
|
|
from qtpy.QtCore import *
|
|
|
|
from qtpy.QtMultimedia import QSound
|
|
|
|
import configparser
|
|
|
|
import json
|
2021-03-19 02:18:18 +00:00
|
|
|
import time
|
2021-03-20 15:01:51 +00:00
|
|
|
browserWindows = []
|
2021-03-18 15:22:56 +00:00
|
|
|
|
|
|
|
os.chdir(sp)
|
|
|
|
distro = os.path.splitext(s.rsplit(os.path.sep)[-1])[0]
|
2021-03-18 18:04:27 +00:00
|
|
|
version = {
|
|
|
|
"major": 0,
|
2021-03-20 16:24:16 +00:00
|
|
|
"minor": 5,
|
2021-03-20 16:58:54 +00:00
|
|
|
"patch": 1,
|
2021-03-18 18:04:27 +00:00
|
|
|
"stage": "dev"
|
|
|
|
}
|
|
|
|
versionString = ".".join(map(str,[version["major"],version["minor"]]))
|
|
|
|
versionStringExt = ".".join(map(str,[version["major"],version["minor"],version["patch"]])) + " " + version["stage"]
|
2021-03-18 15:22:56 +00:00
|
|
|
|
|
|
|
def runCode(str, lcs = False, description = "loose-code"):
|
|
|
|
if lcs == False: lcs = {}
|
|
|
|
code = compile(str,description,"exec")
|
|
|
|
exec(code,globals(),lcs)
|
|
|
|
return lcs
|
|
|
|
|
|
|
|
def runScript(sf, lcs = False):
|
|
|
|
if lcs == False: lcs = {}
|
|
|
|
with open(sf) as script:
|
|
|
|
runCode(script.read(),lcs,sf)
|
|
|
|
return lcs
|
|
|
|
|
|
|
|
def getDataDir(appName):
|
|
|
|
basePath = False
|
|
|
|
if sys.platform.startswith("win"):
|
2021-03-18 16:55:14 +00:00
|
|
|
if "appdata" in os.environ: basePath = os.environ["appdata"]
|
2021-03-18 15:22:56 +00:00
|
|
|
elif sys.platform.startswith("linux"):
|
2021-03-18 16:55:14 +00:00
|
|
|
if "XDG_DATA_HOME" in os.environ:
|
|
|
|
basePath = os.environ["XDG_DATA_HOME"]
|
|
|
|
else:
|
|
|
|
if "HOME" in os.environ: basePath = p(os.environ["HOME"],".config")
|
2021-03-18 15:22:56 +00:00
|
|
|
elif sys.platform.startswith("darwin"):
|
2021-03-18 16:55:14 +00:00
|
|
|
if "HOME" in os.environ: basePath = p(os.environ["HOME"],"Library","Application Support")
|
2021-03-18 15:22:56 +00:00
|
|
|
|
|
|
|
if not basePath: raise
|
|
|
|
return p(basePath,appName)
|
|
|
|
|
|
|
|
def prettyJson(ls):
|
|
|
|
return json.dumps(ls,indent=2)
|
|
|
|
|
|
|
|
class browserWindow(QMainWindow):
|
|
|
|
def __init__(self,*args,**kwargs):
|
|
|
|
super().__init__(*args,**kwargs)
|
2021-03-19 02:37:41 +00:00
|
|
|
self.cTitle = "Hello World - " +distro+ " " +versionStringExt
|
2021-03-18 15:22:56 +00:00
|
|
|
self.cWidth = 640
|
|
|
|
self.cHeight = 480
|
|
|
|
self.setWindowTitle(self.cTitle)
|
|
|
|
self.resize(self.cWidth,self.cHeight)
|
|
|
|
self.cDocumentInfo = {
|
|
|
|
"url": "",
|
|
|
|
"body": "",
|
|
|
|
"headers": {},
|
|
|
|
# additional info:
|
|
|
|
"baseUrl": ""
|
|
|
|
}
|
2021-03-18 18:04:54 +00:00
|
|
|
self.cUserAgent = config["default"]["useragent"].replace("$OS",sys.platform).replace("$VER",versionString).replace("$DIST",distro)
|
2021-03-18 15:22:56 +00:00
|
|
|
self.cCreateElements()
|
|
|
|
|
|
|
|
def cCreateElements(self):
|
|
|
|
self.cMenuBar = self.menuBar()
|
2021-03-20 15:01:51 +00:00
|
|
|
self.cFileMenu = self.cMenuBar.addMenu("&File")
|
|
|
|
self.cNewWindowButton = self.cFileMenu.addAction("New &window")
|
|
|
|
self.cNewWindowButton.triggered.connect(self.cNewWindow)
|
|
|
|
self.cViewMenu = self.cMenuBar.addMenu("&View")
|
2021-03-18 15:22:56 +00:00
|
|
|
|
|
|
|
self.cUrlBar = QLineEdit(config["default"]["home"],self)
|
2021-03-20 14:59:11 +00:00
|
|
|
self.cUrlBar.returnPressed.connect(self.cNavigate)
|
2021-03-18 15:22:56 +00:00
|
|
|
self.cButtonGo = QPushButton("Go",self)
|
|
|
|
self.cButtonGo.clicked.connect(self.cNavigate)
|
|
|
|
|
|
|
|
self.cDoc = browserDoc(self)
|
|
|
|
|
2021-03-19 02:18:42 +00:00
|
|
|
self.cStatusBar = QStatusBar(self)
|
2021-03-19 18:12:28 +00:00
|
|
|
self.cStatusBar.showMessage("Please wait...")
|
2021-03-19 02:18:42 +00:00
|
|
|
|
2021-03-18 15:22:56 +00:00
|
|
|
self.cResizeElements()
|
|
|
|
self.show()
|
|
|
|
self.cNavigate()
|
2021-03-20 15:00:27 +00:00
|
|
|
self.cUrlBar.setFocus()
|
2021-03-18 15:22:56 +00:00
|
|
|
|
|
|
|
def cResizeElements(self):
|
|
|
|
barSize = 22
|
|
|
|
mb = self.cMenuBar.height()
|
|
|
|
self.cUrlBar.move(0,mb)
|
|
|
|
self.cUrlBar.resize(self.cWidth - barSize,barSize)
|
|
|
|
self.cButtonGo.move(self.cWidth - barSize,mb)
|
|
|
|
self.cButtonGo.resize(barSize,barSize)
|
|
|
|
|
|
|
|
self.cDoc.move(0,mb + barSize)
|
2021-03-19 02:18:42 +00:00
|
|
|
self.cDoc.resize(self.cWidth,self.cHeight - barSize - mb - mb)
|
|
|
|
|
|
|
|
self.cStatusBar.move(0,self.cHeight - mb)
|
|
|
|
self.cStatusBar.resize(self.cWidth,mb)
|
2021-03-18 15:22:56 +00:00
|
|
|
|
|
|
|
def resizeEvent(self,event):
|
|
|
|
self.cWidth = self.width()
|
|
|
|
self.cHeight = self.height()
|
|
|
|
self.cResizeElements()
|
|
|
|
|
2021-03-20 15:01:51 +00:00
|
|
|
def closeEvent(self,event):
|
|
|
|
browserWindows.remove(self)
|
|
|
|
event.accept()
|
|
|
|
|
2021-03-18 15:22:56 +00:00
|
|
|
def cNavigate(self,event = None):
|
|
|
|
try:
|
2021-03-19 02:18:18 +00:00
|
|
|
#print(prettyJson(parseUrl(self.cUrlBar.text())))
|
2021-03-19 18:12:28 +00:00
|
|
|
self.cStatusBar.showMessage("Downloading...")
|
|
|
|
self.update()
|
2021-03-19 02:18:18 +00:00
|
|
|
start = time.time()
|
2021-03-18 18:04:54 +00:00
|
|
|
response = downloadPage(self.cUrlBar.text(),{"User-Agent": self.cUserAgent})
|
2021-03-20 16:23:38 +00:00
|
|
|
self.cUrlBar.setText(response["url"])
|
2021-03-19 02:18:18 +00:00
|
|
|
end = time.time()
|
|
|
|
print("Downloading page: " +str(end - start))
|
|
|
|
|
2021-03-18 15:22:56 +00:00
|
|
|
infoFetcher(response)
|
|
|
|
self.cDocumentInfo = response
|
2021-03-19 02:18:18 +00:00
|
|
|
|
2021-03-19 18:12:28 +00:00
|
|
|
self.cStatusBar.showMessage("Rendering...")
|
|
|
|
self.update()
|
2021-03-19 02:18:18 +00:00
|
|
|
start = time.time()
|
2021-03-18 15:22:56 +00:00
|
|
|
self.cDoc.cRenderHtml(response["body"].decode("utf-8",errors="ignore"))
|
2021-03-19 02:18:18 +00:00
|
|
|
end = time.time()
|
|
|
|
print("Rendering page: " +str(end - start))
|
2021-03-20 15:00:27 +00:00
|
|
|
self.cDoc.setFocus()
|
2021-03-19 18:12:28 +00:00
|
|
|
self.cStatusBar.showMessage("Ready")
|
|
|
|
self.update()
|
2021-03-19 02:18:18 +00:00
|
|
|
#print(prettyJson(response["headers"]))
|
2021-03-18 15:22:56 +00:00
|
|
|
except Exception as e:
|
|
|
|
self.cDoc.cRenderHtml(str(e))
|
|
|
|
raise
|
2021-03-20 15:01:51 +00:00
|
|
|
|
|
|
|
def cNewWindow(self):
|
|
|
|
w = browserWindow()
|
|
|
|
browserWindows.append(w)
|
|
|
|
w.show()
|
2021-03-18 15:22:56 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
# load program default addons
|
|
|
|
addonDir = p(sp,"addons")
|
|
|
|
for root,dirs,files in os.walk(addonDir):
|
|
|
|
for file in files:
|
|
|
|
ffile = p(root,file)
|
|
|
|
lfile = ffile.replace(addonDir + os.path.sep,"",1)
|
|
|
|
if lfile[0] == "-": continue
|
|
|
|
print("Running addon: " +lfile)
|
|
|
|
runScript(ffile)
|
|
|
|
break
|
|
|
|
|
|
|
|
global dataDir
|
|
|
|
dataDir = getDataDir(distro)
|
|
|
|
|
|
|
|
global config
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
|
|
|
|
# read program default config
|
|
|
|
config.read(distro + ".ini")
|
|
|
|
|
|
|
|
# read user config
|
|
|
|
if os.path.isfile(p(dataDir,"config.ini")):
|
|
|
|
config.read(p(dataDir,"config.ini"))
|
|
|
|
|
|
|
|
app = QApplication(sys.argv)
|
2021-03-18 16:57:02 +00:00
|
|
|
try:
|
|
|
|
app.setWindowIcon(QtGui.QIcon("assets/BirdyNet-XP.ico"))
|
|
|
|
except Exception as e:
|
|
|
|
print("Could not set window icon: " +print(e))
|
2021-03-20 15:01:51 +00:00
|
|
|
browserWindows.append(browserWindow())
|
2021-03-18 15:22:56 +00:00
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|