其他提示

我刚看到这个今天。这是绝对可能的,相当简单的Qt里面嵌入查科以及WX。事实上,所有的例子,当你ETS_TOOLKIT环境VAR设置为“QT4”运行,在做这个。 (查科需要存在是构成底层GUI工具包。)

我已经写了一个小的,独立的例子是,在你的代码模板的空白填充,并演示了如何嵌入Qt的窗口内查科情节。

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))

    # Create some line plots of some of the data
    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")

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
    plot.overlays.append(zoom)

    # This Window object bridges the Enable and Qt4 worlds, and handles events
    # and drawing.  We can create whatever hierarchy of nested containers we
    # want, as long as the top-level item gets set as the .component attribute
    # of a Window.
    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)

    # The .control attribute references a QWidget that gives Chaco events
    # and that Chaco paints into.
    main_window.setCentralWidget(enable_window.control)

    main_window.show()
    app.exec_()

if __name__ == "__main__":
    main()

我不知道查科,但我使用VTK,这里是代码绘制一些线条,有一个(X,Y,Z)它们的坐标。

    """Define an actor and its properties, to be drawn on the scene using 'lines' representation."""
    ren = vtk.vtkRenderer()
    apd=vtk.vtkAppendPolyData()

    for i in xrange(len(coordinates)):
        line=vtk.vtkLineSource()

        line.SetPoint1(coordinates[i][0]) # 1st atom coordinates for a given bond
        line.SetPoint2(coordinates[i][1]) # 2nd atom coordinates for a given bond
        line.SetResolution(21)
        apd.AddInput(line.GetOutput())

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInput(apd.GetOutput())
    lines_actor = vtk.vtkActor()
    lines_actor.SetMapper(mapper)
    lines_actor.GetProperty().SetColor(colorR, colorG, colorB)
    lines_actor.GetProperty().SetOpacity(opacity)

        # Add newly created actor to the renderer.
        self.ren.AddViewProp(actor) # Prop is the superclass of all actors, composite props etc.
        # Update renderer.
        self.ren.GetRenderWindow().Render()

它使用QVTKRenderWindowInteractor与PyQt4的相互作用。

我不知道查科,但咋一看告诉我,这是不可能的。

查科和PyQt的两者都设计成与用户交互的图形工具包。查科是面向情节和PyQt的侧重于应用方面。每个人都有自己的管理方式的窗口是什么,如何检测用户点击,如何处理油漆事件,......使他们不混合在一起。

如果您需要绘图软件,你可以尝试使用matplotlib生成图表的静态图像,并显示在PyQt的图像。或尝试一个PyQt的基于图形或绘图工具包。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top