Programming

Andrew Chadwick edited this page Jun 10, 2016 · 5 revisions
Clone this wiki locally

:construction: Get started: check out the README for details of how to build & test MyPaint.
:octocat: MyPaint uses git: see the GitHub Help pages for how to get started.

MyPaint is mainly written in Python (using the GTK toolkit), with a brush engine in C++. More information about the code can be found in the old developer documentation. In general, the codebase is quite simple and easy to get into.

We use git for code maintenance and the main repository is currently located on github.

Please write code that matches what you see elsewhere. We have a preferred Python style: see the Python Style Guide for MyPaint.

Contributed code must abide by our Licensing Policy.

MyPaint uses MSYS2 for porting onto the Windows platform.

Discovering PyGI/PyGObject

MyPaint uses GObject-Introspection (“GI”) to access certain third-party libraries. This is a mechanism that allows library code written in a compiled language to be used by scripting languages. It's normally not possible to do this directly. The Python library for using other libs through GI is called PyGObject or PyGI. It's easy to spot Python code which uses it: it will always have imports looking like the following near the top.

from gi.repository import Gdk
from gi.repository import Gtk

GObject-Introspection rewrites the names of class definitions, methods, and functions so that they make the most sense in the target language. For example, if you're constructing a GTK button in C, you'd do

GtkWidget *button = gtk_button_new(...);
gtk_button_set_label(button, "Click me");

but the equivalent Python code is

button = Gtk.Button()
button.set_label("Click me")

The documentation for GTK and GDK is not readily available through GI. You have to consult the C API documentation for the library instead. To make matching up the C function/class names and their Python equivalents, you can use pygi-grep, a tool for searching Python-GObject namespaces.

$ pygi-grep -vi -r 3.0 Gtk tree.*row
from gi.repository import Gtk
Gtk.TreeModelRow
Gtk.TreeModelRowIter
Gtk.TreeRowReference
Gtk.tree_get_row_drag_data
Gtk.tree_row_reference_deleted
Gtk.tree_row_reference_inserted
Gtk.tree_set_row_drag_data

Learning GTK+ and GDK

The C interfaces for GTK+ and GDK are well documented:

You may also wish to install Devhelp for offline browsing.

See Also