Compare commits

...

3 Commits

Author SHA1 Message Date
Fierelier 85eb247823 Accurate URL bar, add site title and loading indicator 2021-12-20 06:46:31 +01:00
Fierelier 64a760021e Enable software mode on default 2021-12-20 06:41:56 +01:00
Fierelier 6b7cdeebee Found my old enhancements 2021-12-20 06:39:23 +01:00
2 changed files with 71 additions and 16 deletions

View File

@ -11,7 +11,7 @@ Bad: It still sucks
Prerequisites (Debian and cousins):
sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0 gir1.2-webkit2-4.0
Below "# Script start" you can find a setting for software mode, which you should use if you're experiencing trouble with the viewport not showing up or freezing.
Below "# Script start" you can find a setting for software mode, which you should comment out if you use a modern PC. I don't use the software rendering that comes included with WebKit, as it's unstable in my experience.
"""
import sys
@ -34,8 +34,8 @@ sp = pUp(s)
# Script start
# Uncomment the following line for software-mode
#os.environ["LIBGL_ALWAYS_SOFTWARE"] = "1"
# Comment the following line for hardware acceleration
os.environ["LIBGL_ALWAYS_SOFTWARE"] = "1"
#os.environ["WEBKIT_USE_SINGLE_WEB_PROCESS"] = "1" # Deprecated, not required with this code
import gi
@ -89,6 +89,8 @@ def birdyWebViewConstructor(webView):
class birdyBrowserWindow(Gtk.Window):
def __init__(self,webView,*args,**kwargs):
super().__init__(*args,**kwargs)
self.cTitle = "webkit-inabox-gtk"
self.set_title(self.cTitle)
self.cWidth = 640
self.cHeight = 480
self.resize(self.cWidth,self.cHeight)
@ -113,6 +115,10 @@ class birdyBrowserWindow(Gtk.Window):
self.cFileMenuButton.set_submenu(self.cFileMenu)
self.cMenuBar.add(self.cFileMenuButton)
# Menu - Loading indication
self.cMenuLoadingIndication = Gtk.MenuItem.new_with_label("Loading...")
self.cMenuBar.add(self.cMenuLoadingIndication)
homepage = "about:blank"
self.cUrlEntry = Gtk.Entry()
self.cUrlEntry.set_text(homepage)
@ -121,12 +127,15 @@ class birdyBrowserWindow(Gtk.Window):
self.cMainBox.add(self.cUrlEntry)
self.cWebView = birdyWebViewConstructor(webView)
self.cWebView.connect("load-changed",self.cWebViewLoadChanged)
self.cWebView.connect("notify::uri",self.cUrlChanged)
self.cWebView.connect("notify::title",self.cTitleChanged)
self.cMainBox.add(self.cWebView)
self.cWebView.load_uri(homepage)
self.cResizeElements()
self.set_focus(self.cUrlEntry)
self.cUrlEntry.select_region(0,2)
self.show_all()
self.cMenuLoadingIndication.hide()
def cResizeElements(self):
# cMenuBar
@ -154,12 +163,20 @@ class birdyBrowserWindow(Gtk.Window):
if len(browserWindows) > 0: return
Gtk.main_quit()
def cWebViewLoadChanged(self,widget,event):
def cUrlChanged(self,widget,prop):
url = widget.get_uri()
if url == "about:blank": return
if self.cUrlEntry.get_text() != url: self.cUrlEntry.set_text(url)
def cTitleChanged(self,widget,prop):
self.set_title(widget.get_title() + " - " +self.cTitle)
def cWebViewLoadChanged(self,widget,event):
if event == WebKit2.LoadEvent.STARTED:
self.cMenuLoadingIndication.show()
#if event == WebKit2.LoadEvent.FINISHED:
# birdyWebContext.clear_cache() # This might cause a memory leak?
if event == WebKit2.LoadEvent.FINISHED:
self.cMenuLoadingIndication.hide()
def cOpenWindow(self,*args,**kwargs):
browserWindows.append(birdyBrowserWindow(self.cWebView))

View File

@ -3,12 +3,12 @@
"""
This uses the abandoned QWebKit, which was abandoned by the soydevs making Qt5. I made this before I realized it was fucked.
Not as fat as the GTK version of "my" browser, but outdated. Needs some old Qt5 idk. There was more optimizations I did to this but I lost them and I don't care enough anymore. Fuck this shit.
Not as fat as the GTK version of "my" browser, but outdated. Needs some old Qt5 idk. Use this if you are restricted in RAM and don't need the newest of newest features to access your pages, but do note that this will eventually stop working.
Prerequisites (Debian and cousins):
sudo apt install python3-pyqt5 python3-qtpy
Below "# Script start" you can find a setting for software mode, which you should use if you're experiencing trouble with the viewport not showing up or freezing.
Below "# Script start" you can find a setting for software mode, which you should comment out if you use a modern PC. I don't use the software rendering that comes included with WebKit, as it's unstable in my experience.
"""
import sys
@ -31,8 +31,8 @@ sp = pUp(s)
# Script start
# Uncomment the following line for software-mode
#os.environ["LIBGL_ALWAYS_SOFTWARE"] = "1"
# Comment the following line for hardware acceleration
os.environ["LIBGL_ALWAYS_SOFTWARE"] = "1"
import qtpy
import qtpy.QtGui as QtGui
@ -40,6 +40,7 @@ from qtpy.QtGui import *
from qtpy.QtWidgets import *
from qtpy.QtCore import *
from PyQt5.QtWebKitWidgets import *
from PyQt5.QtWebKit import *
defaultProtocol = "https"
browserWindows = []
@ -61,43 +62,77 @@ def parseUrl(url):
class browserPage(QWebPage):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.defaultUserAgent = super().userAgentForUrl
self.defaultUserAgent = ""
ua = super().userAgentForUrl(QUrl("https://example.com")).split(" ")
skip = False
for word in ua:
if skip == True:
skip = False
continue
if word == "Gecko)": skip = True
self.defaultUserAgent += " " + word
self.defaultUserAgent = self.defaultUserAgent[1:]
#self.defaultUserAgent = "Opera/9.80 (J2ME/MIDP; Opera Mini/4.0.10992/35.5561; U; hr) Presto/2.8.119 Version/11.10"
#self.settings().setAttribute(QWebSettings.AutoLoadImages,False)
self.settings().setMaximumPagesInCache(0)
self.settings().setAttribute(QWebSettings.DnsPrefetchEnabled,False)
# idk if these work, folders need to exist
#self.settings().setAttribute(QWebSettings.LocalStorageEnabled,True)
#self.settings().setLocalStoragePath(p(sp,"LocalStorage"))
#self.settings().setAttribute(QWebSettings.OfflineStorageDatabaseEnabled,True)
#self.settings().setOfflineStorageDefaultQuota(500000000)
#self.settings().setOfflineStoragePath(p(sp,"StorageOffline"))
#self.settings().setAttribute(QWebSettings.OfflineWebApplicationCacheEnabled,True)
#self.settings().setOfflineWebApplicationCacheQuota(500000000)
#self.settings().setOfflineWebApplicationCachePath(p(sp,"AppStorageOffline"))
def userAgentForUrl(self,url):
protocol,domain,path,arguments = parseUrl(url.toString())
if len(domain) < 2: return self.defaultUserAgent(url)
if len(domain) < 2: return self.defaultUserAgent
mainDomain = (domain[-2] + "." + domain[-1]).lower()
if domain[-2].lower() == "google": return ""
return self.defaultUserAgent(url)
return self.defaultUserAgent
class browserView(QWebView):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.window = args[0]
self.setPage(browserPage())
self.cPage = browserPage()
self.setPage(self.cPage)
self.load(QUrl("about:blank"))
self.titleChanged.connect(self.cTitleChanged)
self.urlChanged.connect(self.cUrlChanged)
def cTitleChanged(self):
self.window.setWindowTitle(self.title()+ " - webkit-inabox-qt5")
self.window.setWindowTitle(self.title()+ " - " +self.window.cTitle)
def cUrlChanged(self,url):
self.window.cUrlBar.setText(url.toString())
self.window.cUrlBar.setCursorPosition(0)
self.cPage.settings().clearMemoryCaches()
class browserWindow(QMainWindow):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.cTitle = "webkit-inabox"
self.cTitle = "webkit-inabox-qt5"
self.setWindowTitle(self.cTitle)
self.cWidth = 640
self.cHeight = 480
self.resize(self.cWidth,self.cHeight)
self.cTaskTimer = QTimer()
self.cTaskTimer.setInterval(10000)
self.cTaskTimer.timeout.connect(self.cRunTasks)
self.cTaskTimer.start()
self.cCreateElements()
def cCreateElements(self):
@ -141,6 +176,9 @@ class browserWindow(QMainWindow):
self.cBrowserView.setFocus()
self.cBrowserView.load(QUrl(url))
def cRunTasks(self):
self.cBrowserView.cPage.settings().clearMemoryCaches()
app = QApplication(sys.argv)
browserWindows.append(browserWindow())