Initial commit
This commit is contained in:
3
src/core/__init__.py
Normal file
3
src/core/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Core Module
|
||||
"""
|
3
src/core/containers/__init__.py
Normal file
3
src/core/containers/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Containers Module
|
||||
"""
|
47
src/core/containers/base_container.py
Normal file
47
src/core/containers/base_container.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from .header_container import HeaderContainer
|
||||
from .body_container import BodyContainer
|
||||
|
||||
|
||||
|
||||
class BaseContainer(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(BaseContainer, self).__init__()
|
||||
|
||||
self.ctx = self.get_style_context()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
self.ctx.add_class("base-container")
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("update_transparency", self._update_transparency)
|
||||
event_system.subscribe("remove_transparency", self._remove_transparency)
|
||||
|
||||
def _load_widgets(self):
|
||||
self.add(HeaderContainer())
|
||||
self.add(BodyContainer())
|
||||
|
||||
def _update_transparency(self):
|
||||
self.ctx.add_class(f"mw_transparency_{settings.theming.transparency}")
|
||||
|
||||
def _remove_transparency(self):
|
||||
self.ctx.remove_class(f"mw_transparency_{settings.theming.transparency}")
|
44
src/core/containers/body_container.py
Normal file
44
src/core/containers/body_container.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from .left_container import LeftContainer
|
||||
from .center_container import CenterContainer
|
||||
from .right_container import RightContainer
|
||||
|
||||
|
||||
|
||||
class BodyContainer(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(BodyContainer, self).__init__()
|
||||
|
||||
self.ctx = self.get_style_context()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.HORIZONTAL)
|
||||
self.ctx.add_class("body-container")
|
||||
self.set_homogeneous(True)
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
|
||||
def _load_widgets(self):
|
||||
self.add(LeftContainer())
|
||||
self.add(CenterContainer())
|
||||
self.add(RightContainer())
|
48
src/core/containers/center_container.py
Normal file
48
src/core/containers/center_container.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from ..widgets.webkit.webkit_ui import WebkitUI
|
||||
|
||||
|
||||
|
||||
class CenterContainer(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(CenterContainer, self).__init__()
|
||||
|
||||
self._builder = settings_manager.get_builder()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
ctx = self.get_style_context()
|
||||
ctx.add_class("center-container")
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
# event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
glade_box = self._builder.get_object("glade_box")
|
||||
button = Gtk.Button(label = "Click Me!")
|
||||
|
||||
button.connect("clicked", self._hello_world)
|
||||
|
||||
self.add(button)
|
||||
self.add(glade_box)
|
||||
self.add( WebkitUI() )
|
||||
|
||||
def _hello_world(self, widget = None, eve = None):
|
||||
logger.debug("Hello, World!")
|
46
src/core/containers/header_container.py
Normal file
46
src/core/containers/header_container.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from ..widgets.transparency_scale import TransparencyScale
|
||||
|
||||
|
||||
|
||||
class HeaderContainer(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(HeaderContainer, self).__init__()
|
||||
|
||||
self.ctx = self.get_style_context()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.HORIZONTAL)
|
||||
self.ctx.add_class("header-container")
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
|
||||
def _load_widgets(self):
|
||||
button = Gtk.Button(label = "Interactive Debug")
|
||||
button.connect("clicked", self._interactive_debug)
|
||||
|
||||
self.add(TransparencyScale())
|
||||
self.add(button)
|
||||
|
||||
def _interactive_debug(self, widget = None, eve = None):
|
||||
event_system.emit("load_interactive_debug")
|
35
src/core/containers/left_container.py
Normal file
35
src/core/containers/left_container.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class LeftContainer(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(LeftContainer, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
ctx = self.get_style_context()
|
||||
ctx.add_class("left-container")
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
# event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
35
src/core/containers/right_container.py
Normal file
35
src/core/containers/right_container.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class RightContainer(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(RightContainer, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
ctx = self.get_style_context()
|
||||
ctx.add_class("right-container")
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
# event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
3
src/core/controllers/__init__.py
Normal file
3
src/core/controllers/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Controllers Module
|
||||
"""
|
72
src/core/controllers/base_controller.py
Normal file
72
src/core/controllers/base_controller.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# Python imports
|
||||
import os
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from libs.mixins.ipc_signals_mixin import IPCSignalsMixin
|
||||
from libs.mixins.keyboard_signals_mixin import KeyboardSignalsMixin
|
||||
|
||||
from ..containers.base_container import BaseContainer
|
||||
|
||||
from .base_controller_data import BaseControllerData
|
||||
from .bridge_controller import BridgeController
|
||||
|
||||
|
||||
|
||||
class BaseController(IPCSignalsMixin, KeyboardSignalsMixin, BaseControllerData):
|
||||
def __init__(self, args, unknownargs):
|
||||
self.setup_controller_data()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_controllers()
|
||||
|
||||
if args.no_plugins == "false":
|
||||
self.plugins.launch_plugins()
|
||||
|
||||
for arg in unknownargs + [args.new_tab,]:
|
||||
if os.path.isfile(arg):
|
||||
message = f"FILE|{arg}"
|
||||
event_system.emit("post_file_to_ipc", message)
|
||||
|
||||
if os.path.isdir(arg):
|
||||
message = f"DIR|{arg}"
|
||||
event_system.emit("post_file_to_ipc", message)
|
||||
|
||||
logger.info(f"Made it past {self.__class__} loading...")
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
def _setup_signals(self):
|
||||
self.window.connect("focus-out-event", self.unset_keys_and_data)
|
||||
self.window.connect("key-press-event", self.on_global_key_press_controller)
|
||||
self.window.connect("key-release-event", self.on_global_key_release_controller)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("shutting_down", lambda: print("Shutting down..."))
|
||||
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
||||
event_system.subscribe("handle_dir_from_ipc", self.handle_dir_from_ipc)
|
||||
event_system.subscribe("tggl_top_main_menubar", self._tggl_top_main_menubar)
|
||||
|
||||
def _load_controllers(self):
|
||||
BridgeController()
|
||||
|
||||
def _tggl_top_main_menubar(self):
|
||||
logger.debug("_tggl_top_main_menubar > stub...")
|
||||
|
||||
def setup_builder_and_container(self):
|
||||
self.builder = Gtk.Builder()
|
||||
self.builder.add_from_file(settings_manager.get_glade_file())
|
||||
self.builder.expose_object("main_window", self.window)
|
||||
|
||||
settings_manager.set_builder(self.builder)
|
||||
self.base_container = BaseContainer()
|
||||
|
||||
settings_manager.register_signals_to_builder([self, self.base_container])
|
83
src/core/controllers/base_controller_data.py
Normal file
83
src/core/controllers/base_controller_data.py
Normal file
@@ -0,0 +1,83 @@
|
||||
# Python imports
|
||||
import os
|
||||
import subprocess
|
||||
from shutil import which
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from plugins.plugins_controller import PluginsController
|
||||
|
||||
|
||||
|
||||
class BaseControllerData:
|
||||
''' BaseControllerData contains most of the state of the app at ay given time. It also has some support methods. '''
|
||||
|
||||
def setup_controller_data(self) -> None:
|
||||
self.window = settings_manager.get_main_window()
|
||||
self.builder = None
|
||||
self.base_container = None
|
||||
self.was_midified_key = False
|
||||
self.ctrl_down = False
|
||||
self.shift_down = False
|
||||
self.alt_down = False
|
||||
|
||||
self.setup_builder_and_container()
|
||||
self.plugins = PluginsController()
|
||||
|
||||
def get_base_container(self):
|
||||
return self.base_container
|
||||
|
||||
def clear_console(self) -> None:
|
||||
''' Clears the terminal screen. '''
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
|
||||
def call_method(self, _method_name: str, data: type) -> type:
|
||||
'''
|
||||
Calls a method from scope of class.
|
||||
|
||||
Parameters:
|
||||
a (obj): self
|
||||
b (str): method name to be called
|
||||
c (*): Data (if any) to be passed to the method.
|
||||
Note: It must be structured according to the given methods requirements.
|
||||
|
||||
Returns:
|
||||
Return data is that which the calling method gives.
|
||||
'''
|
||||
method_name = str(_method_name)
|
||||
method = getattr(self, method_name, lambda data: f"No valid key passed...\nkey={method_name}\nargs={data}")
|
||||
return method(*data) if data else method()
|
||||
|
||||
def has_method(self, obj: type, method: type) -> type:
|
||||
''' Checks if a given method exists. '''
|
||||
return callable(getattr(obj, method, None))
|
||||
|
||||
def clear_children(self, widget: type) -> None:
|
||||
''' Clear children of a gtk widget. '''
|
||||
for child in widget.get_children():
|
||||
widget.remove(child)
|
||||
|
||||
def get_clipboard_data(self, encoding = "utf-8") -> str:
|
||||
if which("xclip"):
|
||||
command = ['xclip','-selection','clipboard']
|
||||
else:
|
||||
logger.info('xclip not found...')
|
||||
return
|
||||
|
||||
proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout = subprocess.PIPE)
|
||||
retcode = proc.wait()
|
||||
data = proc.stdout.read()
|
||||
return data.decode(encoding).strip()
|
||||
|
||||
def set_clipboard_data(self, data: type, encoding = "utf-8") -> None:
|
||||
if which("xclip"):
|
||||
command = ['xclip','-selection','clipboard']
|
||||
else:
|
||||
logger.info('xclip not found...')
|
||||
return
|
||||
|
||||
proc = subprocess.Popen(command, stdin = subprocess.PIPE)
|
||||
proc.stdin.write(data.encode(encoding))
|
||||
proc.stdin.close()
|
||||
retcode = proc.wait()
|
43
src/core/controllers/bridge_controller.py
Normal file
43
src/core/controllers/bridge_controller.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# Python imports
|
||||
import base64
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class BridgeController:
|
||||
def __init__(self):
|
||||
|
||||
self.opened_files = {}
|
||||
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("handle_bridge_event", self.handle_bridge_event)
|
||||
|
||||
|
||||
def handle_bridge_event(self, event):
|
||||
match event.topic:
|
||||
case "save":
|
||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
||||
case "close":
|
||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
||||
case "load_buffer":
|
||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
||||
case "load_file":
|
||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
||||
case "alert":
|
||||
content = base64.b64decode( event.content.encode() ).decode("utf-8")
|
||||
logger.info(f"\nMessage Topic: {event.topic}\nMessage Content: {content}")
|
||||
case "error":
|
||||
content = base64.b64decode( event.content.encode() ).decode("utf-8")
|
||||
logger.info(content)
|
||||
case _:
|
||||
...
|
3
src/core/widgets/__init__.py
Normal file
3
src/core/widgets/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Widgets Module
|
||||
"""
|
48
src/core/widgets/transparency_scale.py
Normal file
48
src/core/widgets/transparency_scale.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class TransparencyScale(Gtk.Scale):
|
||||
def __init__(self):
|
||||
super(TransparencyScale, self).__init__()
|
||||
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_digits(0)
|
||||
self.set_value_pos(Gtk.PositionType.RIGHT)
|
||||
self.add_mark(50.0, Gtk.PositionType.TOP, "50%")
|
||||
self.set_hexpand(True)
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("value-changed", self._update_transparency)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
adjust = self.get_adjustment()
|
||||
adjust.set_lower(0)
|
||||
adjust.set_upper(99)
|
||||
adjust.set_value(settings.theming.transparency)
|
||||
adjust.set_step_increment(1.0)
|
||||
|
||||
def _update_transparency(self, range):
|
||||
event_system.emit("remove_transparency")
|
||||
tp = int(range.get_value())
|
||||
settings.theming.transparency = tp
|
||||
event_system.emit("update_transparency")
|
3
src/core/widgets/webkit/__init__.py
Normal file
3
src/core/widgets/webkit/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
WebKit2 UI Module
|
||||
"""
|
108
src/core/widgets/webkit/webkit_ui.py
Normal file
108
src/core/widgets/webkit/webkit_ui.py
Normal file
@@ -0,0 +1,108 @@
|
||||
# Python imports
|
||||
import json
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gdk', '3.0')
|
||||
gi.require_version('WebKit2', '4.0')
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import WebKit2
|
||||
|
||||
# Application imports
|
||||
from libs.data_types import Event
|
||||
|
||||
|
||||
|
||||
class WebkitUI(WebKit2.WebView):
|
||||
def __init__(self):
|
||||
super(WebkitUI, self).__init__()
|
||||
|
||||
# self.get_context().set_sandbox_enabled(False)
|
||||
|
||||
self._load_settings()
|
||||
self._setup_styling()
|
||||
self._subscribe_to_events()
|
||||
self._load_view()
|
||||
self._setup_content_manager()
|
||||
|
||||
self.show_all()
|
||||
|
||||
if settings_manager.is_debug():
|
||||
inspector = self.get_inspector()
|
||||
inspector.show()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_vexpand(True)
|
||||
self.set_hexpand(True)
|
||||
self.set_background_color( Gdk.RGBA(0, 0, 0, 0.0) )
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe(f"ui_message", self.ui_message)
|
||||
|
||||
def _load_settings(self):
|
||||
self.set_settings( WebkitUISettings() )
|
||||
|
||||
def _load_view(self):
|
||||
path = settings_manager.get_context_path()
|
||||
data = None
|
||||
|
||||
with open(f"{path}/index.html", "r") as f:
|
||||
data = f.read()
|
||||
|
||||
self.load_html(content = data, base_uri = f"file://{path}/")
|
||||
|
||||
def _setup_content_manager(self):
|
||||
content_manager = self.get_user_content_manager()
|
||||
|
||||
content_manager.connect("script-message-received", self._process_js_message)
|
||||
content_manager.register_script_message_handler("backend")
|
||||
|
||||
def _process_js_message(self, user_content_manager, js_result):
|
||||
js_value = js_result.get_js_value()
|
||||
message = js_value.to_string()
|
||||
|
||||
try:
|
||||
event = Event( **json.loads(message) )
|
||||
event_system.emit("handle_bridge_event", (event,))
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
|
||||
def ui_message(self, mtype, message):
|
||||
command = f"displayMessage('{message}', '{mtype}', '3')"
|
||||
self.run_javascript(command, None, None)
|
||||
|
||||
|
||||
class WebkitUISettings(WebKit2.Settings):
|
||||
def __init__(self):
|
||||
super(WebkitUISettings, self).__init__()
|
||||
|
||||
self._set_default_settings()
|
||||
|
||||
|
||||
# Note: Highly insecure setup but most "app" like setup I could think of.
|
||||
# Audit heavily any scripts/links ran/clicked under this setup!
|
||||
def _set_default_settings(self):
|
||||
# self.set_enable_xss_auditor(True)
|
||||
# self.set_enable_hyperlink_auditing(True)
|
||||
self.set_enable_xss_auditor(False)
|
||||
self.set_enable_hyperlink_auditing(False)
|
||||
self.set_enable_dns_prefetching(False)
|
||||
self.set_allow_file_access_from_file_urls(True)
|
||||
self.set_allow_universal_access_from_file_urls(True)
|
||||
# self.set_enable_java(True)
|
||||
|
||||
self.set_enable_page_cache(False)
|
||||
self.set_enable_offline_web_application_cache(False)
|
||||
self.set_enable_html5_local_storage(False)
|
||||
self.set_enable_html5_database(False)
|
||||
|
||||
self.set_print_backgrounds(False)
|
||||
self.set_enable_tabs_to_links(False)
|
||||
self.set_enable_fullscreen(True)
|
||||
self.set_enable_developer_extras(True)
|
||||
self.set_enable_webrtc(True)
|
||||
self.set_enable_webaudio(True)
|
||||
self.set_enable_accelerated_2d_canvas(True)
|
||||
|
||||
self.set_user_agent(f"Mozilla/5.0 {app_name}")
|
64
src/core/widgets/webkit_ui.py
Normal file
64
src/core/widgets/webkit_ui.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gdk', '3.0')
|
||||
gi.require_version('WebKit2', '4.0')
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import WebKit2
|
||||
|
||||
# Application imports
|
||||
from libs.settings_manager.other.webkit_ui_settings import WebkitUISettings
|
||||
|
||||
|
||||
class WebkitUI(WebKit2.WebView):
|
||||
def __init__(self):
|
||||
super(WebkitUI, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._subscribe_to_events()
|
||||
self._load_view()
|
||||
self._setup_content_manager()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_vexpand(True)
|
||||
self.set_hexpand(True)
|
||||
self.set_background_color( Gdk.RGBA(0, 0, 0, 0.0) )
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe(f"ui_message", self.ui_message)
|
||||
|
||||
def _load_settings(self):
|
||||
self.set_settings( WebkitUISettings() )
|
||||
|
||||
def _load_view(self):
|
||||
path = settings_manager.get_context_path()
|
||||
data = None
|
||||
|
||||
with open(f"{path}/index.html", "r") as f:
|
||||
data = f.read()
|
||||
|
||||
self.load_html(content = data, base_uri = f"file://{path}/")
|
||||
|
||||
def _setup_content_manager(self):
|
||||
content_manager = self.get_user_content_manager()
|
||||
content_manager.connect("script-message-received", self._process_js_message)
|
||||
content_manager.register_script_message_handler("backend")
|
||||
|
||||
def _process_js_message(self, user_content_manager, js_result):
|
||||
js_value = js_result.get_js_value()
|
||||
message = js_value.to_string()
|
||||
|
||||
try:
|
||||
event = Event( **json.loads(message) )
|
||||
event_system.emit("handle_bridge_event", (event,))
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
|
||||
def ui_message(self, message, mtype):
|
||||
command = f"displayMessage('{message}', '{mtype}', '3')"
|
||||
self.run_javascript(command, None, None)
|
||||
|
135
src/core/window.py
Normal file
135
src/core/window.py
Normal file
@@ -0,0 +1,135 @@
|
||||
# Python imports
|
||||
import signal
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
import cairo
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from core.controllers.base_controller import BaseController
|
||||
|
||||
|
||||
|
||||
class ControllerStartExceptiom(Exception):
|
||||
...
|
||||
|
||||
|
||||
|
||||
class Window(Gtk.ApplicationWindow):
|
||||
""" docstring for Window. """
|
||||
|
||||
def __init__(self, args, unknownargs):
|
||||
super(Window, self).__init__()
|
||||
settings_manager.set_main_window(self)
|
||||
|
||||
self._controller = None
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets(args, unknownargs)
|
||||
|
||||
self._set_window_data()
|
||||
self._set_size_constraints()
|
||||
|
||||
self.show()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_title(f"{app_name}")
|
||||
self.set_icon_from_file( settings_manager.get_window_icon() )
|
||||
self.set_gravity(5) # 5 = CENTER
|
||||
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
|
||||
|
||||
ctx = self.get_style_context()
|
||||
ctx.add_class("main-window")
|
||||
ctx.add_class(f"mw_transparency_{settings.theming.transparency}")
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("focus-in-event", self._on_focus_in_event)
|
||||
self.connect("focus-out-event", self._on_focus_out_event)
|
||||
|
||||
self.connect("delete-event", self._tear_down)
|
||||
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self._tear_down)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("tear_down", self._tear_down)
|
||||
event_system.subscribe("load_interactive_debug", self._load_interactive_debug)
|
||||
|
||||
def _load_widgets(self, args, unknownargs):
|
||||
if settings_manager.is_debug():
|
||||
self.set_interactive_debugging(True)
|
||||
|
||||
self._controller = BaseController(args, unknownargs)
|
||||
if not self._controller:
|
||||
raise ControllerStartException("BaseController exited and doesn't exist...")
|
||||
|
||||
self.add( self._controller.get_base_container() )
|
||||
|
||||
def _set_size_constraints(self):
|
||||
_window_x = settings.config.main_window_x
|
||||
_window_y = settings.config.main_window_y
|
||||
_min_width = settings.config.main_window_min_width
|
||||
_min_height = settings.config.main_window_min_height
|
||||
_width = settings.config.main_window_width
|
||||
_height = settings.config.main_window_height
|
||||
|
||||
self.move(_window_x, _window_y - 28)
|
||||
self.set_size_request(_min_width, _min_height)
|
||||
self.set_default_size(_width, _height)
|
||||
|
||||
def _set_window_data(self) -> None:
|
||||
screen = self.get_screen()
|
||||
visual = screen.get_rgba_visual()
|
||||
|
||||
if visual and screen.is_composited() and settings.config.make_transparent == 0:
|
||||
self.set_visual(visual)
|
||||
self.set_app_paintable(True)
|
||||
self.connect("draw", self._area_draw)
|
||||
|
||||
# bind css file
|
||||
cssProvider = Gtk.CssProvider()
|
||||
cssProvider.load_from_path( settings_manager.get_css_file() )
|
||||
screen = Gdk.Screen.get_default()
|
||||
styleContext = Gtk.StyleContext()
|
||||
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
|
||||
|
||||
def _area_draw(self, widget: Gtk.ApplicationWindow, cr: cairo.Context) -> None:
|
||||
cr.set_source_rgba( *settings_manager.get_paint_bg_color() )
|
||||
cr.set_operator(cairo.OPERATOR_SOURCE)
|
||||
cr.paint()
|
||||
cr.set_operator(cairo.OPERATOR_OVER)
|
||||
|
||||
|
||||
def _on_focus_in_event(self, widget, event):
|
||||
event_system.emit("pause_dnd_signals")
|
||||
|
||||
def _on_focus_out_event(self, widget, event):
|
||||
event_system.emit("listen_dnd_signals")
|
||||
|
||||
def _load_interactive_debug(self):
|
||||
self.set_interactive_debugging(True)
|
||||
|
||||
|
||||
def _tear_down(self, widget = None, eve = None):
|
||||
event_system.emit("shutting_down")
|
||||
|
||||
size = self.get_size()
|
||||
pos = self.get_position()
|
||||
|
||||
settings_manager.set_main_window_width(size.width)
|
||||
settings_manager.set_main_window_height(size.height)
|
||||
settings_manager.set_main_window_x(pos.root_x)
|
||||
settings_manager.set_main_window_y(pos.root_y)
|
||||
settings_manager.save_settings()
|
||||
|
||||
settings_manager.clear_pid()
|
||||
Gtk.main_quit()
|
||||
|
||||
def main(self):
|
||||
Gtk.main()
|
Reference in New Issue
Block a user