From 19c3e90cca74a63852df498b8860351f3aaffa76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Sverre=20Lien=20Sell=C3=A6g?= Date: Tue, 8 Sep 2020 01:13:31 +0200 Subject: [PATCH] hook into juci after window has been loaded --- src/plugins.cc | 20 ++++++++++++++++++++ src/plugins.h | 3 +++ src/window.cpp | 1 + 3 files changed, 24 insertions(+) diff --git a/src/plugins.cc b/src/plugins.cc index be649b9..79df00f 100644 --- a/src/plugins.cc +++ b/src/plugins.cc @@ -23,6 +23,25 @@ Plugins::~Plugins() { py::finalize_interpreter(); } + +void Plugins::init_hook() { + for(auto &module_name : loaded_modules) { + auto module = py::module(py::handle(PyImport_GetModule(py::str(module_name.c_str()).ptr())), false); + if(py::hasattr(module, "init_hook")) { + py::object obj = module.attr("init_hook"); + if(py::isinstance(obj)) { + py::function func(obj); + try { + func(); + } + catch(const py::error_already_set &err) { + std::cerr << err.what() << std::endl; + } + } + } + } +} + void Plugins::load() { const auto &plugin_path = Config::get().plugins.path; @@ -49,6 +68,7 @@ void Plugins::load() { if((is_directory && !is_pycache) || has_py_extension) { try { auto module = py::module::import(module_name.c_str()); + loaded_modules.push_back(module_name); } catch(py::error_already_set &error) { std::cerr << "Error loading plugin `" << module_name << "`:\n" diff --git a/src/plugins.h b/src/plugins.h index ff2655b..0a18617 100644 --- a/src/plugins.h +++ b/src/plugins.h @@ -10,6 +10,9 @@ public: ~Plugins(); void load(); + void init_hook(); + private: py::detail::embedded_module jucipp_module; + std::vector loaded_modules; }; diff --git a/src/window.cpp b/src/window.cpp index 40bcb32..ffa492a 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -161,6 +161,7 @@ void Window::init() { about.set_comments("This is an open source IDE with high-end features to make your programming experience juicy"); about.set_license_type(Gtk::License::LICENSE_MIT_X11); about.set_transient_for(*this); + plugins.init_hook(); } void Window::configure() {