IRC対応のプログラムのバグを突き止めようとしている過去1時間のうちに私の頭が痛くなりました。何らかのデバッグの後に何らかの理由でgetattr正しく動作していません。私は次のテストコードを持っています:getattrの問題
def privmsg(self, user, channel, msg):
#Callback for when the user receives a PRVMSG.
prvmsgText = textFormatter(msg,
self.factory.mainWindowInstance.ui.testWidget.ui.channelBrowser,
QColor(255, 0, 0, 127), 'testFont', 12)
prvmsgText.formattedTextAppend()
すべてが完全に機能します。
以下の代替、およびコードブレーク(出力PyQtはTextBrowserインスタンスにテキストをしません)
def privmsg(self, user, channel, msg):
#Callback for when the user receives a PRVMSG.
prvmsgText = textFormatter(msg,
getattr(self.factory.mainWindowInstance.ui, 'testWidget.ui.channelBrowser'),
QColor(255, 0, 0, 127), 'testFont', 12)
prvmsgText.formattedTextAppend()
はのTextFormatter関数の第2引数は、本質的に同等の書き込みのこれらの二つの方法ではありませんか?なぜこのようなことが起きるのでしょうか、このようなバグに私がどのようにアプローチするかについてのアイディアはありますか?ありがとう。
編集:ここでは(簡単な)のTextFormatterクラスがあり、場合には役立ちます:
from timeStamp import timeStamp
class textFormatter(object):
'''
Formats text for output to the tab widget text browser.
'''
def __init__(self,text,textBrowserInstance,textColor,textFont,textSize):
self.text = text
self.textBrowserInstance = textBrowserInstance
self.textColor = textColor
self.textFont = textFont
self.textSize = textSize
def formattedTextAppend(self):
timestamp = timeStamp()
self.textBrowserInstance.setTextColor(self.textColor)
self.textBrowserInstance.setFontPointSize(self.textSize)
self.textBrowserInstance.append(unicode(timestamp.stamp()) + unicode(self.text))
'self.factory.mainWindowInstance.ui.testWidget.ui.channelBrowser'の男、WTF?これはJavaではありません。 –
@Samus_ PyQTには、ウィジェットのこの階層があります。そのような属性は、そのようなチェーンの中でアクセスする必要があるようです。メインウィンドウ内にUIがあるメインウィンドウインスタンスがあり、そのメインウィンドウ内に独自のUIを持つウィジェットがたくさんあり、そこにオブジェクトがある場合は、特定のオブジェクトを参照する方法が必要です。おそらくそれを行う良い方法がありますが、私はまだPyQTを学んでいるので、おそらく私はそれをまだ見つけていません! – Bitrex