2
Example of how to directly embed Chaco into Qt widgets.
4
The actual plot being created is drawn from the basic/line_plot1.py code.
6
from traits.etsconfig.etsconfig import ETSConfig
7
ETSConfig.toolkit = "qt4"
10
from numpy import linspace
11
from scipy.special import jn
12
from pyface.qt import QtGui, QtCore
14
from enable.api import Window
16
from chaco.api import ArrayPlotData, Plot
17
from chaco.tools.api import PanTool, ZoomTool
20
class PlotFrame(QtGui.QWidget):
21
""" This widget simply hosts an opaque enable.qt4_backend.Window
22
object, which provides the bridge between Enable/Chaco and the underlying
25
def __init__(self, parent, **kw):
26
QtGui.QWidget.__init__(self)
28
def create_chaco_plot(parent):
29
x = linspace(-2.0, 10.0, 100)
30
pd = ArrayPlotData(index = x)
32
pd.set_data("y" + str(i), jn(i,x))
34
# Create some line plots of some of the data
35
plot = Plot(pd, title="Line Plot", padding=50, border_visible=True)
36
plot.legend.visible = True
37
plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
38
plot.plot(("index", "y3"), name="j_3", color="blue")
40
# Attach some tools to the plot
41
plot.tools.append(PanTool(plot))
42
zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
43
plot.overlays.append(zoom)
45
# This Window object bridges the Enable and Qt4 worlds, and handles events
46
# and drawing. We can create whatever hierarchy of nested containers we
47
# want, as long as the top-level item gets set as the .component attribute
49
return Window(parent, -1, component = plot)
52
app = QtGui.QApplication.instance()
53
main_window = QtGui.QMainWindow()
54
main_window.resize(500,500)
57
enable_window = create_chaco_plot(main_window)
59
# The .control attribute references a QWidget that gives Chaco events
60
# and that Chaco paints into.
61
main_window.setCentralWidget(enable_window.control)
66
if __name__ == "__main__":