Browse Source

move binding code to respective files

python
Jørgen Lien Sellæg 7 years ago committed by Jørgen Sverre Lien Sellæg
parent
commit
f583644a89
  1. 2
      lib/tiny-process-library
  2. 16
      src/cmake.cpp
  3. 4
      src/cmake.hpp
  4. 21
      src/compile_commands.cpp
  5. 5
      src/compile_commands.hpp
  6. 105
      src/config.cpp
  7. 2
      src/config.hpp
  8. 27
      src/ctags.cpp
  9. 2
      src/ctags.hpp
  10. 77
      src/debug_lldb.cpp
  11. 2
      src/debug_lldb.hpp
  12. 17
      src/dialogs.cpp
  13. 2
      src/dialogs.hpp
  14. 8
      src/dispatcher.cpp
  15. 3
      src/dispatcher.hpp
  16. 24
      src/plugins.cc
  17. 28
      src/plugins.h
  18. 342
      src/python_module.h
  19. 31
      src/terminal.cpp
  20. 2
      src/terminal.hpp

2
lib/tiny-process-library

@ -1 +1 @@
Subproject commit c9c8bf810ddad8cd17882b9a9ee628a690e779f5 Subproject commit 6e52608b15d12a13e68269b111afda3013e7cf3a

16
src/cmake.cpp

@ -349,3 +349,19 @@ void CMake::parse_file(const std::string &src, std::map<std::string, std::list<s
} }
} }
} }
void CMake::init_module(pybind11::module &api) {
py::class_<CMake>(api, "CMake")
.def_readwrite("project_path", &CMake::project_path)
.def("update_default_build", &CMake::update_default_build,
py::arg("default_build_path"),
py::arg("force") = false)
.def("update_debug_build", &CMake::update_debug_build,
py::arg("debug_build_path"),
py::arg("force") = false)
.def("get_executable", &CMake::get_executable,
py::arg("build_path"),
py::arg("file_path"))
;
}

4
src/cmake.hpp

@ -3,16 +3,16 @@
#include <list> #include <list>
#include <map> #include <map>
#include <vector> #include <vector>
#include "python_bind.h"
class CMake { class CMake {
public: public:
CMake(const boost::filesystem::path &path); CMake(const boost::filesystem::path &path);
boost::filesystem::path project_path; boost::filesystem::path project_path;
bool update_default_build(const boost::filesystem::path &default_build_path, bool force = false); bool update_default_build(const boost::filesystem::path &default_build_path, bool force = false);
bool update_debug_build(const boost::filesystem::path &debug_build_path, bool force = false); bool update_debug_build(const boost::filesystem::path &debug_build_path, bool force = false);
boost::filesystem::path get_executable(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path); boost::filesystem::path get_executable(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path);
static void init_module(py::module &api);
private: private:
std::vector<boost::filesystem::path> paths; std::vector<boost::filesystem::path> paths;

21
src/compile_commands.cpp

@ -276,3 +276,24 @@ bool CompileCommands::is_source(const boost::filesystem::path &path) {
else else
return false; return false;
} }
void CompileCommands::init_module(py::module &api) {
py::class_<CompileCommands> compile_commands(api, "CompileCommands");
py::class_<CompileCommands::Command>(compile_commands, "CompileCommands")
.def_readwrite("directory", &CompileCommands::Command::directory)
.def_readwrite("parameters", &CompileCommands::Command::parameters)
.def_readwrite("file", &CompileCommands::Command::file)
;
compile_commands
.def_readwrite("commands", &CompileCommands::commands)
.def_static("get_arguments", &CompileCommands::get_arguments,
py::arg("build_path"),
py::arg("file_path"))
.def_static("is_header", &CompileCommands::is_header,
py::arg("path"))
.def_static("is_source", &CompileCommands::is_source,
py::arg("path"))
;
}

5
src/compile_commands.hpp

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "python_bind.h"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <string> #include <string>
#include <vector> #include <vector>
@ -21,16 +22,14 @@ public:
boost::filesystem::path directory; boost::filesystem::path directory;
std::vector<std::string> parameters; std::vector<std::string> parameters;
boost::filesystem::path file; boost::filesystem::path file;
std::vector<std::string> parameter_values(const std::string &parameter_name) const; std::vector<std::string> parameter_values(const std::string &parameter_name) const;
}; };
CompileCommands(const boost::filesystem::path &build_path); CompileCommands(const boost::filesystem::path &build_path);
std::vector<Command> commands; std::vector<Command> commands;
/// Return arguments for the given file using libclangmm /// Return arguments for the given file using libclangmm
static std::vector<std::string> get_arguments(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path); static std::vector<std::string> get_arguments(const boost::filesystem::path &build_path, const boost::filesystem::path &file_path);
static bool is_header(const boost::filesystem::path &path); static bool is_header(const boost::filesystem::path &path);
static bool is_source(const boost::filesystem::path &path); static bool is_source(const boost::filesystem::path &path);
static void init_module(py::module &api);
}; };

