[vtkusers] Import slot from another .py file
Helvin Lui
helvinlui at gmail.com
Thu Aug 20 03:37:24 EDT 2009
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."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090820/d5a92dd7/attachment.htm>
More information about the vtkusers
mailing list