Refactoring and plugin work
This commit is contained in:
parent
ad70e8c819
commit
3bedd83793
@ -13,7 +13,10 @@ class Builtins(IPCServerMixin):
|
||||
"""Docstring for __builtins__ extender"""
|
||||
|
||||
def __init__(self):
|
||||
# NOTE: The format used is list of [type, target, data]
|
||||
# NOTE: The format used is list of [type, target, data] Where:
|
||||
# type is useful context for control flow,
|
||||
# target is the method to call,
|
||||
# data is the method parameters to give
|
||||
# Where data may be any kind of data
|
||||
self._gui_events = []
|
||||
self._fm_events = []
|
||||
@ -66,7 +69,7 @@ class Builtins(IPCServerMixin):
|
||||
|
||||
# NOTE: Just reminding myself we can add to builtins two different ways...
|
||||
# __builtins__.update({"event_system": Builtins()})
|
||||
builtins.app_name = "SolarFM"
|
||||
builtins.app_name = "SolarFM"
|
||||
builtins.event_system = Builtins()
|
||||
builtins.event_sleep_time = 0.2
|
||||
builtins.debug = False
|
||||
|
@ -5,7 +5,7 @@ import os, inspect, time
|
||||
|
||||
# Application imports
|
||||
from utils import Settings
|
||||
from signal_classes import Controller
|
||||
from controller import Controller
|
||||
from __builtins__ import Builtins
|
||||
|
||||
|
||||
|
@ -7,8 +7,8 @@ gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, GLib
|
||||
|
||||
# Application imports
|
||||
from .mixins.ui import *
|
||||
from .mixins import ShowHideMixin, KeyboardSignalsMixin
|
||||
from .mixins import UIMixin
|
||||
from .signals import IPCSignalsMixin, KeyboardSignalsMixin
|
||||
from . import Controller_Data
|
||||
|
||||
|
||||
@ -20,8 +20,7 @@ def threaded(fn):
|
||||
|
||||
|
||||
|
||||
class Controller(WidgetFileActionMixin, PaneMixin, WindowMixin, ShowHideMixin, \
|
||||
KeyboardSignalsMixin, Controller_Data):
|
||||
class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, Controller_Data):
|
||||
def __init__(self, args, unknownargs, _settings):
|
||||
# sys.excepthook = self.custom_except_hook
|
||||
self.setup_controller_data(_settings)
|
||||
@ -58,8 +57,8 @@ class Controller(WidgetFileActionMixin, PaneMixin, WindowMixin, ShowHideMixin, \
|
||||
if event:
|
||||
try:
|
||||
type, target, data = event
|
||||
method = getattr(self.__class__, type)
|
||||
GLib.idle_add(method, (self, data,))
|
||||
method = getattr(self.__class__, target)
|
||||
GLib.idle_add(method, *(self, data,))
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
|
@ -5,9 +5,9 @@ import signal
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from shellfm import WindowController
|
||||
from trasher.xdgtrash import XDGTrash
|
||||
from . import Plugins
|
||||
from shellfm import WindowController
|
||||
from plugins import Plugins
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ class IPCServerMixin:
|
||||
if "FILE|" in msg:
|
||||
file = msg.split("FILE|")[1].strip()
|
||||
if file:
|
||||
event_system.push_gui_event(["create_tab_from_ipc", None, file])
|
||||
event_system.push_gui_event([None, "handle_file_from_ipc", file])
|
||||
|
||||
conn.close()
|
||||
break
|
@ -3,6 +3,5 @@
|
||||
"""
|
||||
from .mixins import *
|
||||
from .IPCServerMixin import IPCServerMixin
|
||||
from .Plugins import Plugins
|
||||
from .Controller_Data import Controller_Data
|
||||
from .Controller import Controller
|
@ -0,0 +1,11 @@
|
||||
# Python imports
|
||||
|
||||
# Gtk imports
|
||||
|
||||
# Application imports
|
||||
from . import ShowHideMixin
|
||||
from .ui import *
|
||||
|
||||
|
||||
class UIMixin(WidgetFileActionMixin, PaneMixin, WindowMixin, ShowHideMixin):
|
||||
pass
|
@ -0,0 +1,2 @@
|
||||
from .ShowHideMixin import ShowHideMixin
|
||||
from .UIMixin import UIMixin
|
@ -16,24 +16,6 @@ from . import WidgetMixin
|
||||
class TabMixin(WidgetMixin):
|
||||
"""docstring for TabMixin"""
|
||||
|
||||
def create_tab_from_ipc(data):
|
||||
self, path = data
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
if notebook.is_visible():
|
||||
self.create_tab(wid, path)
|
||||
return
|
||||
|
||||
if not self.is_pane4_hidden:
|
||||
self.create_tab(4, path)
|
||||
elif not self.is_pane3_hidden:
|
||||
self.create_tab(3, path)
|
||||
elif not self.is_pane2_hidden:
|
||||
self.create_tab(2, path)
|
||||
elif not self.is_pane1_hidden:
|
||||
self.create_tab(1, path)
|
||||
|
||||
|
||||
def create_tab(self, wid, path=None):
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
path_entry = self.builder.get_object(f"path_entry")
|
@ -0,0 +1,27 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
class IPCSignalsMixin:
|
||||
def print_to_console(self, message=None):
|
||||
print(self)
|
||||
print(message)
|
||||
|
||||
def handle_file_from_ipc(self, path):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
if notebook.is_visible():
|
||||
self.create_tab(wid, path)
|
||||
return
|
||||
|
||||
if not self.is_pane4_hidden:
|
||||
self.create_tab(4, path)
|
||||
elif not self.is_pane3_hidden:
|
||||
self.create_tab(3, path)
|
||||
elif not self.is_pane2_hidden:
|
||||
self.create_tab(2, path)
|
||||
elif not self.is_pane1_hidden:
|
||||
self.create_tab(1, path)
|
@ -1,2 +1,2 @@
|
||||
from .KeyboardSignalsMixin import KeyboardSignalsMixin
|
||||
from .ShowHideMixin import ShowHideMixin
|
||||
from .IPCSignalsMixin import IPCSignalsMixin
|
@ -0,0 +1,68 @@
|
||||
# Python imports
|
||||
import os, importlib
|
||||
from os.path import join, isdir
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, Gio
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
|
||||
class Plugins:
|
||||
"""docstring for Plugins"""
|
||||
def __init__(self, settings):
|
||||
self._settings = settings
|
||||
self._plugins_path = self._settings.get_plugins_path()
|
||||
self._socket = Gtk.Socket().new()
|
||||
self._plugins_dir_watcher = None
|
||||
self._socket_id = None
|
||||
self._plugin_collection = []
|
||||
|
||||
self._settings.get_main_window().add(self._socket)
|
||||
self._socket.show()
|
||||
self._socket_id = self._socket.get_id()
|
||||
|
||||
|
||||
def launch_plugins(self):
|
||||
self._set_plugins_watcher()
|
||||
self.load_plugins()
|
||||
|
||||
def _set_plugins_watcher(self):
|
||||
self._plugins_dir_watcher = Gio.File.new_for_path(self._plugins_path) \
|
||||
.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES, Gio.Cancellable())
|
||||
self._plugins_dir_watcher.connect("changed", self._on_plugins_changed, ())
|
||||
|
||||
def _on_plugins_changed(self, file_monitor, file, other_file=None, eve_type=None, data=None):
|
||||
if eve_type in [Gio.FileMonitorEvent.CREATED, Gio.FileMonitorEvent.DELETED,
|
||||
Gio.FileMonitorEvent.RENAMED, Gio.FileMonitorEvent.MOVED_IN,
|
||||
Gio.FileMonitorEvent.MOVED_OUT]:
|
||||
self.reload_plugins(file)
|
||||
|
||||
def load_plugins(self, file=None):
|
||||
print(f"Loading plugins...")
|
||||
for file in os.listdir(self._plugins_path):
|
||||
path = join(self._plugins_path, file)
|
||||
if isdir(path):
|
||||
spec = importlib.util.spec_from_file_location(file, join(path, "__main__.py"))
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
self._plugin_collection.append([file, module])
|
||||
# module.set_socket_id(self._socket_id)
|
||||
# print(f"\n\n\n {event_system} \n\n\n")
|
||||
# module.set_event_system(event_system)
|
||||
# module.main()
|
||||
# module.start_loop(event_system)
|
||||
|
||||
print(self._plugin_collection)
|
||||
|
||||
def reload_plugins(self, file=None):
|
||||
print(f"Reloading plugins...")
|
||||
if self._plugin_collection:
|
||||
to_unload = []
|
||||
for dir in self._plugin_collection:
|
||||
if not os.path.isdir(os.path.join(self._plugins_path, dir)):
|
||||
to_unload.append(dir)
|
@ -0,0 +1,4 @@
|
||||
"""
|
||||
Gtk Bound Plugins Module
|
||||
"""
|
||||
from .Plugins import Plugins
|
@ -1,41 +0,0 @@
|
||||
# Python imports
|
||||
import importlib
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, Gio
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
|
||||
class Plugins:
|
||||
"""docstring for Plugins"""
|
||||
def __init__(self, settings):
|
||||
self._settings = settings
|
||||
self._plugins_path = self._settings.get_plugins_path()
|
||||
self._plugins_dir_watcher = None
|
||||
self._socket = Gtk.Socket().new()
|
||||
|
||||
def launch_plugins(self):
|
||||
self._set_plugins_watcher()
|
||||
self.load_plugins()
|
||||
|
||||
def _set_plugins_watcher(self):
|
||||
self._plugins_dir_watcher = Gio.File.new_for_path(self._plugins_path) \
|
||||
.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES, Gio.Cancellable())
|
||||
self._plugins_dir_watcher.connect("changed", self._on_plugins_changed, ())
|
||||
|
||||
def _on_plugins_changed(self, file_monitor, file, other_file=None, eve_type=None, data=None):
|
||||
if eve_type in [Gio.FileMonitorEvent.CREATED, Gio.FileMonitorEvent.DELETED,
|
||||
Gio.FileMonitorEvent.RENAMED, Gio.FileMonitorEvent.MOVED_IN,
|
||||
Gio.FileMonitorEvent.MOVED_OUT]:
|
||||
self.load_plugins(file)
|
||||
|
||||
def load_plugins(self, file=None):
|
||||
print(f"(Re)loading plugins...")
|
||||
print(locals())
|
||||
|
||||
# importlib.reload(stl_utils)
|
@ -25,10 +25,10 @@ class Settings:
|
||||
self.PLUGINS_PATH = f"{self.CONFIG_PATH}/plugins"
|
||||
self.USR_SOLARFM = f"/usr/share/{app_name.lower()}"
|
||||
|
||||
self.cssFile = f"{self.CONFIG_PATH}/stylesheet.css"
|
||||
self.windows_glade = f"{self.CONFIG_PATH}/Main_Window.glade"
|
||||
self.CSS_FILE = f"{self.CONFIG_PATH}/stylesheet.css"
|
||||
self.WINDOWS_GLADE = f"{self.CONFIG_PATH}/Main_Window.glade"
|
||||
self.DEFAULT_ICONS = f"{self.CONFIG_PATH}/icons"
|
||||
self.window_icon = f"{self.DEFAULT_ICONS}/{app_name.lower()}.png"
|
||||
self.WINDOW_ICON = f"{self.DEFAULT_ICONS}/{app_name.lower()}.png"
|
||||
self.main_window = None
|
||||
|
||||
if not os.path.exists(self.CONFIG_PATH):
|
||||
@ -36,17 +36,17 @@ class Settings:
|
||||
if not os.path.exists(self.PLUGINS_PATH):
|
||||
os.mkdir(self.PLUGINS_PATH)
|
||||
|
||||
if not os.path.exists(self.windows_glade):
|
||||
self.windows_glade = f"{self.USR_SOLARFM}/Main_Window.glade"
|
||||
if not os.path.exists(self.cssFile):
|
||||
self.cssFile = f"{self.USR_SOLARFM}/stylesheet.css"
|
||||
if not os.path.exists(self.window_icon):
|
||||
self.window_icon = f"{self.USR_SOLARFM}/icons/{app_name.lower()}.png"
|
||||
if not os.path.exists(self.WINDOWS_GLADE):
|
||||
self.WINDOWS_GLADE = f"{self.USR_SOLARFM}/Main_Window.glade"
|
||||
if not os.path.exists(self.CSS_FILE):
|
||||
self.CSS_FILE = f"{self.USR_SOLARFM}/stylesheet.css"
|
||||
if not os.path.exists(self.WINDOW_ICON):
|
||||
self.WINDOW_ICON = f"{self.USR_SOLARFM}/icons/{app_name.lower()}.png"
|
||||
if not os.path.exists(self.DEFAULT_ICONS):
|
||||
self.DEFAULT_ICONS = f"{self.USR_SOLARFM}/icons"
|
||||
|
||||
self.logger = Logger(self.CONFIG_PATH).get_logger()
|
||||
self.builder.add_from_file(self.windows_glade)
|
||||
self.builder.add_from_file(self.WINDOWS_GLADE)
|
||||
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ class Settings:
|
||||
self._set_window_data()
|
||||
|
||||
def _set_window_data(self):
|
||||
self.main_window.set_icon_from_file(self.window_icon)
|
||||
self.main_window.set_icon_from_file(self.WINDOW_ICON)
|
||||
screen = self.main_window.get_screen()
|
||||
visual = screen.get_rgba_visual()
|
||||
|
||||
@ -67,7 +67,7 @@ class Settings:
|
||||
|
||||
# bind css file
|
||||
cssProvider = gtk.CssProvider()
|
||||
cssProvider.load_from_path(self.cssFile)
|
||||
cssProvider.load_from_path(self.CSS_FILE)
|
||||
screen = gdk.Screen.get_default()
|
||||
styleContext = gtk.StyleContext()
|
||||
styleContext.add_provider_for_screen(screen, cssProvider, gtk.STYLE_PROVIDER_PRIORITY_USER)
|
||||
|
Loading…
Reference in New Issue
Block a user