[Tutor] How to access a method defined in one class from another class (which is a thread) in Python3?
SM
sunithanc at gmail.com
Thu Aug 8 23:03:43 CEST 2013
On 08/08/13 21:24, SM wrote:
example, I ended up doing exactly what you suggested. I am sure I am
> missing something, as it is giving the same error:
> Here is what I am doing based on your suggestion:
>
> class bcThread(threading.Thread):
> def h(self, y):
> y.setStdoutToTextEditWindowFw() #(line 1277)
>
...
[snip]
> x = Ui_MainWindow()
> self.h(x) # (line 1319)
>
So far so good.
class Ui_MainWindow(object)
> def setupUi(self, MainWindow):
> [snip]
>
> self.textEdit_fwcmdlineoutput = QtGui.QTextEdit(self.tab_fw)
>
This only comes into existence after setupUi is called.
Normally that would be in the UI init() method but you don;t
show any init or any other call to setupUi
[SM] Sorry that I didn't add that part. setupUI is called from the main as
below:
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Wonder if it is necessary to call it through __init__. I used Py Qt4
Designer to generate the skeleton of the Gui code and have been using it
like this for sometime now.
Thanks,
-SM
self.textEdit_fwcmdlineoutput.setObjectName(_fromUtf8("textEdit_fwcmdlineoutput"))
>
def setStdoutToTextEditWindowFw(self):
> self.textEdit_fwcmdlineoutput.setText( sys.stdout.getvalue() )
>
So this fails if setupUi has not been called earlier because the attribute
has not been initialised yet.
self.textEdit_fwcmdlineoutput.setText( sys.stdout.getvalue() )
> AttributeError: 'Ui_MainWindow' object has no attribute
> 'textEdit_fwcmdlineoutput'
>
You need to ensure that the UI __init__() method calls self.setupUi()
I suspect.
On Thu, Aug 8, 2013 at 4:57 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:
> On 08/08/13 21:24, SM wrote:
>
> example, I ended up doing exactly what you suggested. I am sure I am
>> missing something, as it is giving the same error:
>> Here is what I am doing based on your suggestion:
>>
>> class bcThread(threading.Thread):
>> def h(self, y):
>> y.setStdoutToTextEditWindowFw(**) #(line 1277)
>>
>
> ...
>
> [snip]
>> x = Ui_MainWindow()
>> self.h(x) # (line 1319)
>>
>
> So far so good.
>
>
> class Ui_MainWindow(object)
>> def setupUi(self, MainWindow):
>> [snip]
>>
>> self.textEdit_fwcmdlineoutput = QtGui.QTextEdit(self.tab_fw)
>>
>
> This only comes into existence after setupUi is called.
> Normally that would be in the UI init() method but you don;t
> show any init or any other call to setupUi
>
> self.textEdit_fwcmdlineoutput.**setObjectName(_fromUtf8("**
>> textEdit_fwcmdlineoutput"))
>>
>
> def setStdoutToTextEditWindowFw(**self):
>> self.textEdit_fwcmdlineoutput.**setText( sys.stdout.getvalue() )
>>
>
> So this fails if setupUi has not been called earlier because the attribute
> has not been initialised yet.
>
>
> self.textEdit_fwcmdlineoutput.**setText( sys.stdout.getvalue() )
>> AttributeError: 'Ui_MainWindow' object has no attribute
>> 'textEdit_fwcmdlineoutput'
>>
>
> You need to ensure that the UI __init__() method calls self.setupUi()
> I suspect.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> ______________________________**_________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130808/ad1591b4/attachment-0001.html>
More information about the Tutor
mailing list