Updates to Python GTK+ 3 Tutorial

I continued working on the Python GTK+ 3 Tutorial since I announced it almost a month ago. I added a section describing the Gtk.Grid widget, menus, dialogs and Gtk.TextView, the latter just added today. In addition, I added screenshots for all examples and merged a couple of grammar/typo fixes from other people. The current contents should cover the most important widgets and should allow you to create more complex applications. Still missing are some advanced topics such as Drag-n-Drop and creating custom widgets such as CellRenderes or GObject sub-classes.

Although, I tried to describe all classes and methods I used in the examples, it's still sad that there is currently no replacement for the excellent PyGTK reference. Because of that I decided to include a stripped down version of the API reference in the tutorial. Hopefully, people don't get confused by this and expect it to reflect the complete API.

The source of the tutorial and all examples are available at my github repository.


diff --git a/source/treeview.txt b/source/treeview.txt
index 66b33b2..0ba47e9 100644
--- a/source/treeview.txt
+++ b/source/treeview.txt
@@ -67,7 +67,7 @@ of rows and use slices to retrieve or set values.

.. code-block:: python

- # Print number of columns
+ # Print number of rows
print len(store)
# Print all but first column
print store[treeiter][1:]

Thanks for this tutorial.

Nice work. Gtk3 seems really usefull with introspection but it have a lack of documentation very important. It is needed cover advanced examples and link apps that use the really potential of the methods. Also cover custom widgets and extensions of the API.

Nice Work. I noted two errors in the exemple of the chapter 6 about Entry.
This one is localised in the function on_icon_toggled (for me on_chckIcon_toggled).
The code line for the position of the icon is not at the good location
Another error is a strange behaviour. Effectively, modifying the code for having a stock icon at the begin (or at the end,it is the same result) this one is effectively present but when the check button is de-active, this one is always present. I have not able to resolve this last point.

#-*- coding: utf8 -*-
# entrywindow.py
# Copyright 2012 Olivier <xxxxxxxxxxxxxxx>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
from gi.repository import Gtk, GObject

class EntryWindow(Gtk.Window):

def __init__(self):
Gtk.Window.__init__(self, title="Demo Entrée")
self.set_size_request(220, 100)

self.timeout_id = None

vboxEntry = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)

self.txtSalut = Gtk.Entry()
self.txtSalut.set_text("Salut tout le monde")
vboxEntry.pack_start(self.txtSalut, True, True, 0)

hboxcheckbutton = Gtk.Box(spacing=6)
vboxEntry.pack_start(hboxcheckbutton, True, True, 0)

self.chckbtnEditable = Gtk.CheckButton("Editable")
self.chckbtnEditable.connect("toggled", self.on_chckbtnEditable_toggled)
hboxcheckbutton.pack_start(self.chckbtnEditable, True, True, 0)

self.chckbtnVisible = Gtk.CheckButton("Visible")
self.chckbtnVisible.connect("toggled", self.on_chckbtnVisible_toggled)
hboxcheckbutton.pack_start(self.chckbtnVisible, True, True, 0)

self.chckbtnPulse = Gtk.CheckButton("Pulse")
self.chckbtnPulse.connect("toggled", self.on_chckbtnPulse_toggled)
hboxcheckbutton.pack_start(self.chckbtnPulse, True, True, 0)

self.chckbtnIcon = Gtk.CheckButton("Icon")
self.chckbtnIcon.connect("toggled", self.on_chckbtnIcon_toggled)
hboxcheckbutton.pack_start(self.chckbtnIcon, True, True, 0)

def on_chckbtnEditable_toggled(self, button):
value = button.get_active()

def on_chckbtnVisible_toggled(self, button):
value = button.get_active()

def on_chckbtnPulse_toggled(self, button):
if button.get_active():
#Appelle self.do_pulse chaque 100 ms
self.timeout_id = GObject.timeout_add(100, self.do_pulse, None)
#N'appelle pas du tout self.do_pulse
self.timeout_id = None

def do_pulse(self, user_data):
return True

def on_chckbtnIcon_toggled(self, button):
if button.get_active():
stock_id = Gtk.STOCK_NO
self.txtSalut.set_icon_from_stock(Gtk.EntryIconPosition.PRIMARY, stock_id)
stock_id = None
#self.txtSalut.set_icon_from_stock(Gtk.EntryIconPosition.PRIMARY, stock_id)

interface = EntryWindow()
interface.connect("delete_event", Gtk.main_quit)