Commit 57df7a7897f2fe75e9847681380a00b4e87b86e9
1 parent
f94789e8
Exists in
master
Corrige problemas na geração da biblioteca (.so) e usa uma solução de captura do…
… clipboard com o utilitário XSel.
Showing
11 changed files
with
127 additions
and
121 deletions
Show diff stats
... | ... | @@ -0,0 +1,6 @@ |
1 | +------------------------------------------------------------ | |
2 | + LISTA DE PROBLEMAS A SEREM RESOLVIDOS | |
3 | +------------------------------------------------------------ | |
4 | + | |
5 | +1. Ao selecionar um texto de uma palavra por linha no editor gedit, por exemplo, o sistema só captura a primeira; | |
6 | +2. | ... | ... |
Makefile
... | ... | @@ -15,32 +15,25 @@ |
15 | 15 | |
16 | 16 | include Makefile.top |
17 | 17 | |
18 | -MODULE = vlibras_desktop | |
19 | -LIBNAME = CorePlugin | |
18 | +MODULE = vlibras_desktop | |
19 | +LIBNAME = CorePlugin | |
20 | 20 | |
21 | -VERSION = 0.2 | |
21 | +VERSION = 0.2 | |
22 | 22 | |
23 | -CFLAGS = \ | |
23 | +CFLAGS =\ | |
24 | 24 | -I$(INCDIR)\ |
25 | - -I/usr/include/python2.7 | |
25 | + `python-config --cflags`\ | |
26 | 26 | |
27 | -CFLAGS += -m64 -g -fPIC | |
28 | - | |
29 | -LDFLAGS = \ | |
30 | - -L/usr/lib/python2.7/config\ | |
31 | - -lpthread\ | |
32 | - -ldl\ | |
33 | - -lutil\ | |
34 | - -lm\ | |
35 | - -lpython2.7 | |
27 | +LDFLAGS =\ | |
28 | + `python-config --ldflags` | |
36 | 29 | |
37 | 30 | HEADERS = \ |
38 | - py_tradutor.h\ | |
39 | - core_plugin.h | |
31 | + py_tradutor.h\ | |
32 | + core_plugin.h | |
40 | 33 | |
41 | 34 | SOURCES = \ |
42 | - py_tradutor.cpp\ | |
43 | - core_plugin.cpp | |
35 | + $(SRCDIR)/py_tradutor.cpp\ | |
36 | + $(SRCDIR)/core_plugin.cpp | |
44 | 37 | |
45 | 38 | .SUFFIXES: .cpp .o .h |
46 | 39 | ... | ... |
Makefile.build
... | ... | @@ -3,22 +3,17 @@ LIB = lib$(LIBNAME)-$(VERSION).so |
3 | 3 | |
4 | 4 | all: shared |
5 | 5 | |
6 | -shared: $(addprefix $(SRCDIR),$(OBJS)) | |
6 | +shared: | |
7 | 7 | @mkdir $(PLUGINDIR) > /dev/null 2>&1 && \ |
8 | 8 | echo "Create directory $(PLUGINDIR)... $(OK)" || echo -n "" |
9 | 9 | @echo -n Linking $(LIB) ... |
10 | - @$(CC) -shared -o $(PLUGINDIR)$(LIB) $(addprefix $(SRCDIR),$(OBJS)) $(LDFLAGS) || \ | |
10 | + @$(CXX) -shared -fPIC $(CFLAGS) $(SOURCES) $(LDFLAGS) -o $(PLUGINDIR)/$(LIB) || \ | |
11 | 11 | (echo " $(FAILED)"; exit 1;) |
12 | 12 | @cd $(PLUGINDIR); \ |
13 | 13 | ln -f -s $(LIB) lib$(LIBNAME).so; \ |
14 | 14 | cd .. && echo " $(OK)" || (echo " $(FAILED)"; exit 1;) |
15 | 15 | |
16 | -%.o: %.cpp | |
17 | - @echo -n Compiling file $(notdir $<) to $(notdir $@) ... | |
18 | - @$(CXX) $(CFLAGS) -c $< -o $@ && \ | |
19 | - echo " $(OK)" || (echo " $(FAILED)"; exit 1;) | |
20 | - | |
21 | 16 | clean: |
22 | 17 | @echo -n Cleaning... |
23 | 18 | @rm -rf $(addprefix $(SRCDIR),$(OBJS)) $(PLUGINDIR) 2> /dev/null && \ |
24 | - echo " $(OK)" || (echo " $(FAILED)"; exit 1;) | |
19 | + echo " $(OK)" || (echo " $(FAILED)"; exit 1;) | ... | ... |
Makefile.top
... | ... | @@ -3,11 +3,11 @@ INSTALL_PATH = . |
3 | 3 | CC = gcc |
4 | 4 | CXX = g++ |
5 | 5 | |
6 | -INCDIR = ./include/ | |
7 | -SRCDIR = ./src/ | |
8 | -TESTSDIR = ./tests/ | |
9 | -PLUGINDIR = ./plugin/ | |
10 | -DOCDIR = ./doc/ | |
6 | +INCDIR = ./include | |
7 | +SRCDIR = ./src | |
8 | +TESTSDIR = ./tests | |
9 | +PLUGINDIR = ./plugin | |
10 | +DOCDIR = ./doc | |
11 | 11 | |
12 | 12 | OK = \033[30;32mOK\033[m |
13 | 13 | FAILED = \033[30;31mFAILED\033[m | ... | ... |
README
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | # |
8 | 8 | # ***************************************************************** |
9 | 9 | |
10 | + | |
10 | 11 | ------------------------------------------------------------------- |
11 | 12 | Compile and generate the shared library to VLibras-Core-Desktop |
12 | 13 | ------------------------------------------------------------------- |
... | ... | @@ -17,4 +18,5 @@ $ make |
17 | 18 | Clean object and shared library files |
18 | 19 | ------------------------------------------------------------------- |
19 | 20 | |
20 | -$ make clean | |
21 | 21 | \ No newline at end of file |
22 | +$ make clean | |
23 | + | ... | ... |
include/core_plugin.h
... | ... | @@ -13,24 +13,21 @@ |
13 | 13 | * \date Janeiro 2015 |
14 | 14 | */ |
15 | 15 | |
16 | -#ifndef COREPLUGIN_H | |
17 | -#define COREPLUGIN_H | |
16 | +#ifndef COREPLUGIN_H_ | |
17 | +#define COREPLUGIN_H_ | |
18 | 18 | |
19 | -#include "py_tradutor.h" | |
20 | 19 | #include <string> |
21 | -#include <stdio.h> | |
22 | - | |
23 | -/** \brief Encapsulamento do plugin | |
24 | - * | |
25 | - * Encapsula todo o funcionamento do core tornando-o acessível | |
26 | - * a qualquer outra aplicação que importe o plugin gerado. | |
27 | - * As funções de aqui declaradas realizam todas as ações | |
28 | - * necessarias ao usuário que deseja utilizar este plugin. | |
29 | - */ | |
20 | +#include <stdio.h> | |
21 | +#include "py_tradutor.h" | |
22 | + | |
23 | +#define MAX_BUFFER_SELECTION 1024 | |
24 | + | |
25 | +#ifdef __cplusplus | |
30 | 26 | extern "C" |
31 | 27 | { |
32 | - static PyTradutor * tradutor = new PyTradutor(); | |
28 | +#endif | |
33 | 29 | |
30 | + PyTradutor *tradutor; | |
34 | 31 | |
35 | 32 | /** \brief Inicializa o ambiente core |
36 | 33 | * |
... | ... | @@ -55,6 +52,11 @@ extern "C" |
55 | 52 | * das funcionalidades do core na aplicação. |
56 | 53 | */ |
57 | 54 | int coreFinalize(); |
55 | + | |
56 | + char * get_text_selection(); | |
57 | + | |
58 | +#ifdef __cplusplus | |
58 | 59 | } |
60 | +#endif | |
59 | 61 | |
60 | -#endif /* COREPLUGIN_H */ | |
61 | 62 | \ No newline at end of file |
63 | +#endif // COREPLUGIN_H_ | |
62 | 64 | \ No newline at end of file | ... | ... |
include/py_tradutor.h
src/core_plugin.cpp
... | ... | @@ -15,34 +15,38 @@ |
15 | 15 | |
16 | 16 | #include "core_plugin.h" |
17 | 17 | |
18 | + | |
18 | 19 | int coreInitialize() |
19 | 20 | { |
20 | - // Initialize the translater (python) enviroment | |
21 | - //tradutor = new PyTradutor(); | |
22 | - printf("[INFO]: CorePlugin initialized\n"); | |
21 | + tradutor = new PyTradutor(); | |
23 | 22 | return 1; |
24 | 23 | } |
25 | 24 | |
26 | 25 | const char* coreExecute() |
27 | 26 | { |
28 | - printf("[INFO]: CorePlugin running\n"); | |
29 | - // Gets the content on Pasteboard and pass it as argument for the translater | |
30 | - //std::string pasteboardContent = Pasteboard::getGeneralContent(); | |
31 | - printf("[WAR]: *** XSel not found!\n"); | |
32 | - char* str = new char[10]; | |
33 | - strcpy(str, "teste da biblioteca do sistema"); | |
34 | - std::string traducao = tradutor->convertStringToGlosa((const char*) str); | |
35 | - | |
36 | - // Puts the translater return in lowercase and convert it as char pointer to be returned | |
37 | - //std::transform(traducao.begin(), traducao.end(), traducao.begin(), ::tolower); | |
38 | - return traducao.c_str(); | |
27 | + | |
28 | + return tradutor->convertStringToGlosa((const char*) get_text_selection()); | |
39 | 29 | } |
40 | 30 | |
41 | 31 | int coreFinalize() |
42 | 32 | { |
43 | - // Finalize the translater | |
44 | - if (tradutor) | |
45 | - delete tradutor; | |
46 | - printf("[INFO]: CorePlugin finalized\n"); | |
47 | - return 1; | |
33 | + if (!tradutor) | |
34 | + return -1; | |
35 | + delete tradutor; | |
36 | + return 1; | |
37 | +} | |
38 | + | |
39 | +char * get_text_selection() | |
40 | +{ | |
41 | + FILE *comm_file_p = popen("xsel -o ", "r"); | |
42 | + if (!comm_file_p) | |
43 | + { | |
44 | + /* FIXME: add exception */ | |
45 | + return NULL; | |
46 | + } | |
47 | + char line_buff [MAX_BUFFER_SELECTION]; | |
48 | + char *output_str_p = fgets(line_buff, sizeof(line_buff), comm_file_p); | |
49 | + pclose(comm_file_p); | |
50 | + | |
51 | + return output_str_p; | |
48 | 52 | } |
49 | 53 | \ No newline at end of file | ... | ... |
src/main.cpp
... | ... | @@ -1,53 +0,0 @@ |
1 | -//***************************************************************** | |
2 | -/* | |
3 | - VLibras: Automatic pasteboardContents translator from Portuguese to LIBRAS | |
4 | - | |
5 | - Copyright (c) 2015 Gustavo Sobral, Erickson Silva, Leonardo Araújo | |
6 | - VLibras-Core group at LAViD, Federal University of Paraiba | |
7 | -*/ | |
8 | -//***************************************************************** | |
9 | - | |
10 | -/** | |
11 | - * \file main.cpp | |
12 | - * \author Gustavo Sobral, Leonardo Araújo | |
13 | - * \date Janeiro 2015 | |
14 | - */ | |
15 | - | |
16 | -//#include <py_tradutor.h> | |
17 | -#include <core_plugin.h> | |
18 | - | |
19 | -#include <iostream> | |
20 | -#include <fstream> | |
21 | -#include <string> | |
22 | - | |
23 | -int main() | |
24 | -{ | |
25 | - | |
26 | - // Inicializa o tradutor | |
27 | - //PyTradutor *tradutorTest; | |
28 | - //tradutorTest = new PyTradutor(); | |
29 | - | |
30 | - // Pega o conteúdo do clipboard e salva em `pasteboardContent` | |
31 | - //std::string pasteboardContent = Pasteboard::getGeneralContent(); | |
32 | - // Traduz o conteúdo do clipboard em `pasteboardContent` para a string `traducao` | |
33 | - //char* str = new char[10]; | |
34 | - //strcpy(str, "o gato comeu o rato"); | |
35 | - //std::string traducao = tradutorTest->convertStringToGlosa(str); | |
36 | - | |
37 | - // [LOG] Exibe o conteudo do buffer de clipboard em `pasteboardContent` e traduz para glosa salvando seu resultado em `traducao` | |
38 | - //std::cout << "[[ Conteudo em memoria ]]\n" << str << std::endl; | |
39 | - //std::cout << "[[ Tradução ]]\n" << traducao << std::endl; | |
40 | - | |
41 | - //std::cout << "\n##### ##### #####" << std::endl; | |
42 | - | |
43 | - // Inicializa o plugin | |
44 | - std::cout << "[[Initialize]] | " << coreInitialize() << std::endl; | |
45 | - // Executa o CorePlugin | |
46 | - std::cout << "[[Execute]] | " << coreExecute() << std::endl; | |
47 | - // Finaliza o ambiente | |
48 | - std::cout << "[[Finalize]] | " << coreFinalize() << std::endl; | |
49 | - | |
50 | - // Exclui o que foi utilizado | |
51 | - // delete tradutorTest; | |
52 | - return 0; | |
53 | -} | |
54 | 0 | \ No newline at end of file |
src/py_tradutor.cpp
... | ... | @@ -18,7 +18,11 @@ |
18 | 18 | PyTradutor::PyTradutor() |
19 | 19 | { |
20 | 20 | Py_Initialize(); |
21 | - pName = PyString_FromString("ModuleTranslate"); | |
21 | + // Imports the Aelius and Tradutor inside the Unity python interpreter | |
22 | + PyRun_SimpleString("import sys, os\n" | |
23 | + "sys.path.append(os.path.expanduser('~') + '/vlibras-libs/tradutor')\n" | |
24 | + "sys.path.append(os.path.expanduser('~') + '/vlibras-libs')\n"); | |
25 | + pName = PyString_FromString("PortGlosa"); | |
22 | 26 | assert(pName!=NULL); |
23 | 27 | pModule = PyImport_Import(pName); |
24 | 28 | PyErr_Print(); |
... | ... | @@ -26,7 +30,7 @@ PyTradutor::PyTradutor() |
26 | 30 | pDict = PyModule_GetDict(pModule); |
27 | 31 | PyErr_Print(); |
28 | 32 | assert(pDict!=NULL); |
29 | - pFunc = PyDict_GetItemString(pDict, "iniciar"); | |
33 | + pFunc = PyDict_GetItemString(pDict, "traduzir"); | |
30 | 34 | PyErr_Print(); |
31 | 35 | assert(pFunc!=NULL); |
32 | 36 | ... | ... |
... | ... | @@ -0,0 +1,53 @@ |
1 | +//***************************************************************** | |
2 | +/* | |
3 | + VLibras: Automatic pasteboardContents translator from Portuguese to LIBRAS | |
4 | + | |
5 | + Copyright (c) 2015 Gustavo Sobral, Erickson Silva, Leonardo Araújo | |
6 | + VLibras-Core group at LAViD, Federal University of Paraiba | |
7 | +*/ | |
8 | +//***************************************************************** | |
9 | + | |
10 | +/** | |
11 | + * \file main.cpp | |
12 | + * \author Gustavo Sobral, Leonardo Araújo | |
13 | + * \date Janeiro 2015 | |
14 | + */ | |
15 | + | |
16 | +#include <py_tradutor.h> | |
17 | +//#include <core_plugin.h> | |
18 | + | |
19 | +#include <iostream> | |
20 | +#include <fstream> | |
21 | +#include <string> | |
22 | + | |
23 | +int main() | |
24 | +{ | |
25 | + | |
26 | + // Inicializa o tradutor | |
27 | + PyTradutor *tradutorTest; | |
28 | + tradutorTest = new PyTradutor(); | |
29 | + | |
30 | + // Pega o conteúdo do clipboard e salva em `pasteboardContent` | |
31 | + //std::string pasteboardContent = Pasteboard::getGeneralContent(); | |
32 | + // Traduz o conteúdo do clipboard em `pasteboardContent` para a string `traducao` | |
33 | + char* str = new char[10]; | |
34 | + strcpy(str, "o gato comeu o rato"); | |
35 | + std::string traducao = tradutorTest->convertStringToGlosa(str); | |
36 | + | |
37 | + // [LOG] Exibe o conteudo do buffer de clipboard em `pasteboardContent` e traduz para glosa salvando seu resultado em `traducao` | |
38 | + std::cout << "[[ Conteudo em memoria ]]\n" << str << std::endl; | |
39 | + std::cout << "[[ Tradução ]]\n" << traducao << std::endl; | |
40 | + | |
41 | + //std::cout << "\n##### ##### #####" << std::endl; | |
42 | + | |
43 | + // Inicializa o plugin | |
44 | + //std::cout << "[[Initialize]] | " << coreInitialize() << std::endl; | |
45 | + // Executa o CorePlugin | |
46 | + //std::cout << "[[Execute]] | " << coreExecute() << std::endl; | |
47 | + // Finaliza o ambiente | |
48 | + //std::cout << "[[Finalize]] | " << coreFinalize() << std::endl; | |
49 | + | |
50 | + // Exclui o que foi utilizado | |
51 | + // delete tradutorTest; | |
52 | + return 0; | |
53 | +} | ... | ... |