Search code examples
documentationpygobject

Where to find reference for PyGObject


I'm working on a Python based source code editor. I've created a clean layout with a Gtk.Notebook. Creating a main layout was easy with Glade, but right after I imported gi.repository, everything got hard. It's very hard to find documentation. From pydoc I can 't get anything, only method signatures, which are usually *args, **kwargs. I often need to check what a method returns or takes in, and I haven't really started signals and other stuff yet.

Is there a complete/almost-complete documentation, especially for GtkSource? GtkSource is especially undocumented.


Solution

  • You should probably read my answer to a similar SO question: PyGObject GTK+ 3 Documentation. In short, you should refer to the GtkSourceView API Reference for C. Don't worry, it's not hard. When you see "GtkSourceView" in the C docs you know it's "GtkSource.View" in Python. When you see "gtk_source_view_new" in C docs you know it's the constructor in Python "GtkSouce.View()". You can set any GTK+ property in the constructor and there is usually get_foo/set_foo style methods for each property.

    Therefore, you can do things like:

    view = GtkSouce.View(indent_width=4, show_line_numbers=True)
    view.get_buffer().set_text("Hello World!")
    

    Remember, GTK+ widgets are objects so you need to pay attention to the hierarchy to find all the methods and properties for a widget.