static-sites/bases/do-blog/resources/documents/python/gtk3/tutorial16.py

53 lines
2.0 KiB
Python
Executable File

#+BEGIN_COMMENT
.. title: GTK-3 custom signals example
.. slug: 16-gtk3-custom-signals-example
.. date: 2014-09-11 12:00:00 UTC
.. tags: GTK-3, python, widgets, signals
.. category: python
.. description: Simple example on how to setup, connect to and trigger signals.
.. type: text
#+END_COMMENT
#+CAPTION: Opengl touch events
[[../../../images/gtk/tut16-signals.png]]
#append this to module path so we can load from the parent directory
import sys, os
from scaffold import web
from scaffold.loaders import load, load_partial
class page:
name = __name__
title = 'GTK3 custom signals example'
tags = 'GTK3', 'Python', 'signals'
intro = 'Simple example on how to setup, connect to and trigger signals.'
date = '2014-09-11'
path = os.path.abspath('./')
image = web.template.path_image + '/gtk/tut16-signals.png'
def create_content(self):
web.images.create(self.image, title='GTK Window')
web.page.section(
web.div.create(
web.images.render()
).set_classes('sources').render()
)
web.paragraph.create(
"""In this program we create 4 custom signals, the first to are connected to and triggered on launch, the latter two are triggered when you click the buttons.""")
web.page.section(web.paragraph.render())
web.paragraph.create(
"""We can create new signals using GObject.signal_new, we can then connect the new signal and callback as we normally would using widget .connect methods as normal.
To trigger our custom event we use the .emit() method, this method also aalows us to fake events, for example we might want to fake the user clicking a button.""")
web.page.section(web.paragraph.render())
web.link.create('Launchpad','Gtk signals','http://bazaar.launchpad.net/~oly/python-examples/trunk/files/head:/python-examples/gtk3/')
print self.files
web.pre.create(load(self.files + '/gtk3/tut16/tut16-signals.py'))
web.page.section(web.pre.render())