static gboolean
init (NstPlugin *plugin)
{
	Py_Initialize();

	gobject = pygobject_init(2,1,0);

	module = PyImport_ImportModule("blueman.gui.NstBluetooth");
	if(!module) {
		PyErr_Print();
		return FALSE;
	}

	PyObject* class = PyObject_GetAttrString(module, "NstBluetooth");
	if(!class) {
		PyErr_Print();
		return FALSE;
	}

	Py_DECREF(class);

	self = PyInstance_New(class, NULL, NULL);
	if(!self) {
		PyErr_Print();
		return FALSE;
	}

	return PyInstance_Check(self);
}
Ejemplo n.º 2
0
static void
glade_python_init_pygobject_check (gint req_major, gint req_minor, gint req_micro)
{
  PyObject *gi, *gobject;

  /* import gobject */
  pygobject_init (req_major, req_minor, req_micro);
  if (PyErr_Occurred ())
    {
      g_warning ("Error initializing Python interpreter: could not "
                 "import pygobject");

      return;
    }

  gi = PyImport_ImportModule ("gi");
  if (gi == NULL)
    {
      g_warning ("Error initializing Python interpreter: could not "
                 "import gi");

      return;
    }

  gobject = PyImport_ImportModule ("gi.repository.GObject");
  if (gobject == NULL)
    {
      g_warning ("Error initializing Python interpreter: could not "
                 "import gobject");

      return;
    }
}
Ejemplo n.º 3
0
PyMODINIT_FUNC
init_gi(void)
{
    PyObject *m;
    PyObject *api;

    m = Py_InitModule("_gi", _pygi_functions);
    if (m == NULL) {
        return;
    }

    if (pygobject_init(-1, -1, -1) == NULL) {
        return;
    }

    if (_pygobject_import() < 0) {
        return;
    }

    Pycairo_IMPORT;
    if (Pycairo_CAPI == NULL)
        return;

    _pygi_repository_register_types(m);
    _pygi_info_register_types(m);
    _pygi_struct_register_types(m);
    _pygi_boxed_register_types(m);
    _pygi_argument_init();

    api = PyCObject_FromVoidPtr((void *)&PyGI_API, NULL);
    if (api == NULL) {
        return;
    }
    PyModule_AddObject(m, "_API", api);
}
Ejemplo n.º 4
0
initthunarx(void)
{
    PyObject *m, *d;
    
    if (!g_getenv("INSIDE_THUNARX_PYTHON"))
    {
	    Py_FatalError("This module can only be used from thunarx");
	    return;
    }
	
    if (!pygobject_init(-1, -1, -1))
    {
      PyErr_Print();
      Py_FatalError("Can't initialize module gobject");
    }
    init_pygtk ();

    m = Py_InitModule ("thunarx", pythunarx_functions);
    d = PyModule_GetDict (m);

    pythunarx_register_classes(d);
    
    if (PyErr_Occurred())
    {
      PyErr_Print();
      Py_FatalError("Can't initialize module thunarx");
    }
}
Ejemplo n.º 5
0
PyMODINIT_FUNC
initpywebkitgtk(void)
{
    PyObject* m;
    PyObject* d;

    gtk_init(NULL, NULL);
    g_type_init();
    if (!g_thread_supported ())
        g_thread_init(NULL);

    if (!pygobject_init(-1, -1, -1)) {
        PyErr_Print();
        Py_FatalError ("can't initialise module gobject");
    }

    init_pygobject();

    WebViewObjectType.tp_new = PyType_GenericNew;
    if (PyType_Ready(&WebViewObjectType) < 0)
        return;

    m = Py_InitModule3("pywebkitgtk", webkitgtk_methods, webkitgtk_doc);
    if (m == NULL)
        return;

    Py_INCREF(&WebViewObjectType);
    PyModule_AddObject(m, "WebView", (PyObject *)&WebViewObjectType);

    d = PyModule_GetDict (m);
    webkit_init_pywebkit(m, &pywebkit_api_fns);
}
Ejemplo n.º 6
0
PyMODINIT_FUNC
PyInit_PageLauncherHook(void)
{

	pygobject_init(-1, -1, -1);

	PyObject * m;
	m = PyModule_Create(&moduledef);
	if (m == NULL)
		return NULL;

	/* create the PageLauncherHook exception */
	((struct module_state*)PyModule_GetState(m))->Error = PyErr_NewException("PageLauncherHook.error", NULL, NULL);
	Py_INCREF(((struct module_state*)PyModule_GetState(m))->Error);
	PyModule_AddObject(m, "error", ((struct module_state*)PyModule_GetState(m))->Error);

        
	/** init numpy **/
	//import_array();

	return m;

}
Ejemplo n.º 7
0
static gboolean
peas_plugin_loader_python_initialize (PeasPluginLoader *loader)
{
  PeasPluginLoaderPython *pyloader = PEAS_PLUGIN_LOADER_PYTHON (loader);
  PeasPluginLoaderPythonPrivate *priv = GET_PRIV (pyloader);
  PyGILState_STATE state = 0;
  long hexversion;

  /* We can't support multiple Python interpreter states:
   * https://bugzilla.gnome.org/show_bug.cgi?id=677091
   */

  /* Python initialization */
  if (Py_IsInitialized ())
    {
      state = PyGILState_Ensure ();
    }
  else
    {
      Py_InitializeEx (FALSE);
      priv->must_finalize_python = TRUE;
    }

  hexversion = PyLong_AsLong (PySys_GetObject ((char *) "hexversion"));

#if PY_VERSION_HEX < 0x03000000
  if (hexversion >= 0x03000000)
#else
  if (hexversion < 0x03000000)
#endif
    {
      g_critical ("Attempting to mix incompatible Python versions");

      goto python_init_error;
    }

  /* Initialize PyGObject */
  pygobject_init (PYGOBJECT_MAJOR_VERSION,
                  PYGOBJECT_MINOR_VERSION,
                  PYGOBJECT_MICRO_VERSION);

  if (PyErr_Occurred ())
    {
      g_warning ("Error initializing Python Plugin Loader: "
                 "PyGObject initialization failed");

      goto python_init_error;
    }

  /* Initialize support for threads */
  pyg_enable_threads ();
  PyEval_InitThreads ();

  /* Only redirect warnings when python was not already initialized */
  if (!priv->must_finalize_python)
    pyg_disable_warning_redirections ();

  /* Must be done last, finalize() depends on init_failed */
  if (!peas_python_internal_setup (!priv->must_finalize_python))
    {
      /* Already warned */
      goto python_init_error;
    }

  if (!priv->must_finalize_python)
    PyGILState_Release (state);
  else
    priv->py_thread_state = PyEval_SaveThread ();

  return TRUE;

python_init_error:

  if (PyErr_Occurred ())
    PyErr_Print ();

  g_warning ("Please check the installation of all the Python "
             "related packages required by libpeas and try again");

  if (!priv->must_finalize_python)
    PyGILState_Release (state);

  priv->init_failed = TRUE;
  return FALSE;
}
Ejemplo n.º 8
0
void ada_init_pygtk (void) {
#ifdef PYGTK
  init_pygtk();
#endif
  pygobject_init(-1, -1, -1);
}
Ejemplo n.º 9
0
void
gtk_inspector_python_init(void)
{
#ifdef ENABLE_PYTHON
    int res;
    struct sigaction old_sigint;

    if (is_blacklisted())
        return;

    /* This prevents errors such as "undefined symbol: PyExc_ImportError" */
    if (!dlopen(PYTHON_SHARED_LIB, RTLD_NOW | RTLD_GLOBAL))
    {
        g_error("%s\n", dlerror());
        return;
    }

    captured_stdout = g_string_new("");
    captured_stderr = g_string_new("");

    /* Back up and later restore SIGINT so Python doesn't steal it from us. */
    res = sigaction(SIGINT, NULL, &old_sigint);

    if (!Py_IsInitialized())
        Py_Initialize();

    res = sigaction(SIGINT, &old_sigint, NULL);

    Py_InitModule("gtk_inspector", gtk_inspector_python_methods);
    PyRun_SimpleString(
        "import gtk_inspector\n"
        "import sys\n"
        "\n"
        "class StdoutCatcher:\n"
        "    def write(self, str):\n"
        "        gtk_inspector.capture_stdout(str)\n"
        "\n"
        "class StderrCatcher:\n"
        "    def write(self, str):\n"
        "        gtk_inspector.capture_stderr(str)\n"
        "\n"
    );

    if (!pygobject_init(-1, -1, -1))
    {
        fprintf(stderr, "Error initializing pygobject support.\n");
        PyErr_Print();
        return;
    }

    char *argv[] = { "", NULL };
    PySys_SetArgv(0, argv);

    if (!PyImport_ImportModule("gi._gobject"))
      {
        PyErr_SetString(PyExc_ImportError, "could not import gi.gobject");
        return;
      }
    if (!PyImport_ImportModule("gi.repository"))
      {
        PyErr_SetString(PyExc_ImportError, "could not import gi.repository");
        return;
      }
    if (!PyImport_ImportModule("gi.repository.Gtk"))
      {
        PyErr_SetString(PyExc_ImportError, "could not import gtk");
        return;
      }

    python_enabled = TRUE;
#endif // ENABLE_PYTHON
}