generated from itdominator/Python-With-Gtk-Template
Fixing loading of passed in files
This commit is contained in:
parent
d98982bc86
commit
2a2fe27667
|
@ -1,5 +1,4 @@
|
||||||
# Python imports
|
# Python imports
|
||||||
import os
|
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
import gi
|
import gi
|
||||||
|
@ -21,15 +20,7 @@ from .bridge_controller import BridgeController
|
||||||
|
|
||||||
class BaseController(KeyboardSignalsMixin, BaseControllerData):
|
class BaseController(KeyboardSignalsMixin, BaseControllerData):
|
||||||
def __init__(self, args, unknownargs):
|
def __init__(self, args, unknownargs):
|
||||||
messages = []
|
self.collect_files_dirs(args, unknownargs)
|
||||||
for arg in unknownargs + [args.new_tab,]:
|
|
||||||
# NOTE: If passing line number with file split against :
|
|
||||||
if os.path.isfile(arg.replace("file://", "").split(":")[0]):
|
|
||||||
messages.append(f"FILE|{arg.replace('file://', '')}")
|
|
||||||
|
|
||||||
if len(messages) > 0:
|
|
||||||
settings_manager.set_is_starting_with_file(True)
|
|
||||||
|
|
||||||
|
|
||||||
self.setup_controller_data()
|
self.setup_controller_data()
|
||||||
|
|
||||||
|
@ -38,13 +29,9 @@ class BaseController(KeyboardSignalsMixin, BaseControllerData):
|
||||||
self._subscribe_to_events()
|
self._subscribe_to_events()
|
||||||
self._load_controllers()
|
self._load_controllers()
|
||||||
|
|
||||||
|
|
||||||
if args.no_plugins == "false":
|
if args.no_plugins == "false":
|
||||||
self.plugins.launch_plugins()
|
self.plugins.launch_plugins()
|
||||||
|
|
||||||
for message in messages:
|
|
||||||
event_system.emit("post_file_to_ipc", message)
|
|
||||||
|
|
||||||
|
|
||||||
def _setup_styling(self):
|
def _setup_styling(self):
|
||||||
...
|
...
|
||||||
|
|
|
@ -26,6 +26,20 @@ class BaseControllerData:
|
||||||
self.load_glade_file()
|
self.load_glade_file()
|
||||||
self.plugins = PluginsController()
|
self.plugins = PluginsController()
|
||||||
|
|
||||||
|
def collect_files_dirs(self, args, unknownargs):
|
||||||
|
files = []
|
||||||
|
for arg in unknownargs + [args.new_tab,]:
|
||||||
|
if os.path.isdir( arg.replace("file://", "") ):
|
||||||
|
files.append( f"DIR|{arg.replace('file://', '')}" )
|
||||||
|
|
||||||
|
# NOTE: If passing line number with file split against :
|
||||||
|
if os.path.isfile( arg.replace("file://", "").split(":")[0] ):
|
||||||
|
files.append( f"FILE|{arg.replace('file://', '')}" )
|
||||||
|
|
||||||
|
if len(files) > 0:
|
||||||
|
settings_manager.set_is_starting_with_file(True)
|
||||||
|
settings_manager.set_starting_files(files)
|
||||||
|
|
||||||
def set_active_src_view(self, source_view):
|
def set_active_src_view(self, source_view):
|
||||||
if self.active_src_view:
|
if self.active_src_view:
|
||||||
old_notebook = self.active_src_view.get_parent().get_parent()
|
old_notebook = self.active_src_view.get_parent().get_parent()
|
||||||
|
|
|
@ -10,7 +10,6 @@ import base64
|
||||||
class BridgeController:
|
class BridgeController:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.opened_files = {}
|
|
||||||
self.originator = -1
|
self.originator = -1
|
||||||
|
|
||||||
self._setup_signals()
|
self._setup_signals()
|
||||||
|
@ -44,6 +43,9 @@ class BridgeController:
|
||||||
self.originator = event.originator
|
self.originator = event.originator
|
||||||
|
|
||||||
match event.topic:
|
match event.topic:
|
||||||
|
case "load_starting_files":
|
||||||
|
for file in settings_manager.get_starting_files():
|
||||||
|
event_system.emit("post_file_to_ipc", file)
|
||||||
case "save":
|
case "save":
|
||||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
||||||
case "close":
|
case "close":
|
||||||
|
|
|
@ -11,6 +11,7 @@ from gi.repository import GLib
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from libs.data_types import Event
|
from libs.data_types import Event
|
||||||
|
from libs.settings_manager.other.webkit_ui_settings import WebkitUISettings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,37 +125,6 @@ class AceEditor(WebKit2.WebView):
|
||||||
command = f"displayMessage('{message}', '{mtype}', '3')"
|
command = f"displayMessage('{message}', '{mtype}', '3')"
|
||||||
self.run_javascript(command, None, None)
|
self.run_javascript(command, None, None)
|
||||||
|
|
||||||
|
def run_javascript(self, script, cancellable, callback):
|
||||||
class WebkitUISettings(WebKit2.Settings):
|
logger.debug(script)
|
||||||
def __init__(self):
|
super().run_javascript(script, cancellable, callback)
|
||||||
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_allow_file_access_from_file_urls(True)
|
|
||||||
self.set_allow_universal_access_from_file_urls(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_enable_fullscreen(False)
|
|
||||||
self.set_print_backgrounds(False)
|
|
||||||
self.set_enable_tabs_to_links(False)
|
|
||||||
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}")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,7 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
self._debug = False
|
self._debug = False
|
||||||
self._dirty_start = False
|
self._dirty_start = False
|
||||||
self._passed_in_file = False
|
self._passed_in_file = False
|
||||||
|
self._starting_files = []
|
||||||
|
|
||||||
|
|
||||||
def register_signals_to_builder(self, classes=None):
|
def register_signals_to_builder(self, classes=None):
|
||||||
|
@ -110,7 +111,6 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
def set_main_window(self, window): self._main_window = window
|
def set_main_window(self, window): self._main_window = window
|
||||||
def set_builder(self, builder) -> any: self._builder = builder
|
def set_builder(self, builder) -> any: self._builder = builder
|
||||||
|
|
||||||
|
|
||||||
def get_monitor_data(self) -> list:
|
def get_monitor_data(self) -> list:
|
||||||
screen = self._main_window.get_screen()
|
screen = self._main_window.get_screen()
|
||||||
monitors = []
|
monitors = []
|
||||||
|
@ -134,6 +134,7 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
def get_home_config_path(self) -> str: return self._HOME_CONFIG_PATH
|
def get_home_config_path(self) -> str: return self._HOME_CONFIG_PATH
|
||||||
def get_window_icon(self) -> str: return self._WINDOW_ICON
|
def get_window_icon(self) -> str: return self._WINDOW_ICON
|
||||||
def get_home_path(self) -> str: return self._USER_HOME
|
def get_home_path(self) -> str: return self._USER_HOME
|
||||||
|
def get_starting_files(self) -> []: return self._starting_files
|
||||||
|
|
||||||
def is_trace_debug(self) -> str: return self._trace_debug
|
def is_trace_debug(self) -> str: return self._trace_debug
|
||||||
def is_debug(self) -> str: return self._debug
|
def is_debug(self) -> str: return self._debug
|
||||||
|
@ -150,6 +151,7 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
def set_main_window_height(self, height = 600): self.settings.config.main_window_height = height
|
def set_main_window_height(self, height = 600): self.settings.config.main_window_height = height
|
||||||
def set_main_window_min_width(self, width = 720): self.settings.config.main_window_min_width = width
|
def set_main_window_min_width(self, width = 720): self.settings.config.main_window_min_width = width
|
||||||
def set_main_window_min_height(self, height = 480): self.settings.config.main_window_min_height = height
|
def set_main_window_min_height(self, height = 480): self.settings.config.main_window_min_height = height
|
||||||
|
def set_starting_files(self, files: []) -> None: self._starting_files = files
|
||||||
|
|
||||||
def set_trace_debug(self, trace_debug):
|
def set_trace_debug(self, trace_debug):
|
||||||
self._trace_debug = trace_debug
|
self._trace_debug = trace_debug
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
"""
|
||||||
|
Settings Other module
|
||||||
|
"""
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('WebKit2', '4.0')
|
||||||
|
from gi.repository import WebKit2
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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_allow_file_access_from_file_urls(True)
|
||||||
|
self.set_allow_universal_access_from_file_urls(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_enable_fullscreen(False)
|
||||||
|
self.set_print_backgrounds(False)
|
||||||
|
self.set_enable_tabs_to_links(False)
|
||||||
|
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"{app_name}")
|
Loading…
Reference in New Issue