From 477c5a1e1a6e2854dbffdc3d7c8f0697cbc3d1d1 Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 23 Feb 2015 08:39:16 +0100 Subject: [PATCH] BAB-21 #comment removed test-folder #time 2m --- juci/plugin/CMakeLists.txt | 57 ------------------ juci/plugin/plugin.cc | 118 ------------------------------------- juci/plugin/plugin.h | 28 --------- juci/plugin/plugin_ext.cc | 8 --- juci/plugin/randomtext.txt | 39 ------------ 5 files changed, 250 deletions(-) delete mode 100644 juci/plugin/CMakeLists.txt delete mode 100644 juci/plugin/plugin.cc delete mode 100644 juci/plugin/plugin.h delete mode 100644 juci/plugin/plugin_ext.cc delete mode 100644 juci/plugin/randomtext.txt diff --git a/juci/plugin/CMakeLists.txt b/juci/plugin/CMakeLists.txt deleted file mode 100644 index 2b05816..0000000 --- a/juci/plugin/CMakeLists.txt +++ /dev/null @@ -1,57 +0,0 @@ -cmake_minimum_required (VERSION 2.4) -set(project_name plugin) -project (${project_name}) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") - -include(FindPkgConfig) - -#Boost_FOUND - True if headers and requested libraries were found -#Boost_INCLUDE_DIRS - Boost include directories -#Boost_LIBRARY_DIRS - Link directories for Boost libraries -#Boost_LIBRARIES - Boost component libraries to be linked -find_package(Boost 1.55 REQUIRED COMPONENTS python system ) - -if(!${Boost_FOUND}) - message(FATAL_ERROR "Boost libraries not found") -endif() - -#GTKMM_FOUND - True if headers and requested libraries were found -#GTKMM_INCLUDE_DIRS - GTKMM include directories -#GTKMM_LIBRARY_DIRS - Link directories for GTKMM libraries -#GTKMM_LIBRARIES - GTKMM component libraries to be linked -pkg_check_modules(GTKMM REQUIRED gtkmm-3.0) - -if(!${GTKMM_FOUND}) - message(FATAL_ERROR "Gtkmm not found") -endif() - -#PYTHONLIBS_FOUND - True if headers and requested libraries were found -#PYTHON_INCLUDE_DIRS - GTKMM include directories -#PYTHON_LIBRARIES - GTKMM component libraries to be linked -#$PYTHONLIBS_VERSION_STRING - ersion string -find_package(PythonLibs 2.7 REQUIRED) - -if(!${PYTHONLIBS_FOUND}) - message(FATAL_ERROR "Pythonlibs not found") -else() - message("Found python libs ${PYTHONLIBS_VERSION_STRING}") -endif() - -ADD_LIBRARY(plugintest_ext MODULE - plugin.h - plugin.cc - plugin_ext.cc - ) - -set_target_properties(plugintest_ext PROPERTIES PREFIX "") -target_link_libraries(plugintest_ext ${Boost_LIBRARIES}) - -add_executable(${project_name} - plugin.h - plugin.cc - ) - -include_directories(${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS}) -link_directories(${GTKMM_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS} ${PYTHON_LIBRARIES}) -target_link_libraries(${project_name} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${GTKMM_LIBRARIES}) \ No newline at end of file diff --git a/juci/plugin/plugin.cc b/juci/plugin/plugin.cc deleted file mode 100644 index 1a76f57..0000000 --- a/juci/plugin/plugin.cc +++ /dev/null @@ -1,118 +0,0 @@ -#include "plugin.h" - -//////////////////////////////////////////////////////////////////////////////// -// -// setPythonVar: -// initiates a string value (k_var_value) to a declared variable name -// (k_var_name) within a given namespace(python_name_space) -// -//////////////////////////////////////////////////////////////////////////////// - -bp::object Plugin::setPythonVar(const std::string k_var_name, - const std::string k_var_value, - bp::object python_name_space ) { - std::string temp = k_var_name + " = \"" + k_var_value + "\""; - bp::str the_var(temp); - return bp::exec(the_var, python_name_space); -} - -//////////////////////////////////////////////////////////////////////////////// -// -// openPythonScript: -// Opens a python plugin script within a file path and a python namespace -// -//////////////////////////////////////////////////////////////////////////////// - -bp::object Plugin::openPythonScript(const std::string path, - bp::object python_name_space) { - std::string temp = g_project_root + "plugins/" + path + "/" + path + ".py"; - bp::str the_path(temp); - return bp::exec_file(the_path, python_name_space); -} - -//////////////////////////////////////////////////////////////////////////////// -// -// for testing purposes only -// -//////////////////////////////////////////////////////////////////////////////// - -std::string Plugin::get_test_value2(){ - return "STRING FROM WITHIN C++"; -} - -/* public functions */ - - -//////////////////////////////////////////////////////////////////////////////// -// -// snippet: -// takes a std::string and converts it into a matching snippet -// if no matching snippet, returns the same string -// -//////////////////////////////////////////////////////////////////////////////// - -void Plugin::snippet(std::string& word){ - try{ - /* initialize python interpreter */ - Py_Initialize(); - bp::object main_module = bp::import("__main__"); - bp::object main_namespace = main_module.attr("__dict__"); - - /* runs script from python */ - bp::object ignored1 = setPythonVar("word", word, main_namespace); - bp::object ignored2 = openPythonScript(__func__, main_namespace); - - /* extracts desired values */ - bp::object pySnippet = bp::eval("getSnippet()", main_namespace); - word = bp::extract(pySnippet); - /* add snippet to textView */ - //TODO add snippet - - }catch(bp::error_already_set const&){ - PyErr_Print(); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// -// get_test_value: -// for testing purposes -// uses a python module generated from c++ -// calls c++ function from python -// returns string to c++ from python -// prints the string from python within c++ -// -//////////////////////////////////////////////////////////////////////////////// - - void Plugin::get_test_value(){ - try{ - /* initialize python interpreter */ - Py_Initialize(); - bp::object main_module = bp::import("__main__"); - bp::object main_namespace = main_module.attr("__dict__"); - - /* runs script from python */ - const std::string path("test"); - bp::object ignored2 = openPythonScript(path, main_namespace); - - /* extracts desired values */ - bp::object pySnippet = bp::eval("get_test_value()", main_namespace); - std::string mword = bp::extract(pySnippet); - /* add snippet to textView */ - std::cout << mword << std::endl; - //TODO add snippet - - }catch(bp::error_already_set const&){ - PyErr_Print(); - } - } - -int main(int argc, char *argv[]) -{ - std::string word("ifelse"); - Plugin::snippet(word); - //Plugin::get_test_value(); - std::cout << word << std::endl; - return 0; - -} diff --git a/juci/plugin/plugin.h b/juci/plugin/plugin.h deleted file mode 100644 index 0c6e1aa..0000000 --- a/juci/plugin/plugin.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef JUCI_PLUGIN_H_ -#define JUCI_PLUGIN_H_ - -#include -#include - -#include -#include - -namespace bp = boost::python; - -const std::string g_project_root("~/q6/testing/plugin/"); -//TODO (forgie) get current working directory.. - -class Plugin{ - public: - static void snippet(std::string& word); - static void get_test_value(); - static std::string get_test_value2(); - private: - static bp::object setPythonVar(const std::string varName, - const std::string varValue, - bp::object python_name_space); - static bp::object openPythonScript(const std::string path, - bp::object python_name_space); -}; - -#endif // JUCI_PLUGIN_H_ diff --git a/juci/plugin/plugin_ext.cc b/juci/plugin/plugin_ext.cc deleted file mode 100644 index 5067e10..0000000 --- a/juci/plugin/plugin_ext.cc +++ /dev/null @@ -1,8 +0,0 @@ -#include "plugin.h" -#include -using namespace boost::python; - -BOOST_PYTHON_MODULE(plugintest_ext) -{ - def("get_test_value2", &Plugin::get_test_value2); -} diff --git a/juci/plugin/randomtext.txt b/juci/plugin/randomtext.txt deleted file mode 100644 index 4bbb4f6..0000000 --- a/juci/plugin/randomtext.txt +++ /dev/null @@ -1,39 +0,0 @@ -/* -void theprogram() -{ - std::string input; - std::cout << "Enter string to transform: "; - std::getline(std::cin, input); - //std::string inttransformed = CallPythonPlugIn(input); - std::cout << "The transformed string is: " << input << std::endl; -} - -int test1() -{ - try{ - Py_Initialize(); - object main_module = import("__main__"); - object main_namespace = main_module.attr("__dict__"); - object ignored = exec("result = 5 ** 2", main_namespace); - int five_squared = extract(main_namespace["result"]); - - printf("%d\n", five_squared); - - return five_squared; - } - catch(error_already_set const&){ - PyErr_Print(); - } - - return -1; -} - -void test2(int theNum, int &test) -{ - int seven = 7; - - test = 7+ theNum; - - std::cout << theNum << std::endl; -} -*/