pyClip.cpp
1.37 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
#include "pyClip.h"
namespace Clipboard
{
PyClip::PyClip()
{
// Initialize the Python interpreter
Py_Initialize();
// Type conversion between C++ string to Py string
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 object from dictionary pDict which has a key 'iniciar'
pFunc = PyDict_GetItemString(pDict, "clip");
p_On = PyDict_GetItemString(pDict, "bdragOn");
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,pArgs);
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);
}
}