blob: 897c86f6d9d52baec129e9be321b51ae5a3e8e91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
from __future__ import absolute_import
import gtk
import cairo
import cairoplot
from .handler import Handler as _Handler
class GTKHandler(_Handler, gtk.DrawingArea):
"""Handler to create plots that output to vector files."""
def __init__(self, *args, **kwargs):
"""Create Handler for arbitrary surfaces."""
_Handler.__init__(self)
gtk.DrawingArea.__init__(self)
# users of this class must set plot manually
self.plot = None
self.context = None
# connect events for resizing/redrawing
self.connect("expose_event", self.on_expose_event)
def on_expose_event(self, widget, data):
"""Redraws plot if need be."""
self.context = widget.window.cairo_create()
if (self.plot is not None):
self.plot.render()
def prepare(self, plot):
"""Update plot's size and context with custom widget."""
_Handler.prepare(self, plot)
self.plot = plot
plot.context = self.context
allocation = self.get_allocation()
plot.dimensions[cairoplot.HORZ] = allocation.width
plot.dimensions[cairoplot.VERT] = allocation.height
|