105
src/config.cpp

@ -222,3 +222,108 @@ void Config::read(const boost::property_tree::ptree &cfg) {
std::cout << "Plugins enabled" << std::endl; std::cout << "Plugins enabled" << std::endl;
} }
} }
void Config::init_module(py::module &api) {
py::class_<Config, std::unique_ptr<Config, py::nodelete>> config(api, "Config");
config
.def(py::init([]() { return &(Config::get()); }))
.def("load", &Config::load)
.def_readonly("version", &Config::version)
;
py::class_<Config::Menu>(config, "Menu")
.def_readwrite("keys", &Config::Menu::keys)
;
py::class_<Config::Theme>(config, "Theme")
.def_readwrite("name", &Config::Theme::name)
.def_readwrite("variant", &Config::Theme::variant)
.def_readwrite("font", &Config::Theme::font)
;
py::class_<Config::Terminal>(config, "Terminal")
.def_readwrite("history_size", &Config::Terminal::history_size)
.def_readwrite("font", &Config::Terminal::font)
;
py::class_<Config::Project> project(config, "Project");
py::class_<Config::Project::CMake>(project, "CMake")
.def_readwrite("command", &Config::Project::CMake::command)
.def_readwrite("compile_command", &Config::Project::CMake::compile_command)
;
py::class_<Config::Project::Meson>(project, "Meson")
.def_readwrite("command", &Config::Project::Meson::command)
.def_readwrite("compile_command", &Config::Project::Meson::compile_command)
;
project
.def_readwrite("default_build_path", &Config::Project::default_build_path)
.def_readwrite("debug_build_path", &Config::Project::debug_build_path)
.def_readwrite("cmake", &Config::Project::cmake)
.def_readwrite("meson", &Config::Project::meson)
.def_readwrite("save_on_compile_or_run", &Config::Project::save_on_compile_or_run)
.def_readwrite("clear_terminal_on_compile", &Config::Project::clear_terminal_on_compile)
.def_readwrite("ctags_command", &Config::Project::ctags_command)
.def_readwrite("python_command", &Config::Project::python_command)
;
py::class_<Config::Source> source(config, "Source");
py::class_<Config::Source::DocumentationSearch>(source, "DocumentationSearch")
.def_readwrite("separator", &Config::Source::DocumentationSearch::separator)
.def_readwrite("compile_command", &Config::Source::DocumentationSearch::queries)
;
source
.def_readwrite("style", &Config::Source::style)
.def_readwrite("font", &Config::Source::font)
.def_readwrite("spellcheck_language", &Config::Source::spellcheck_language)
.def_readwrite("cleanup_whitespace_characters", &Config::Source::cleanup_whitespace_characters)
.def_readwrite("show_whitespace_characters", &Config::Source::show_whitespace_characters)
.def_readwrite("format_style_on_save", &Config::Source::format_style_on_save)
.def_readwrite("format_style_on_save_if_style_file_found", &Config::Source::format_style_on_save_if_style_file_found)
.def_readwrite("smart_inserts", &Config::Source::smart_inserts)
.def_readwrite("show_map", &Config::Source::show_map)
.def_readwrite("map_font_size", &Config::Source::map_font_size)
.def_readwrite("show_git_diff", &Config::Source::show_git_diff)
.def_readwrite("show_background_pattern", &Config::Source::show_background_pattern)
.def_readwrite("show_right_margin", &Config::Source::show_right_margin)
.def_readwrite("right_margin_position", &Config::Source::right_margin_position)
.def_readwrite("auto_tab_char_and_size", &Config::Source::auto_tab_char_and_size)
.def_readwrite("default_tab_char", &Config::Source::default_tab_char)
.def_readwrite("default_tab_size", &Config::Source::default_tab_size)
.def_readwrite("tab_indents_line", &Config::Source::tab_indents_line)
.def_readwrite("wrap_lines", &Config::Source::wrap_lines)
.def_readwrite("highlight_current_line", &Config::Source::highlight_current_line)
.def_readwrite("show_line_numbers", &Config::Source::show_line_numbers)
.def_readwrite("enable_multiple_cursors", &Config::Source::enable_multiple_cursors)
.def_readwrite("auto_reload_changed_files", &Config::Source::auto_reload_changed_files)
.def_readwrite("clang_format_style", &Config::Source::clang_format_style)
.def_readwrite("clang_usages_threads", &Config::Source::clang_usages_threads)
.def_readwrite("documentation_searches", &Config::Source::documentation_searches)
;
py::class_<Config::Log>(config, "Log")
.def_readwrite("libclang", &Config::Log::libclang)
.def_readwrite("language_server", &Config::Log::language_server)
;
py::class_<Config::Plugins>(config, "Plugins")
.def_readwrite("enabled", &Config::Plugins::enabled)
.def_readwrite("path", &Config::Plugins::path)
;
config
.def_readwrite("menu", &Config::menu)
.def_readwrite("theme", &Config::theme)
.def_readwrite("terminal", &Config::terminal)
.def_readwrite("project", &Config::project)
.def_readwrite("source", &Config::source)
.def_readwrite("log", &Config::log)
.def_readwrite("plugins", &Config::plugins)
.def_readwrite("home_path", &Config::home_path)
.def_readwrite("home_juci_path", &Config::home_juci_path)
;
}

