Question

Comment puis-je aller sur l'ajout Chaco à une application existante PyQt4?

Heures de recherches ont donné peu ( recherche pour vous ). Jusqu'à présent, j'ai pensé que j'ai besoin les lignes suivantes:

import os
os.environ['ETS_TOOLKIT']='qt4'

je ne pouvais pas trouver le code PyQt4-Chaco ne importe où sur les internets

Je serais très reconnaissant à tous ceux qui remplir les blancs pour me montrer le tracé de la ligne la plus simple possible (avec 2 points)

from PyQt4 import QtCore, QtGui
import sys
import os
os.environ['ETS_TOOLKIT']='qt4'

from enthought <blanks>
:
:

app = QtGui.QApplication(sys.argv)
main_window = QtGui.QMainWindow()
main_window.setCentralWidget(<blanks>)
main_window.show()
app.exec_()
print('bye')

quelle classe Chaco / Enthought hérite de QWidget?

Était-ce utile?

La solution

Voici ce que vous avez besoin:

import os, sys
os.environ['ETS_TOOLKIT'] = 'qt4'

from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
from numpy import linspace, pi, sin
from enthought.enable.api import Component, Container, Window
from enthought.chaco.api import create_line_plot, \
                                add_default_axes, \
                                add_default_grids, \
                                OverlayPlotContainer


x = linspace(-pi,pi,100)
y = sin(x)
plot = create_line_plot((x,y))
add_default_grids(plot)
add_default_axes(plot)
container = OverlayPlotContainer(padding = 50)
container.add(plot)
plot_window = Window(None, -1, component=container)
plot_window.control.setWindowTitle('hello')
plot_window.control.resize(400,400)
plot_window.control.show()

app.exec_()

plot_window.control hérite de QWidget

Autres conseils

Je viens de voir aujourd'hui. Il est tout à fait possible et assez facile à intégrer Chaco dans Qt ainsi que WX. En fait, tous les exemples, lorsqu'il est exécuté avec votre environnement ETS_TOOLKIT var ensemble à « Qt4 », font exactement cela. (Chaco nécessite il être une boîte à outils graphique sous-jacente.)

Je l'ai écrit un petit exemple autonome qui remplit les espaces vides dans votre modèle de code, et montre comment intégrer un terrain chaco dans une fenêtre 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()

Je ne sais pas Chaco, mais j'utilise VTK, voici le code pour tirer des lignes, ayant un (x, y, z) les coordonnées d'entre eux.

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

Il utilise QVTKRenderWindowInteractor pour interagir avec le pyqt4.

Je ne sais pas Chaco, mais un coup d'œil me dit que ce n'est pas possible.

Les deux Chaco et PyQt sont des boîtes à outils graphiques destinées à interagir avec l'utilisateur. Chaco est INTRIGUE et PyQt plus orientée vers les applications. Chacun a sa propre façon de gérer ce une fenêtre est, comment détecter les clics des utilisateurs, comment gérer les événements de peinture, ... afin qu'ils ne se mélangent pas.

Si vous avez besoin logiciel de traçage, vous pouvez essayer d'utiliser matplotlib pour générer des images statiques de graphique et afficher l'image en PyQt. Ou essayez un graphique à base de PyQt ou boîte à outils de traçage.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top