Compare commits

...

8 Commits

Author SHA1 Message Date
Fierelier b7d7d66f0b Update addons.txt 2023-01-10 15:27:20 +01:00
Fierelier 9306959dfe Add addon: contextMenuWindow 2023-01-10 15:26:43 +01:00
Fierelier 6f2b747e0c Add addon: contextMenuGo 2023-01-10 15:26:23 +01:00
Fierelier 317b00178a Add addon: contextMenu 2023-01-10 15:26:08 +01:00
Fierelier 28c0e0582b Assume about:blank when no URL given 2023-01-10 15:25:37 +01:00
Fierelier b0ff40d137 Add missing prerequisite 2023-01-10 14:22:35 +01:00
Fierelier 88ae0029d6 Add parseComments argument to readList 2022-12-20 23:58:50 +01:00
Fierelier 2443494ac0 Change resize naming convention 2022-12-19 19:35:29 +01:00
7 changed files with 118 additions and 11 deletions

View File

@ -1,14 +1,17 @@
import sys
import gi
gi.require_version("Gtk","3.0")
gi.require_version("WebKit2","4.0")
from gi.repository import Gtk,WebKit2
browser = mfp.require("browser")
if len(sys.argv) < 2:
sys.argv.append("about:blank")
def onResize(obj,event):
resizeElements(obj,event.width,event.height)
def resizeHandler(obj,event):
onResize(obj,event.width,event.height)
def resizeElements(obj,width,height):
def onResize(obj,width,height):
for webView in obj.cWebViews:
webView.set_size_request(width,height)
@ -19,11 +22,11 @@ def onClose(obj):
if len(browser.windows) == 0:
Gtk.main_quit()
def create():
import sys
def create(url = sys.argv[1]):
self = mfp.Bunch()
obj = Gtk.Window()
self.obj = obj
self.data = mfp.Bunch()
obj.cMainWrapper = Gtk.ScrolledWindow()
obj.add(obj.cMainWrapper)
@ -33,7 +36,7 @@ def create():
obj.cParent = self
obj.set_title(browser.name)
obj.resize(640,480)
obj.connect("configure-event",onResize)
obj.connect("configure-event",resizeHandler)
obj.connect("destroy",onClose)
webView = WebKit2.WebView()
@ -43,10 +46,10 @@ def create():
obj.cWebViews = []
obj.cWebViews.append(webView)
obj.cMain.add(webView)
webView.load_uri(sys.argv[1])
webView.load_uri(url)
obj.set_focus(webView)
resizeElements(obj,640,480)
onResize(obj,640,480)
obj.show_all()
return self

View File

@ -19,13 +19,14 @@ def findAll(path,method = os.path.isfile):
if method(fp): rtn.append(fp)
return rtn
def readList(path):
def readList(path,parseComments = True):
with open(path,encoding="utf-8") as f:
content = f.read().replace("\r","").strip("\n").split("\n")
index = 0
length = len(content)
while index < length:
line = content[index]
if parseComments: line = line.split("#",1)[0]
line.strip("\t ")
if line == "":
del content[index]

View File

@ -1,4 +1,4 @@
Gawk is a minimal browser. It opens the page you give as the first argument and gives you a default WebKit browser. Any further functionality has to be added/replaced with addons.
Prerequisites:
sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0 gir1.2-webkit2-4.0
sudo apt install python3-munch python3-gi python3-gi-cairo gir1.2-gtk-3.0 gir1.2-webkit2-4.0

View File

@ -1 +1,5 @@
userModules
userModules
title
contextMenu
contextMenuWindow
contextMenuGo

View File

@ -0,0 +1,37 @@
import gi
gi.require_version("WebKit2","4.0")
from gi.repository import WebKit2,Gio
browser = mfp.require("browser")
def addItem(status,name,func):
action = simpleAction(status,name,func)
item = WebKit2.ContextMenuItem.new_from_gaction(action,name,None)
status.contextMenu.prepend(item)
def simpleAction(status,name,func):
action = Gio.SimpleAction.new(name,None)
action.cStatus = status
action.cFunc = func
action.connect("activate",runAction)
return action
def runAction(action,_):
action.cFunc(action.cStatus)
def onMenu(*args):
status = mfp.Bunch()
status.webView = args[0]
status.contextMenu = args[1]
status.event = args[2]
status.hit = args[3]
status.addon = mfpl.g
status.contextMenu.prepend(WebKit2.ContextMenuItem.new_separator())
browser.event.trigger("contextMenu:created",status)
def onWebviewCreated(webView):
webView.connect("context-menu",onMenu)
eventHandler = mfp.Bunch()
eventHandler["webview:created"] = onWebviewCreated

View File

@ -0,0 +1,53 @@
import gi
gi.require_version("Gtk","3.0")
gi.require_version("WebKit2","4.0")
from gi.repository import Gtk,WebKit2
defaultProtocol = "http"
def resizeHandler(obj,event):
onResize(obj,event.width,event.height)
def onResize(obj,width,height):
obj.cMain.move(obj.cUrlBox,5,5)
obj.cUrlBox.set_size_request(width - 10,32)
obj.cMain.move(obj.cGoButton,width - 65,height - 35)
obj.cGoButton.set_size_request(60,30)
def doGo(button):
window = button.get_toplevel()
uri = window.cUrlBox.get_text()
uri = uri.split(":",1)
if len(uri) < 2: uri = [defaultProtocol] + uri
window.cStatus.webView.load_uri(":".join(uri))
window.close()
def goAction(status):
obj = Gtk.Window()
obj.set_title("Go... (" +status.webView.cWindow.get_title()+ ")")
obj.resize(320,80)
obj.connect("configure-event",resizeHandler)
obj.cMainWrapper = Gtk.ScrolledWindow()
obj.add(obj.cMainWrapper)
obj.cMain = Gtk.Fixed()
obj.cMainWrapper.add(obj.cMain)
obj.cStatus = status
obj.cUrlBox = Gtk.Entry()
obj.cUrlBox.set_text(status.webView.get_uri())
obj.cUrlBox.connect("activate",doGo)
obj.cMain.add(obj.cUrlBox)
obj.cGoButton = Gtk.Button()
obj.cGoButton.set_label("Go!")
obj.cGoButton.connect("clicked",doGo)
obj.cMain.add(obj.cGoButton)
onResize(obj,320,80)
obj.show_all()
def addGo(status):
status.addon.addItem(status,"Go ...",goAction)
eventHandler = mfp.Bunch()
eventHandler["contextMenu:created"] = addGo

View File

@ -0,0 +1,9 @@
def newAction(status):
browser = mfp.require("browser")
browser.windows.append(mfp.require("browser").module.require(mfp.p("window","browser.py")).create("about:blank"))
def addNew(status):
status.addon.addItem(status,"New window",newAction)
eventHandler = mfp.Bunch()
eventHandler["contextMenu:created"] = addNew