2
src/config.hpp

@ -6,6 +6,7 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "python_bind.h"
class Config { class Config {
public: public:
@ -141,6 +142,7 @@ public:
boost::filesystem::path home_path; boost::filesystem::path home_path;
boost::filesystem::path home_juci_path; boost::filesystem::path home_juci_path;
static void init_module(py::module &api);
private: private:
/// Used to dispatch Terminal outputs after juCi++ GUI setup and configuration /// Used to dispatch Terminal outputs after juCi++ GUI setup and configuration

27
src/ctags.cpp

@ -278,3 +278,30 @@ std::vector<Ctags::Location> Ctags::get_locations(const boost::filesystem::path
return best_locations; return best_locations;
} }
void Ctags::init_module(py::module &api) {
py::class_<Ctags> ctags(api, "Ctags");
py::class_<Ctags::Location>(api, "Ctags")
.def_readwrite("file_path", &Ctags::Location::file_path)
.def_readwrite("line", &Ctags::Location::line)
.def_readwrite("index", &Ctags::Location::index)
.def_readwrite("symbol", &Ctags::Location::symbol)
.def_readwrite("scope", &Ctags::Location::scope)
.def_readwrite("source", &Ctags::Location::source)
.def("__bool__", &Ctags::Location::operator bool)
;
ctags
.def_static("get_result", &Ctags::get_result,
py::arg("path"))
.def_static("get_location", &Ctags::get_location,
py::arg("line"),
py::arg("markup"))
.def_static("get_locations", &Ctags::get_locations,
py::arg("path"),
py::arg("name"),
py::arg("type"))
;
}

2
src/ctags.hpp

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "python_bind.h"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <sstream> #include <sstream>
#include <string> #include <string>
@ -28,6 +29,7 @@ public:
std::stringstream output; std::stringstream output;
static std::vector<Location> get_locations(const boost::filesystem::path &path, const std::string &name, const std::string &type, const std::string &languages = {}); static std::vector<Location> get_locations(const boost::filesystem::path &path, const std::string &name, const std::string &type, const std::string &languages = {});
static void init_module(py::module &api);
private: private:
bool enable_scope, enable_kind; bool enable_scope, enable_kind;

77
src/debug_lldb.cpp

@ -569,3 +569,80 @@ void Debug::LLDB::write(const std::string &buffer) {
process->PutSTDIN(buffer.c_str(), buffer.size()); process->PutSTDIN(buffer.c_str(), buffer.size());
} }
} }
void Debug::LLDB::init_module(pybind11::module &api) {
py::class_<Debug::LLDB, std::unique_ptr<Debug::LLDB, py::nodelete>> dbg(api, "LLDB");
py::class_<Debug::LLDB::Frame>(dbg, "Frame")
.def_readwrite("index", &Debug::LLDB::Frame::index)
.def_readwrite("module_filename", &Debug::LLDB::Frame::module_filename)
.def_readwrite("file_path", &Debug::LLDB::Frame::file_path)
.def_readwrite("function_name", &Debug::LLDB::Frame::function_name)
.def_readwrite("line_nr", &Debug::LLDB::Frame::line_nr)
.def_readwrite("line_index", &Debug::LLDB::Frame::line_index)
;
py::class_<Debug::LLDB::Variable>(dbg, "Variable")
.def_readwrite("thread_index_id", &Debug::LLDB::Variable::thread_index_id)
.def_readwrite("frame_index", &Debug::LLDB::Variable::frame_index)
.def_readwrite("name", &Debug::LLDB::Variable::name)
.def_readwrite("value", &Debug::LLDB::Variable::value)
.def_readwrite("declaration_found", &Debug::LLDB::Variable::declaration_found)
.def_readwrite("file_path", &Debug::LLDB::Variable::file_path)
.def_readwrite("line_nr", &Debug::LLDB::Variable::line_nr)
.def_readwrite("line_index", &Debug::LLDB::Variable::line_index)
;
// py::class_<lldb::SBProcess>(api, "SBProcess");
// .def_readwrite("on_start", &Debug::LLDB::on_start)
// .def_readwrite("on_event", &Debug::LLDB::on_event)
dbg
.def(py::init([]() { return &(Debug::LLDB::get()); }))
.def_readwrite("on_exit", &Debug::LLDB::on_exit)
// .def_readwrite("mutex", &Debug::LLDB::mutex)
.def("continue_debug", &Debug::LLDB::continue_debug)
.def("stop", &Debug::LLDB::stop)
.def("kill", &Debug::LLDB::kill)
.def("step_over", &Debug::LLDB::step_over)
.def("step_into", &Debug::LLDB::step_into)
.def("step_out", &Debug::LLDB::step_out)
.def("cancel", &Debug::LLDB::cancel)
.def("is_invalid", &Debug::LLDB::is_invalid)
.def("is_stopped", &Debug::LLDB::is_stopped)
.def("is_running", &Debug::LLDB::is_running)
.def("get_backtrace", &Debug::LLDB::get_backtrace)
.def("get_variables", &Debug::LLDB::get_variables)
.def("cancel", &Debug::LLDB::cancel)
.def("start", &Debug::LLDB::start,
py::arg("command"),
py::arg("path") = "",
py::arg("breakpoints") = std::vector<std::pair<boost::filesystem::path, int>>(),
py::arg("startup_commands") = std::vector<std::string>(),
py::arg("remote_host") = "")
.def("run_command", &Debug::LLDB::run_command,
py::arg("command"))
.def("select_frame", &Debug::LLDB::select_frame,
py::arg("frame_index"),
py::arg("thread_index_id") = 0)
.def("get_value", &Debug::LLDB::get_value,
py::arg("variable"),
py::arg("file_path"),
py::arg("line_nr"),
py::arg("line_index"))
.def("get_return_value", &Debug::LLDB::get_return_value,
py::arg("file_path"),
py::arg("line_nr"),
py::arg("line_index"))
.def("add_breakpoint", &Debug::LLDB::add_breakpoint,
py::arg("file_path"),
py::arg("line_nr"))
.def("remove_breakpoint", &Debug::LLDB::remove_breakpoint,
py::arg("file_path"),
py::arg("line_nr"),
py::arg("line_count"))
.def(" write", &Debug::LLDB::write,
py::arg("buffer"))
;
}

