[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: namespace problems in pyqt
From:       Phil Thompson <phil () river-bank ! demon ! co ! uk>
Date:       2003-03-30 1:06:35
[Download RAW message or body]

On Sunday 30 March 2003 12:29 am, Tom Chance wrote:
> Hullo,
>
> I've got a problem that's come about by not wanting to create a new
> class for a dialogue box in PyQt. Previously, I had a class for the
> dialogue which included a function connected to a button in the dialogue. I
> made the class for the dialogue box in Qt Designer, imported that class,
> inherited it in a new class, into which I put the function (so it overrode
> the empty function declaration in the original class), like so:
>
> class Inherited(QDialog):
>         /all the pyqt stuff/
>         connect signal to function2
>
> class Inheritor(Inherited):
>         def function2:
>                 /so some stuff/

This isn't valid Python.

> Now that function isn't in that dialogue's class... it's in the namespace
> that is calling the class instance, e.g.:
>
> def function1(self):
>         /do some stuff.../
>         instance = Inherited()
>
> def function2(self):
>         /do some stuff.../

Are these class methods or functions? Functions don't (to be more accurate, 
shouldn't) have self arguments.

> How can I connect the button in Inherited to function2()? I've been told
> you can connect a Qt signal to a global function, but I can't work out how;
> I've tried declaring "global function2", and I've read through the Qt docs,
> but I cant' figure it out, so I'm obviously just being dumb and missing
> something here. Can someone give me a hand?

It isn't clear which function2() you want to connect to. Either way, simply 
use the name in the call to connect(), ie.

QObject.connect(sender,SIGNAL('sig()'),Inheritor.function2)

...or...

QObject.connect(sender,SIGNAL('sig()'),function2)

See http://www.riverbankcomputing.co.uk/pyqt/docs/x232.html

Phil

-- 
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic