still confused with QTsignal
root
root at localhost.localdomain
Sun Jan 20 10:14:47 EST 2002
> Note that it isn't exactly nice to create functions with names like
> 'print' :-).
>
The print function is only there from sheer desperation :) I just wanted to see
if i could figure out what was going on. I have read and re-read your on line
book and it looks to me like this should work. The 'emitworked' and 'doit'
functions are again only there to get output. This code expects an include
called mixer_element which contains Blackadder generated code for a widget of
the same name. I sub-class this in mixer_sub. The widget contains lots of other
widgets of which only a QPushButton called recButton is relevant. I am trying
to have the function mixer.doit() called when anyof the record buttons are
clicked. I only put in the second connect and 'emitworked' functions to prove
that the signal is being emited.
When I click any of the buttons I get 'spam' and the button number printed but
I cant get it to call 'doit'
from qt import *
from mixer_element import **
class pystudio(main_form):
def __init__(self,parent=None):
main_form.__init__(self)
m=mixer(self)
class mixer:
def __init__(self, parent=None):
self.mixer_sections = []
for section in range(8):
self.mixer_sections.append(mixer_sub(section,parent))
self.mixer_sections[section].setGeometry(72*section,0,100,100)
QObject.connect( self.mixer_sections[section],
PYSIGNAL("rec_button_clicked"),
self.doit
)
QObject.connect( self.mixer_sections[section],
PYSIGNAL("rec_button_clicked"),
self.mixer_sections[section].emitworked
)
def doit(self):
print "self called"
class mixer_sub(mixer_element):
def __init__(self, name, parent=None):
mixer_element.__init__(self, parent)
self.name = name
QObject.connect(self.recButton, SIGNAL( 'clicked()'
),self.wasClicked )
def wasClicked(self):
self.recButton.setPalette( QPalette(QColor(255, 20, 20)) )
self.emit(PYSIGNAL("rec_button_clicked"),())
def emitworked(self):
print "Spam",self.name
a = QApplication(sys.argv)
mainWidget = pystudio()
a.setMainWidget(mainWidget)
mainWidget.show()
a.exec_loop()
More information about the Python-list
mailing list