Hi,<div><br></div><div>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") </div>
<div>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.</div>
<div><br></div><div>The main file is like this:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">import sys, os, tempfile<br>
from PyQt4 import QtCore, QtGui, QtOpenGL<br>from ui0 import Ui_main<br># Import the VTKGraphics Class from the file called vtkGraphics.py<br><span class="Apple-style-span" style="background-color: rgb(255, 255, 51);">from vtkGraphics import VTKGraphics</span><br>
<br>class StartMain(QtGui.QMainWindow):<br></span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"> </span></font></span><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><br>
</span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"> </span></font></span><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">def __init__(self, parent=None):<br>
</span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"> </span></font></span><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">QtGui.QWidget.__init__(self, parent)<br>
</span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"> </span></font></span><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">self.ui = Ui_main()<br>
</span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"> </span></font></span><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">self.ui.setupUi(self)<br>
</span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"> </span></font></span><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"># Here I want to connect the clicked signal of button_importMesh to the slot called displayMesh. But an error occurs here.<br>
</span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"> </span></font></span><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="background-color: rgb(255, 204, 204);">QtCore.QObject.connect(self.ui.button_importMesh, QtCore.SIGNAL("clicked()"), VTKGraphics.displayMesh)</span><br>
<br># etc...</span></font></blockquote><div><font class="Apple-style-span" face="'courier new'" size="2"><span class="Apple-style-span" style="font-size: 10px;"><br></span></font><br></div><div>My vtkGraphics.py file:</div>
<div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: small;">from PyQt4 import QtCore<br>
<br><span class="Apple-style-span" style="background-color: rgb(255, 255, 51);">class VTKGraphics(QtCore.QObject)</span>:<br><br> def <span class="Apple-style-span" style="background-color: rgb(255, 255, 51);">displayMesh</span>(self): <br>
import vtk<br> <br> with open('C:\\Qt\\SimLCM\\Default\\Data_Input_Geometry.txt', 'r') as f: <br> meshPoints = vtk.vtkPoints()<br> aMesh = vtk.vtkVoxel()</span></font></blockquote>
<div><div> </div><div> # etc...</div><div><br></div><div><br></div><div>I have searched around for quite a bit, but could not find the solution. </div><div>Thanks so much guys,</div></div><div>-- <br>Helvin <br>
<br>"Though the world may promise me more, I'm just made to be filled with the Lord."<br>
</div>