Skip to content
Carl Smith edited this page May 13, 2014 · 20 revisions

Welcome to the PyGGI wiki!

PyGGI stands for Python Graphical Generated Interface. It is a binding for GTk, GDK, WebkitGTK and supporting libraries. It uses ctypes exclusively to create the binding, thereby elminating problems with native Python code and cross-platform availability.

PyGGI's API is faithful to the underlying C API, with a few exceptions. One exception is how signals and callbacks are implemented. PyGGI makes the connection explicit as methods of a class, rather than a string-based (hidden) API. So a signal connection like "on-view-ready" for the WebKitWebView class becomes a method

def on_view_ready(self, callback)

The callback in such a case must match the signature in number of parameters for that signal as defined in the underlying system. Also, the GObject's idle_add function in Python has the signature gobject.idle_add( func, arg1, arg3, arg3,...)

This will add the function func for execution in the gtk main thread, calling func with the arbitrary number of arguments provided. Returning True from this function will continue to execute the function during idle periods of time within the gtk main loop.

Javascript Integration

PyGGI has integration with the javascriptcore engine, that allows:

  • Export of python modules and classes to javascript, accessible from the javascript code
  • Import of javascript objects/function/classes into Python, allowing use of any included javascript .js lib directly from Python
  • Complete ability to write Python script that mimics javascript to act on the DOM. No need to write a line of javascript!

Scripting the DOM through Ophidian

Ophidian is a techonology that is a binding between javascript and Python. Do not confuse this with a binding to javascriptcore engine. Python can import javascript objects and export classes and object to javascript. With Ophidian, the is no need to write any javascript. For example, a jQuery line:

$('.button').button();
$('.button').click( function(){ $(this).html("Clicked");} );

in Ophidian looks like

from pyggi.javascript import jquery
  ...
browser = ... << create browser window >> ...
  ...

_ = jquery.initialize( browser.ge_env() ) #each browser window has a unique javascript environment
def button_clicked( index, obj):
    this = _(obj)
    this.html("Clicked")
_('.button').button();
_('.button').click( button_clicked )`

There are a few points of interest. Each browser window has its own javascript environment, and the code manipulating a browser page must first call jquery.initialize using the target environment; this function returns the jquery object, equivalent to the "$" object/operator.

jq = jquery.initialize( webkitview.get_env() )

Also, as standard with GTK, execution of Ophidian script must be done within the gtk main loop to take effect.

Installation and System Requirements

Tutorial