~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to examples/demo/qt_example.py

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
Example of how to directly embed Chaco into Qt widgets.
3
 
 
4
 
The actual plot being created is drawn from the basic/line_plot1.py code.
5
 
"""
6
 
from traits.etsconfig.etsconfig import ETSConfig
7
 
ETSConfig.toolkit = "qt4"
8
 
 
9
 
import sys
10
 
from numpy import linspace
11
 
from scipy.special import jn
12
 
from pyface.qt import QtGui, QtCore
13
 
 
14
 
from enable.api import Window
15
 
 
16
 
from chaco.api import ArrayPlotData, Plot
17
 
from chaco.tools.api import PanTool, ZoomTool
18
 
 
19
 
 
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
23
 
    UI toolkit (qt4).  
24
 
    """
25
 
    def __init__(self, parent, **kw):
26
 
        QtGui.QWidget.__init__(self)
27
 
 
28
 
def create_chaco_plot(parent):
29
 
    x = linspace(-2.0, 10.0, 100)
30
 
    pd = ArrayPlotData(index = x)
31
 
    for i in range(5):
32
 
        pd.set_data("y" + str(i), jn(i,x))
33
 
 
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")
39
 
 
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)
44
 
 
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
48
 
    # of a Window.
49
 
    return Window(parent, -1, component = plot)
50
 
 
51
 
def main():
52
 
    app = QtGui.QApplication.instance()
53
 
    main_window = QtGui.QMainWindow()
54
 
    main_window.resize(500,500)
55
 
    
56
 
 
57
 
    enable_window = create_chaco_plot(main_window)
58
 
 
59
 
    # The .control attribute references a QWidget that gives Chaco events
60
 
    # and that Chaco paints into.
61
 
    main_window.setCentralWidget(enable_window.control)
62
 
 
63
 
    main_window.show()
64
 
    app.exec_()
65
 
 
66
 
if __name__ == "__main__":
67
 
    main()
68