我今天看到了这个。将Chaco嵌入Qt和WX中是完全可能且相当简单的。事实上,当您的ETS_TOOLKIT环境变量设置为“qt4”时,所有示例都会执行此操作。(Chaco需要有一个底层GUI工具包。)
我编写了一个小型的独立示例,填充了您的代码模板中的空白,并演示了如何在Qt窗口中嵌入chaco Plot。
qt_example.py:
qt_example.py:
"""
Example of how to directly embed Chaco into Qt widgets.
The actual plot being created is drawn from the basic/line_plot1.py code.
"""
import sys
from numpy import linspace
from scipy.special import jn
from PyQt4 import QtGui, QtCore
from enthought.etsconfig.etsconfig import ETSConfig
ETSConfig.toolkit = "qt4"
from enthought.enable.api import Window
from enthought.chaco.api import ArrayPlotData, Plot
from enthought.chaco.tools.api import PanTool, ZoomTool
class PlotFrame(QtGui.QWidget):
""" This widget simply hosts an opaque enthought.enable.qt4_backend.Window
object, which provides the bridge between Enable/Chaco and the underlying
UI toolkit (qt4). This code is basically a duplicate of what's in
enthought.enable.example_support.DemoFrame, but is reproduced here to
make this example more stand-alone.
"""
def __init__(self, parent, **kw):
QtGui.QWidget.__init__(self)
def create_chaco_plot(parent):
x = linspace(-2.0, 10.0, 100)
pd = ArrayPlotData(index = x)
for i in range(5):
pd.set_data("y" + str(i), jn(i,x))
plot = Plot(pd, title="Line Plot", padding=50, border_visible=True)
plot.legend.visible = True
plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
plot.plot(("index", "y3"), name="j_3", color="blue")
plot.tools.append(PanTool(plot))
zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
plot.overlays.append(zoom)
return Window(parent, -1, component = plot)
def main():
app = QtGui.QApplication(sys.argv)
main_window = QtGui.QMainWindow(size=QtCore.QSize(500,500))
enable_window = create_chaco_plot(main_window)
main_window.setCentralWidget(enable_window.control)
main_window.show()
app.exec_()
if __name__ == "__main__":
main()
app = QtGui.QApplication(sys.argv)
这一行。 - random guy