What's New
Methods of subclasses of the X11 `Canvas` class that start with the `draw_` prefix will be re-bound to the cairo context passed to the `on_draw` callback method. For example,
~~~ python
class DrawMethodsCanvas(x11.Canvas):
def on_button_pressed(self, button, state, x, y):
if button == 1:
self.destroy()
def draw_rect(ctx, width, height):
ctx.set_source_rgb(*[r() for _ in range(3)])
ctx.rectangle(0, 0, width, height)
ctx.fill()
def on_draw(self, ctx):
for i in range(4):
ctx.draw_rect(self.width >> i, self.height >> i)
~~~
Whilst the method `draw_rect` is defined inside the `DrawMethodsCanvas` class, inside the `on_draw` method it can be accessible as a method of `ctx` (which is now an instance of `ExtendedContext`, a wrapper around `cairo.Context`).