pyClip.cpp
1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//*****************************************************************
/*
VLibras: Automatic contents translator from Portuguese to LIBRAS
Copyright (c) 2015 Bruno santos
VLibras-Core group at LAViD, Federal University of Paraiba
*/
//*****************************************************************
/**
* \file pyClip.cpp
* \authors Bruno Santos
* \date Janeiro 2015
*/
#include "pyClip.h"
PyClip::PyClip()
{
// Initialize the Python interpreter
Py_Initialize();
// Call the Bdrag application and copy the clipboard
pName = PyString_FromString("Clipboard");
assert(pName!=NULL);
// Loads the script name saved in 'pName'
pModule = PyImport_Import(pName);
//PyErr_Print();
assert(pModule!=NULL);
// Returns the dictionary object that implements the namespace pModule
pDict = PyModule_GetDict(pModule);
//PyErr_Print();
assert(pDict!=NULL);
// Return the string of clipboard
pFunc = PyDict_GetItemString(pDict, "clip");
// Start Bdrag
p_On = PyDict_GetItemString(pDict, "bdragOn");
// OFF Bdrag
p_Off = PyDict_GetItemString(pDict, "bdragOff");
//PyErr_Print();
assert(pFunc!=NULL);
}
PyClip::~PyClip()
{
Py_Finalize();
}
char * PyClip::clip()
{
// Call the callable object 'pFunc' with arguments given by the tuple 'pArgs'
pResult = PyObject_CallObject(pFunc,NULL);
assert(pResult!=NULL);
return PyString_AsString(pResult);
}
void PyClip::bdragOn()
{
// Call the callable object 'pFunc' with arguments given by the tuple 'pArgs'
PyObject_CallObject(p_On,pArgs);
}
void PyClip::bdragOff()
{
// Call the callable object 'pFunc' with arguments given by the tuple 'pArgs'
PyObject_CallObject(p_Off,pArgs);
}