pyClip.cpp 1.37 KB
#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);  	    
	}

}