2
src/debug_lldb.hpp

@ -5,6 +5,7 @@
#include <lldb/API/LLDB.h> #include <lldb/API/LLDB.h>
#include <thread> #include <thread>
#include <tuple> #include <tuple>
#include "python_bind.h"
namespace Debug { namespace Debug {
class LLDB { class LLDB {
@ -84,6 +85,7 @@ namespace Debug {
void remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count); void remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count);
void write(const std::string &buffer); void write(const std::string &buffer);
static void init_module(py::module &api);
private: private:
std::tuple<std::vector<std::string>, std::string, std::vector<std::string>> parse_run_arguments(const std::string &command); std::tuple<std::vector<std::string>, std::string, std::vector<std::string>> parse_run_arguments(const std::string &command);

17
src/dialogs.cpp

@ -94,3 +94,20 @@ std::string Dialog::gtk_dialog(const boost::filesystem::path &path, const std::s
dialog.add_button(button.first, button.second); dialog.add_button(button.first, button.second);
return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : "";
} }
void Dialog::init_module(py::module &api) {
py::class_<Dialog>(api, "Dialog")
.def_static("open_folder", Dialog::open_folder,
py::arg("path"))
.def_static("open_file", Dialog::open_file,
py::arg("path"))
.def_static("new_file", Dialog::new_file,
py::arg("path"))
.def_static("new_folder", Dialog::new_folder,
py::arg("path"))
.def_static("save_file_as", Dialog::save_file_as,
py::arg("path"))
;
}

2
src/dialogs.hpp

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "python_bind.h"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <gtkmm.h> #include <gtkmm.h>
#include <string> #include <string>
@ -11,6 +12,7 @@ public:
static std::string new_file(const boost::filesystem::path &path); static std::string new_file(const boost::filesystem::path &path);
static std::string new_folder(const boost::filesystem::path &path); static std::string new_folder(const boost::filesystem::path &path);
static std::string save_file_as(const boost::filesystem::path &path); static std::string save_file_as(const boost::filesystem::path &path);
static void init_module(py::module &api);
class Message : public Gtk::Window { class Message : public Gtk::Window {
public: public:

8
src/dispatcher.cpp

@ -40,3 +40,11 @@ void Dispatcher::reset() {
functions.clear(); functions.clear();
connect(); connect();
} }
void Dispatcher::init_module(py::module &api) {
py::class_<Dispatcher>(api, "Dispatcher")
.def(py::init())
.def("disconnect", &Dispatcher::disconnect)
.def("post", &Dispatcher::post<std::function<void()> &>)
;

3
src/dispatcher.hpp

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "mutex.hpp" #include "mutex.hpp"
#include "python_bind.h"
#include <functional> #include <functional>
#include <gtkmm.h> #include <gtkmm.h>
#include <list> #include <list>
@ -32,4 +33,6 @@ public:
/// Must be called from main GUI thread /// Must be called from main GUI thread
void reset(); void reset();
static void init_module(py::module &api);
}; };

24
src/plugins.cc

@ -1,6 +1,28 @@
#include "plugins.h" #include "plugins.h"
#include "cmake.h"
#include "compile_commands.h"
#include "config.h" #include "config.h"
#include "python_module.h" #include "ctags.h"
#ifdef JUCI_ENABLE_DEBUG
#include "debug_lldb.h"
#endif
#include "dialogs.h"
#include "terminal.h"
PyObject *Plugins::Module::init_jucipp_module() {
auto api = py::module("Jucipp", "API");
CMake::init_module(api);
CompileCommands::init_module(api);
Config::init_module(api);
Ctags::init_module(api);
#ifdef JUCI_ENABLE_DEBUG
Debug::LLDB::init_module(api);
#endif
Dialog::init_module(api);
Dispatcher::init_module(api);
Terminal::init_module(api);
return api.ptr();
};
Plugins::Plugins() : jucipp_module("Jucipp", Module::init_jucipp_module) { Plugins::Plugins() : jucipp_module("Jucipp", Module::init_jucipp_module) {
auto &config = Config::get(); auto &config = Config::get();

28
src/plugins.h

@ -1,14 +1,38 @@
#pragma once #pragma once
#include <pybind11/embed.h>
#include "python_interpreter.h" #include "python_interpreter.h"
#include <boost/filesystem.hpp>
#include <pybind11/embed.h>
namespace pybind11 {
namespace detail {
template <>
struct type_caster<boost::filesystem::path> {
public:
PYBIND11_TYPE_CASTER(boost::filesystem::path, _("str"));
bool load(handle src, bool) {
value = std::string(pybind11::str(src));
return !PyErr_Occurred();
}
static handle cast(boost::filesystem::path src, return_value_policy, handle) {
return pybind11::str(src.string());
}
};
} // namespace detail
} // namespace pybind11
class __attribute__((visibility("default"))) class __attribute__((visibility("default")))
Plugins { Plugins {
public: public:
Plugins(); Plugins();
void load(); void load();
private: private:
class Module {
public:
static PyObject *init_jucipp_module();
};
py::detail::embedded_module jucipp_module; py::detail::embedded_module jucipp_module;
Python::Interpreter interpreter; Python::Interpreter interpreter;
}; };

342
src/python_module.h

@ -1,342 +0,0 @@
#pragma once
#include "cmake.h"
#include "compile_commands.h"
#include "config.h"
#include "ctags.h"
#include "python_bind.h"
#include "terminal.h"
#include <boost/filesystem.hpp>
#include <pybind11/operators.h>
#include <pybind11/stl.h>
#ifdef JUCI_ENABLE_DEBUG
#include "debug_lldb.h"
#endif
#include "dialogs.h"
namespace pybind11 {
namespace detail {
template <>
struct type_caster<boost::filesystem::path> {
public:
PYBIND11_TYPE_CASTER(boost::filesystem::path, _("str"));
bool load(handle src, bool) {
value = std::string(pybind11::str(src));
return !PyErr_Occurred();
}
static handle cast(boost::filesystem::path src, return_value_policy, handle) {
return pybind11::str(src.string());
}
};
} // namespace detail
} // namespace pybind11
class Module {
static void init_terminal_module(pybind11::module &api) {
py::class_<Terminal, std::unique_ptr<Terminal, py::nodelete>>(api, "Terminal")
.def(py::init([]() { return &(Terminal::get()); }))
.def("process", (int (Terminal::*)(const std::string &, const boost::filesystem::path &, bool)) & Terminal::process,
py::arg("command"),
py::arg("path") = "",
py::arg("use_pipes") = false)
.def("async_process", (void (Terminal::*)(const std::string &, const boost::filesystem::path &, const std::function<void(int)> &, bool)) & Terminal::async_process,
py::arg("command"),
py::arg("path") = "",
py::arg("callback") = nullptr,
py::arg("quiet") = false)
.def("kill_last_async_process", &Terminal::kill_last_async_process,
py::arg("force") = false)
.def("kill_async_processes", &Terminal::kill_async_processes,
py::arg("force") = false)
.def("print", &Terminal::print,
py::arg("message"),
py::arg("bold") = false)
.def("async_print", (void (Terminal::*)(const std::string &, bool)) & Terminal::async_print,
py::arg("message"),
py::arg("bold") = false)
.def("async_print", (void (Terminal::*)(size_t, const std::string &)) & Terminal::async_print,
py::arg("line_nr"),
py::arg("message"))
.def("configure", &Terminal::configure)
.def("clear", &Terminal::clear);
};
static void init_config_module(pybind11::module &api) {
py::class_<Config, std::unique_ptr<Config, py::nodelete>> config(api, "Config");
config
.def(py::init([]() { return &(Config::get()); }))
.def("load", &Config::load)
.def_readonly("version", &Config::version)
;
py::class_<Config::Menu>(config, "Menu")
.def_readwrite("keys", &Config::Menu::keys)
;
py::class_<Config::Theme>(config, "Theme")
.def_readwrite("name", &Config::Theme::name)
.def_readwrite("variant", &Config::Theme::variant)
.def_readwrite("font", &Config::Theme::font)
;
py::class_<Config::Terminal>(config, "Terminal")
.def_readwrite("history_size", &Config::Terminal::history_size)
.def_readwrite("font", &Config::Terminal::font)
;
py::class_<Config::Project> project(config, "Project");
py::class_<Config::Project::CMake>(project, "CMake")
.def_readwrite("command", &Config::Project::CMake::command)
.def_readwrite("compile_command", &Config::Project::CMake::compile_command)
;
py::class_<Config::Project::Meson>(project, "Meson")
.def_readwrite("command", &Config::Project::Meson::command)
.def_readwrite("compile_command", &Config::Project::Meson::compile_command)
;
project
.def_readwrite("default_build_path", &Config::Project::default_build_path)
.def_readwrite("debug_build_path", &Config::Project::debug_build_path)
.def_readwrite("cmake", &Config::Project::cmake)
.def_readwrite("meson", &Config::Project::meson)
.def_readwrite("save_on_compile_or_run", &Config::Project::save_on_compile_or_run)
.def_readwrite("clear_terminal_on_compile", &Config::Project::clear_terminal_on_compile)
.def_readwrite("ctags_command", &Config::Project::ctags_command)
.def_readwrite("python_command", &Config::Project::python_command)
;
py::class_<Config::Source> source(config, "Source");
py::class_<Config::Source::DocumentationSearch>(source, "DocumentationSearch")
.def_readwrite("separator", &Config::Source::DocumentationSearch::separator)
.def_readwrite("compile_command", &Config::Source::DocumentationSearch::queries)
;
source
.def_readwrite("style", &Config::Source::style)
.def_readwrite("font", &Config::Source::font)
.def_readwrite("spellcheck_language", &Config::Source::spellcheck_language)
.def_readwrite("cleanup_whitespace_characters", &Config::Source::cleanup_whitespace_characters)
.def_readwrite("show_whitespace_characters", &Config::Source::show_whitespace_characters)
.def_readwrite("format_style_on_save", &Config::Source::format_style_on_save)
.def_readwrite("format_style_on_save_if_style_file_found", &Config::Source::format_style_on_save_if_style_file_found)
.def_readwrite("smart_inserts", &Config::Source::smart_inserts)
.def_readwrite("show_map", &Config::Source::show_map)
.def_readwrite("map_font_size", &Config::Source::map_font_size)
.def_readwrite("show_git_diff", &Config::Source::show_git_diff)
.def_readwrite("show_background_pattern", &Config::Source::show_background_pattern)
.def_readwrite("show_right_margin", &Config::Source::show_right_margin)
.def_readwrite("right_margin_position", &Config::Source::right_margin_position)
.def_readwrite("auto_tab_char_and_size", &Config::Source::auto_tab_char_and_size)
.def_readwrite("default_tab_char", &Config::Source::default_tab_char)
.def_readwrite("default_tab_size", &Config::Source::default_tab_size)
.def_readwrite("tab_indents_line", &Config::Source::tab_indents_line)
.def_readwrite("wrap_lines", &Config::Source::wrap_lines)
.def_readwrite("highlight_current_line", &Config::Source::highlight_current_line)
.def_readwrite("show_line_numbers", &Config::Source::show_line_numbers)
.def_readwrite("enable_multiple_cursors", &Config::Source::enable_multiple_cursors)
.def_readwrite("auto_reload_changed_files", &Config::Source::auto_reload_changed_files)
.def_readwrite("clang_format_style", &Config::Source::clang_format_style)
.def_readwrite("clang_usages_threads", &Config::Source::clang_usages_threads)
.def_readwrite("documentation_searches", &Config::Source::documentation_searches)
;
py::class_<Config::Log>(config, "Log")
.def_readwrite("libclang", &Config::Log::libclang)
.def_readwrite("language_server", &Config::Log::language_server)
;
py::class_<Config::Plugins>(config, "Plugins")
.def_readwrite("enabled", &Config::Plugins::enabled)
.def_readwrite("path", &Config::Plugins::path)
;
config
.def_readwrite("menu", &Config::menu)
.def_readwrite("theme", &Config::theme)
.def_readwrite("terminal", &Config::terminal)
.def_readwrite("project", &Config::project)
.def_readwrite("source", &Config::source)
.def_readwrite("log", &Config::log)
.def_readwrite("plugins", &Config::plugins)
.def_readwrite("home_path", &Config::home_path)
.def_readwrite("home_juci_path", &Config::home_juci_path)
;
}
static void init_cmake_module(pybind11::module &api) {
py::class_<CMake>(api, "CMake")
.def_readwrite("project_path", &CMake::project_path)
.def("update_default_build", &CMake::update_default_build,
py::arg("default_build_path"),
py::arg("force") = false)
.def("update_debug_build", &CMake::update_debug_build,
py::arg("debug_build_path"),
py::arg("force") = false)
.def("get_executable", &CMake::get_executable,
py::arg("build_path"),
py::arg("file_path"))
;
}
static void init_compile_commands_module(pybind11::module &api) {
py::class_<CompileCommands> compile_commands(api, "CompileCommands");
py::class_<CompileCommands::Command>(compile_commands, "CompileCommands")
.def_readwrite("directory", &CompileCommands::Command::directory)
.def_readwrite("parameters", &CompileCommands::Command::parameters)
.def_readwrite("file", &CompileCommands::Command::file)
;
compile_commands
.def_readwrite("commands", &CompileCommands::commands)
.def_static("get_arguments", &CompileCommands::get_arguments,
py::arg("build_path"),
py::arg("file_path"))
.def_static("is_header", &CompileCommands::is_header,
py::arg("path"))
.def_static("is_source", &CompileCommands::is_source,
py::arg("path"))
;
}
static void init_compile_ctags_module(pybind11::module &api) {
py::class_<Ctags> ctags(api, "Ctags");
py::class_<Ctags::Location>(api, "Ctags")
.def_readwrite("file_path", &Ctags::Location::file_path)
.def_readwrite("line", &Ctags::Location::line)
.def_readwrite("index", &Ctags::Location::index)
.def_readwrite("symbol", &Ctags::Location::symbol)
.def_readwrite("scope", &Ctags::Location::scope)
.def_readwrite("source", &Ctags::Location::source)
.def("__bool__", &Ctags::Location::operator bool)
;
ctags
.def_static("get_result", &Ctags::get_result,
py::arg("path"))
.def_static("get_location", &Ctags::get_location,
py::arg("line"),
py::arg("markup"))
.def_static("get_locations", &Ctags::get_locations,
py::arg("path"),
py::arg("name"),
py::arg("type"))
;
}
#ifdef JUCI_ENABLE_DEBUG
static void init_debug_LLDB_module(pybind11::module &api) {
py::class_<Debug::LLDB, std::unique_ptr<Debug::LLDB, py::nodelete>> dbg(api, "LLDB");
py::class_<Debug::LLDB::Frame>(dbg, "Frame")
.def_readwrite("index", &Debug::LLDB::Frame::index)
.def_readwrite("module_filename", &Debug::LLDB::Frame::module_filename)
.def_readwrite("file_path", &Debug::LLDB::Frame::file_path)
.def_readwrite("function_name", &Debug::LLDB::Frame::function_name)
.def_readwrite("line_nr", &Debug::LLDB::Frame::line_nr)
.def_readwrite("line_index", &Debug::LLDB::Frame::line_index)
;
py::class_<Debug::LLDB::Variable>(dbg, "Variable")
.def_readwrite("thread_index_id", &Debug::LLDB::Variable::thread_index_id)
.def_readwrite("frame_index", &Debug::LLDB::Variable::frame_index)
.def_readwrite("name", &Debug::LLDB::Variable::name)
.def_readwrite("value", &Debug::LLDB::Variable::value)
.def_readwrite("declaration_found", &Debug::LLDB::Variable::declaration_found)
.def_readwrite("file_path", &Debug::LLDB::Variable::file_path)
.def_readwrite("line_nr", &Debug::LLDB::Variable::line_nr)
.def_readwrite("line_index", &Debug::LLDB::Variable::line_index)
;
// py::class_<lldb::SBProcess>(api, "SBProcess");
// .def_readwrite("on_start", &Debug::LLDB::on_start)
// .def_readwrite("on_event", &Debug::LLDB::on_event)
dbg
.def(py::init([]() { return &(Debug::LLDB::get()); }))
.def_readwrite("on_exit", &Debug::LLDB::on_exit)
// .def_readwrite("mutex", &Debug::LLDB::mutex)
.def("continue_debug", &Debug::LLDB::continue_debug)
.def("stop", &Debug::LLDB::stop)
.def("kill", &Debug::LLDB::kill)
.def("step_over", &Debug::LLDB::step_over)
.def("step_into", &Debug::LLDB::step_into)
.def("step_out", &Debug::LLDB::step_out)
.def("cancel", &Debug::LLDB::cancel)
.def("is_invalid", &Debug::LLDB::is_invalid)
.def("is_stopped", &Debug::LLDB::is_stopped)
.def("is_running", &Debug::LLDB::is_running)
.def("get_backtrace", &Debug::LLDB::get_backtrace)
.def("get_variables", &Debug::LLDB::get_variables)
.def("cancel", &Debug::LLDB::cancel)
.def("start", &Debug::LLDB::start,
py::arg("command"),
py::arg("path") = "",
py::arg("breakpoints") = std::vector<std::pair<boost::filesystem::path, int>>(),
py::arg("startup_commands") = std::vector<std::string>(),
py::arg("remote_host") = "")
.def("run_command", &Debug::LLDB::run_command,
py::arg("command"))
.def("select_frame", &Debug::LLDB::select_frame,
py::arg("frame_index"),
py::arg("thread_index_id") = 0)
.def("get_value", &Debug::LLDB::get_value,
py::arg("variable"),
py::arg("file_path"),
py::arg("line_nr"),
py::arg("line_index"))
.def("get_return_value", &Debug::LLDB::get_return_value,
py::arg("file_path"),
py::arg("line_nr"),
py::arg("line_index"))
.def("add_breakpoint", &Debug::LLDB::add_breakpoint,
py::arg("file_path"),
py::arg("line_nr"))
.def("remove_breakpoint", &Debug::LLDB::remove_breakpoint,
py::arg("file_path"),
py::arg("line_nr"),
py::arg("line_count"))
.def(" write", &Debug::LLDB::write,
py::arg("buffer"))
;
}
#endif
static void init_dialogs_module(py::module &api) {
py::class_<Dialog>(api, "Dialog")
.def_static("open_folder", Dialog::open_folder,
py::arg("path"))
.def_static("open_file", Dialog::open_file,
py::arg("path"))
.def_static("new_file", Dialog::new_file,
py::arg("path"))
.def_static("new_folder", Dialog::new_folder,
py::arg("path"))
.def_static("save_file_as", Dialog::save_file_as,
py::arg("path"))
;
}
public:
static auto init_jucipp_module() {
auto api = py::module("Jucipp", "API");
Module::init_terminal_module(api);
Module::init_config_module(api);
Module::init_cmake_module(api);
Module::init_compile_commands_module(api);
#ifdef JUCI_ENABLE_DEBUG
Module::init_debug_LLDB_module(api);
#endif
Module::init_dialogs_module(api);
return api.ptr();
};
};

31
src/terminal.cpp

@ -603,3 +603,34 @@ bool Terminal::on_key_press_event(GdkEventKey *event) {
} }
return true; return true;
} }
void Terminal::init_module(pybind11::module &api) {
py::class_<Terminal, std::unique_ptr<Terminal, py::nodelete>>(api, "Terminal")
.def(py::init([]() { return &(Terminal::get()); }))
.def("process", (int (Terminal::*)(const std::string &, const boost::filesystem::path &, bool)) & Terminal::process,
py::arg("command"),
py::arg("path") = "",
py::arg("use_pipes") = false)
.def("async_process", (void (Terminal::*)(const std::string &, const boost::filesystem::path &, const std::function<void(int)> &, bool)) & Terminal::async_process,
py::arg("command"),
py::arg("path") = "",
py::arg("callback") = nullptr,
py::arg("quiet") = false)
.def("kill_last_async_process", &Terminal::kill_last_async_process,
py::arg("force") = false)
.def("kill_async_processes", &Terminal::kill_async_processes,
py::arg("force") = false)
.def("print", &Terminal::print,
py::arg("message"),
py::arg("bold") = false)
.def("async_print", (void (Terminal::*)(const std::string &, bool)) & Terminal::async_print,
py::arg("message"),
py::arg("bold") = false)
.def("async_print", (void (Terminal::*)(size_t, const std::string &)) & Terminal::async_print,
py::arg("line_nr"),
py::arg("message"))
.def("configure", &Terminal::configure)
.def("clear", &Terminal::clear)
;
}

2
src/terminal.hpp

@ -2,6 +2,7 @@
#include "dispatcher.hpp" #include "dispatcher.hpp"
#include "mutex.hpp" #include "mutex.hpp"
#include "process.hpp" #include "process.hpp"
#include "python_bind.h"
#include "source_base.hpp" #include "source_base.hpp"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
@ -33,6 +34,7 @@ public:
void configure(); void configure();
void clear(); void clear();
static void init_module(pybind11::module &api);
std::function<void()> scroll_to_bottom; std::function<void()> scroll_to_bottom;

Loading…
Cancel
Save