[vtkusers] Import slot from another .py file
Helvin Lui
helvinlui at gmail.com
Thu Aug 20 03:42:04 EDT 2009
Sorry, want to correct myself.
When the above code is run, no error occurs at the command line, but a
window comes up saying "vtkpython.exe has stopped working". The way I run
the code is in command line, using the vtkpython exe.
If I instead, change the red line to:
QtCore.QObject.connect(self.ui.button_importMesh,
QtCore.SIGNAL("clicked()"), displayMesh)
that is, removing the VTKGraphics part, which is the class name, then the
error says that displayMesh is not defined.
Regards,
Helvin
p.s Please help!
On Thu, Aug 20, 2009 at 7:37 PM, Helvin Lui <helvinlui at gmail.com> wrote:
> Hi,
> I wanted to use a slot which has been defined in another .py file. (The
> slot is called displayMesh, defined in a class called "VTKGraphics", in a
> file called "vtkGraphics.py")
> However, when I try to connect the slot to a button in my gui, an error
> comes up: "NameError: global name 'displayMesh' is not defined. Am I
> importing the VTKGraphics class wrongly? I have included the beginning of
> each file below.
>
> The main file is like this:
>
> import sys, os, tempfile
> from PyQt4 import QtCore, QtGui, QtOpenGL
> from ui0 import Ui_main
> # Import the VTKGraphics Class from the file called vtkGraphics.py
> from vtkGraphics import VTKGraphics
>
> class StartMain(QtGui.QMainWindow):
>
> def __init__(self, parent=None):
> QtGui.QWidget.__init__(self, parent)
> self.ui = Ui_main()
> self.ui.setupUi(self)
> # Here I want to connect the clicked signal of button_importMesh to the
> slot called displayMesh. But an error occurs here.
> QtCore.QObject.connect(self.ui.button_importMesh,
> QtCore.SIGNAL("clicked()"), VTKGraphics.displayMesh)
>
> # etc...
>
>
>
> My vtkGraphics.py file:
>
> from PyQt4 import QtCore
>
> class VTKGraphics(QtCore.QObject):
>
> def displayMesh(self):
> import vtk
>
> with open('C:\\Qt\\SimLCM\\Default\\Data_Input_Geometry.txt', 'r')
> as f:
> meshPoints = vtk.vtkPoints()
> aMesh = vtk.vtkVoxel()
>
>
> # etc...
>
>
> I have searched around for quite a bit, but could not find the solution.
> Thanks so much guys,
> --
> Helvin
>
> "Though the world may promise me more, I'm just made to be filled with the
> Lord."
>
--
Helvin
"Though the world may promise me more, I'm just made to be filled with the
Lord."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090820/5b1e8293/attachment.htm>
More information about the vtkusers
mailing list