develop #2
							
								
								
									
										2
									
								
								plugins/README.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								plugins/README.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
### Note
 | 
			
		||||
Copy the example and rename it to your desired name. The Main class and passed in arguments are required. You don't necessarily need to use the passed in socket_id or event_system.
 | 
			
		||||
							
								
								
									
										37
									
								
								plugins/example/__main__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								plugins/example/__main__.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
# Python imports
 | 
			
		||||
import sys, traceback, threading, inspect, os, time
 | 
			
		||||
 | 
			
		||||
# Gtk imports
 | 
			
		||||
import gi
 | 
			
		||||
gi.require_version('Gtk', '3.0')
 | 
			
		||||
from gi.repository import Gtk
 | 
			
		||||
 | 
			
		||||
# Application imports
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def threaded(fn):
 | 
			
		||||
    def wrapper(*args, **kwargs):
 | 
			
		||||
        threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
 | 
			
		||||
    return wrapper
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Main:
 | 
			
		||||
    def __init__(self, socket_id, event_system):
 | 
			
		||||
        self._socket_id    = socket_id
 | 
			
		||||
        self._event_system = event_system
 | 
			
		||||
        self._gtk_plug     = Gtk.Plug.new(self._socket_id)
 | 
			
		||||
        self.start_loop()
 | 
			
		||||
 | 
			
		||||
    @threaded
 | 
			
		||||
    def start_loop(self):
 | 
			
		||||
        i      = 0
 | 
			
		||||
        cycles = 5
 | 
			
		||||
        alive  = True
 | 
			
		||||
        while alive:
 | 
			
		||||
            if i == cycles:
 | 
			
		||||
                alive = False
 | 
			
		||||
 | 
			
		||||
            self._event_system.push_gui_event(["some_type", "display_message", ("warning", str(i), None)])
 | 
			
		||||
            i += 1
 | 
			
		||||
 | 
			
		||||
            time.sleep(1)
 | 
			
		||||
@@ -4,7 +4,7 @@ import builtins
 | 
			
		||||
# Lib imports
 | 
			
		||||
 | 
			
		||||
# Application imports
 | 
			
		||||
from signal_classes import IPCServerMixin
 | 
			
		||||
from controller import IPCServerMixin
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ def threaded(fn):
 | 
			
		||||
 | 
			
		||||
class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, Controller_Data):
 | 
			
		||||
    def __init__(self, args, unknownargs, _settings):
 | 
			
		||||
        # sys.excepthook = self.custom_except_hook
 | 
			
		||||
        sys.excepthook = self.custom_except_hook
 | 
			
		||||
        self.setup_controller_data(_settings)
 | 
			
		||||
        self.window.show()
 | 
			
		||||
        self.generate_windows(self.state)
 | 
			
		||||
@@ -58,7 +58,7 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, Controller_Data
 | 
			
		||||
                try:
 | 
			
		||||
                    type, target, data = event
 | 
			
		||||
                    method = getattr(self.__class__, target)
 | 
			
		||||
                    GLib.idle_add(method, *(self, data,))
 | 
			
		||||
                    GLib.idle_add(method, *(self, *data,))
 | 
			
		||||
                except Exception as e:
 | 
			
		||||
                    print(repr(e))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -17,14 +17,14 @@ class Plugins:
 | 
			
		||||
    def __init__(self, settings):
 | 
			
		||||
        self._settings            = settings
 | 
			
		||||
        self._plugins_path        = self._settings.get_plugins_path()
 | 
			
		||||
        self._socket              = Gtk.Socket().new()
 | 
			
		||||
        self.gtk_socket           = Gtk.Socket().new()
 | 
			
		||||
        self._plugins_dir_watcher = None
 | 
			
		||||
        self._socket_id           = None
 | 
			
		||||
        self.gtk_socket_id        = None
 | 
			
		||||
        self._plugin_collection   = []
 | 
			
		||||
 | 
			
		||||
        self._settings.get_main_window().add(self._socket)
 | 
			
		||||
        self._socket.show()
 | 
			
		||||
        self._socket_id = self._socket.get_id()
 | 
			
		||||
        self._settings.get_main_window().add(self.gtk_socket)
 | 
			
		||||
        self.gtk_socket.show()
 | 
			
		||||
        self.gtk_socket_id = self.gtk_socket.get_id()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def launch_plugins(self):
 | 
			
		||||
@@ -49,20 +49,15 @@ class Plugins:
 | 
			
		||||
            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)
 | 
			
		||||
                spec.loader.exec_module(module)
 | 
			
		||||
                module.Main(self.gtk_socket_id, event_system)
 | 
			
		||||
 | 
			
		||||
    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)
 | 
			
		||||
        # 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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user