Browse Source

hook into juci after window has been loaded

python
Jørgen Lien Sellæg 5 years ago
parent
commit
19c3e90cca
  1. 20
      src/plugins.cc
  2. 3
      src/plugins.h
  3. 1
      src/window.cpp

20
src/plugins.cc

@ -23,6 +23,25 @@ Plugins::~Plugins() {
py::finalize_interpreter(); 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<py::function>(obj)) {
py::function func(obj);
try {
func();
}
catch(const py::error_already_set &err) {
std::cerr << err.what() << std::endl;
}
}
}
}
}
void Plugins::load() { void Plugins::load() {
const auto &plugin_path = Config::get().plugins.path; const auto &plugin_path = Config::get().plugins.path;
@ -49,6 +68,7 @@ void Plugins::load() {
if((is_directory && !is_pycache) || has_py_extension) { if((is_directory && !is_pycache) || has_py_extension) {
try { try {
auto module = py::module::import(module_name.c_str()); auto module = py::module::import(module_name.c_str());
loaded_modules.push_back(module_name);
} }
catch(py::error_already_set &error) { catch(py::error_already_set &error) {
std::cerr << "Error loading plugin `" << module_name << "`:\n" std::cerr << "Error loading plugin `" << module_name << "`:\n"

3
src/plugins.h

@ -10,6 +10,9 @@ public:
~Plugins(); ~Plugins();
void load(); void load();
void init_hook();
private: private:
py::detail::embedded_module jucipp_module; py::detail::embedded_module jucipp_module;
std::vector<std::string> loaded_modules;
}; };

1
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_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_license_type(Gtk::License::LICENSE_MIT_X11);
about.set_transient_for(*this); about.set_transient_for(*this);
plugins.init_hook();
} }
void Window::configure() { void Window::configure() {

Loading…
Cancel
Save