Initial commit
This commit is contained in:
commit
e243096962
|
@ -0,0 +1 @@
|
|||
__pycache__
|
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2022
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python3
|
||||
def init(): pass
|
||||
def main():
|
||||
mfp.setProgramName("me.fier.gawk") # Your domain/username and the name of your program
|
||||
|
||||
mfp.paths = [mfp.p(mfp.sd,"module","browser")] + mfp.paths
|
||||
browser = mfp.require("browser")
|
||||
config = mfp.require("config")
|
||||
eig = mfp.require("exception").ignore
|
||||
|
||||
print("Loading addons ...")
|
||||
addonList = eig([],config.readList,eig(None,config.find,mfp.p("addon","addons.txt")))
|
||||
for addonName in addonList:
|
||||
print("> " +addonName)
|
||||
try:
|
||||
addonFile = config.find(mfp.p("addon",addonName,"main.py"))
|
||||
except Exception as e:
|
||||
print("Could not find " +addonName+ ": " +str(e))
|
||||
continue
|
||||
|
||||
addon = mfp.dofile(addonFile) # Add exception handling
|
||||
browser.addon.add(addonName,addon)
|
||||
|
||||
print("Done, starting browser.")
|
||||
browser.start()
|
||||
|
||||
def bootstrap(name,modName):
|
||||
if name in globals(): return
|
||||
import sys, os, importlib
|
||||
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
|
||||
s = os.path.realpath(sys.executable)
|
||||
else:
|
||||
s = os.path.realpath(__file__)
|
||||
|
||||
if not os.path.join(os.path.dirname(s),"module","py") in sys.path:
|
||||
sys.path = [os.path.join(os.path.dirname(s),"module","py")] + sys.path
|
||||
|
||||
mod = importlib.import_module(modName); modl = mod.Bunch()
|
||||
mod.init(mod,modl,s,name)
|
||||
globals()[name] = mod; globals()[name + "l"] = modl
|
||||
|
||||
bootstrap("mfp","me.fier.python")
|
||||
init()
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,12 @@
|
|||
name = mfp.programName.rsplit(".",1)[-1]
|
||||
module = mfp.dofile(mfp.p(mfpl.sd,"module.py"))
|
||||
addon = mfp.dofile(mfp.p(mfpl.sd,"addon.py"))
|
||||
windows = []
|
||||
|
||||
import gi
|
||||
gi.require_version("Gtk","3.0")
|
||||
from gi.repository import Gtk
|
||||
|
||||
def start():
|
||||
windows.append(mfp.require("browser").module.require(mfp.p("window","browser.py")).create())
|
||||
Gtk.main()
|
|
@ -0,0 +1,13 @@
|
|||
addons = mfp.Bunch()
|
||||
|
||||
def remove(name):
|
||||
addons[name].unload()
|
||||
del addons[name]
|
||||
|
||||
def add(name,glb):
|
||||
if name in addons:
|
||||
remove(name)
|
||||
addons[name] = glb
|
||||
glb._addon = mfp.Bunch()
|
||||
glb._addon.name = name
|
||||
if "init" in glb: glb.init()
|
|
@ -0,0 +1,13 @@
|
|||
import os
|
||||
paths = []
|
||||
paths.append(mfp.p(mfpl.sd,"module"))
|
||||
|
||||
modules = mfp.Bunch()
|
||||
def require(mod):
|
||||
if mod in modules: return modules[mod]
|
||||
for path in paths:
|
||||
fpath = mfp.p(path,mod)
|
||||
if os.path.isfile(fpath):
|
||||
modules[mod] = mfp.dofile(fpath)
|
||||
return modules[mod]
|
||||
raise Exception("Module not found: " +mod)
|
|
@ -0,0 +1,49 @@
|
|||
import gi
|
||||
gi.require_version("Gtk","3.0")
|
||||
gi.require_version("WebKit2","4.0")
|
||||
from gi.repository import Gtk,WebKit2
|
||||
|
||||
browser = mfp.require("browser")
|
||||
|
||||
def onResize(obj,event):
|
||||
resizeElements(obj,event.width,event.height)
|
||||
|
||||
def resizeElements(obj,width,height):
|
||||
for webView in obj.cWebViews:
|
||||
webView.set_size_request(width,height)
|
||||
|
||||
def onClose(obj):
|
||||
browser.windows.remove(obj.cParent)
|
||||
for webView in obj.cWebViews: webView.destroy()
|
||||
obj.destroy()
|
||||
if len(browser.windows) == 0:
|
||||
Gtk.main_quit()
|
||||
|
||||
def create():
|
||||
import sys
|
||||
self = mfp.Bunch()
|
||||
obj = Gtk.Window()
|
||||
self.obj = obj
|
||||
|
||||
obj.cMainWrapper = Gtk.ScrolledWindow()
|
||||
obj.add(obj.cMainWrapper)
|
||||
obj.cMain = Gtk.Fixed()
|
||||
obj.cMainWrapper.add(obj.cMain)
|
||||
|
||||
obj.cParent = self
|
||||
obj.set_title(mfp.require("browser").name)
|
||||
obj.resize(640,480)
|
||||
obj.connect("configure-event",onResize)
|
||||
obj.connect("destroy",onClose)
|
||||
|
||||
webView = WebKit2.WebView()
|
||||
obj.cWebViews = []
|
||||
obj.cWebViews.append(webView)
|
||||
obj.cMain.add(webView)
|
||||
webView.load_uri(sys.argv[1])
|
||||
obj.set_focus(webView)
|
||||
|
||||
resizeElements(obj,640,480)
|
||||
|
||||
obj.show_all()
|
||||
return self
|
|
@ -0,0 +1 @@
|
|||
windows = []
|
|
@ -0,0 +1,53 @@
|
|||
import os
|
||||
try:
|
||||
import configparser
|
||||
except Exception:
|
||||
import ConfigParser as configparser
|
||||
|
||||
paths = []
|
||||
|
||||
def find(path,method = os.path.isfile):
|
||||
for p in paths:
|
||||
fp = mfp.p(p,path)
|
||||
if method(fp): return fp
|
||||
raise Exception("Config file not found: " +path)
|
||||
|
||||
def findAll(path,method = os.path.isfile):
|
||||
rtn = []
|
||||
for p in paths:
|
||||
fp = mfp.p(p,path)
|
||||
if method(fp): rtn.append(fp)
|
||||
return rtn
|
||||
|
||||
def readList(path):
|
||||
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]
|
||||
line.strip("\t ")
|
||||
if line == "":
|
||||
del content[index]
|
||||
length -= 1
|
||||
continue
|
||||
content[index] = line
|
||||
index += 1
|
||||
return content
|
||||
|
||||
def readIni(path,config = None):
|
||||
if config == None:
|
||||
config = configparser.ConfigParser()
|
||||
config.optionxform = str
|
||||
config.read(path)
|
||||
return config
|
||||
|
||||
def init():
|
||||
import sys
|
||||
if sys.platform == "windows":
|
||||
paths.append(mfp.p(os.environ["APPDATA"],mfp.programName))
|
||||
else:
|
||||
paths.append(mfp.p(os.environ["HOME"],".config",mfp.programName))
|
||||
paths.append(mfp.p(mfp.sd,"user"))
|
||||
|
||||
init()
|
|
@ -0,0 +1,5 @@
|
|||
def ignore(rtn,func,*args,**kwargs):
|
||||
try:
|
||||
return func(*args,**kwargs)
|
||||
except Exception:
|
||||
return rtn
|
|
@ -0,0 +1,81 @@
|
|||
import os
|
||||
|
||||
# BUNCH
|
||||
try:
|
||||
import munch
|
||||
Bunch = munch.Munch
|
||||
bunchify = munch.munchify
|
||||
unbunchify = munch.unmunchify
|
||||
except Exception:
|
||||
import bunch
|
||||
Bunch = munch.Bunch
|
||||
bunchify = munch.bunchify
|
||||
unbunchify = munch.unbunchify
|
||||
|
||||
# GLOBALS
|
||||
g = Bunch()
|
||||
|
||||
# SCRIPTS
|
||||
paths = []
|
||||
loaded = Bunch()
|
||||
|
||||
def docode(st,name = "Unknown"):
|
||||
code = compile(st,name,"exec")
|
||||
glb = Bunch()
|
||||
glb[distro] = me
|
||||
glb[distro + "l"] = Bunch()
|
||||
glb[distro + "l"].s = name
|
||||
try:
|
||||
glb[distro + "l"].sd = pUp(name)
|
||||
except Exception:
|
||||
pass
|
||||
glb[distro + "l"].g = glb
|
||||
exec(code,glb)
|
||||
return glb
|
||||
|
||||
def dofile(path):
|
||||
return docode(open(path,encoding="utf-8").read(),path)
|
||||
|
||||
def dorequire(name,*args,**kwargs):
|
||||
for path in paths:
|
||||
path = path.replace("?",name)
|
||||
if os.path.isfile(path):
|
||||
return dofile(path,*args,**kwargs)
|
||||
raise Exception("Library " +name+ " not found.")
|
||||
|
||||
def require(name,*args,**kwargs):
|
||||
if not name in loaded:
|
||||
loaded[name] = dorequire(name,*args,**kwargs)
|
||||
return loaded[name]
|
||||
|
||||
# PROGRAM
|
||||
programName = None
|
||||
programNameSet = False
|
||||
def setProgramName(name):
|
||||
global programName,programNameSet
|
||||
if programNameSet: return
|
||||
programNameSet = True
|
||||
programName = name
|
||||
|
||||
# INIT
|
||||
inited = False
|
||||
def init(mod,modl,sp,d):
|
||||
global inited
|
||||
if inited: return
|
||||
global distro,me,p,pUp,programName,programNameSet,s,sd,distro
|
||||
import sys
|
||||
inited = True
|
||||
distro = d
|
||||
me = mod
|
||||
|
||||
p = os.path.join
|
||||
pUp = os.path.dirname
|
||||
s = sp
|
||||
sd = pUp(sp)
|
||||
modl.s = s
|
||||
modl.sd = sd
|
||||
programName = distro + "." + s.replace(modl.sd + os.path.sep,"",1).rsplit(".",1)[0]
|
||||
programNameSet = False
|
||||
|
||||
paths.append(p(modl.sd,"module","?.py"))
|
||||
paths.append(p(modl.sd,"module","?","_main.py"))
|
|
@ -0,0 +1 @@
|
|||
userModules
|
|
@ -0,0 +1 @@
|
|||
mfp.require("browser").module.paths.append(mfp.p(mfp.require("config").paths[0],"module"))
|
Loading…
Reference in New Issue