pyClip.cpp 1.63 KB
//*****************************************************************
/*
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);  	    
}