Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit 3c4f4a3

Browse files
author
Raven
committed
Added Plugin Support
1 parent e885f0b commit 3c4f4a3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

filediff.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import difflib
55
import chardet
66
import html
7+
import importlib.util
78

89
from PyQt5.QtCore import Qt, QRect, QSize, QThread, pyqtSignal
910
from PyQt5.QtGui import QFont, QColor, QTextCharFormat, QPainter
@@ -22,6 +23,30 @@
2223

2324

2425

26+
""" Utility function to load plugins """
27+
def load_plugins(app_context):
28+
user_home = os.path.expanduser("~")
29+
plugins_dir = os.path.join(user_home, "fdplugins")
30+
os.makedirs(plugins_dir, exist_ok=True)
31+
loaded_plugins = []
32+
for filename in os.listdir(plugins_dir):
33+
if filename.endswith(".py") and not filename.startswith("_"):
34+
plugin_path = os.path.join(plugins_dir, filename)
35+
mod_name = os.path.splitext(filename)[0]
36+
spec = importlib.util.spec_from_file_location(mod_name, plugin_path)
37+
module = importlib.util.module_from_spec(spec)
38+
try:
39+
spec.loader.exec_module(module)
40+
if hasattr(module, "register_plugin"):
41+
module.register_plugin(app_context)
42+
loaded_plugins.append(mod_name)
43+
print(f"Plugin '{mod_name}' loaded successfully from {plugins_dir}")
44+
except Exception as e:
45+
print(f"Failed to load plugin '{filename}' from {plugins_dir}: {e}")
46+
return loaded_plugins
47+
48+
49+
2550
""" Utility function to load the CSS stylesheet """
2651
def loadStyle():
2752
user_css_path = os.path.join(os.path.expanduser("~"), "fdstyle.css")
@@ -196,6 +221,8 @@ def __init__(self):
196221
self.binary_worker_left = None
197222
self.binary_worker_right = None
198223
self.init_ui()
224+
app_context = {"main_window": self}
225+
self.plugins = load_plugins(app_context)
199226

200227
def init_ui(self):
201228
main_widget = QWidget(self)

0 commit comments

Comments
 (0)