Active Topics

 


Reply
Thread Tools
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#21
Originally Posted by fatalsaint View Post
Come on man.. that's exactly what Mine was to show you how to do .
almost! what it didn't explain to my thick head... and what i wasn't prepared for.... The QT Designer dumps classes in the mix, so i think i'm trying to call a general function from within a class.... (Global variables helped me out earlier )

i got a function working 15 mins ago! - and i'm now commenting my work, so once that is done, i'm goi ng to try and split it into more functions
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 
Posts: 3,319 | Thanked: 5,610 times | Joined on Aug 2008 @ Finland
#22
Originally Posted by noobmonkey View Post
[*]Can someone explain simply how i get a button to call a function please? - i understand the "def part" - created a function, but really can't figure out how to simply call it from the button... is there any easy guide?
self.connect(self.myButton, QtCore.SIGNAL("clicked()"), self.clickFoo)

(obviously the exact object names will differ, but you get the idea)
__________________
Blogging about mobile linux - The Penguin Moves!
Maintainer of PyQt (see introduction and docs), AppWatch, QuickBrownFox, etc
 

The Following User Says Thank You to attila77 For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#23
Originally Posted by attila77 View Post
self.connect(self.myButton, QtCore.SIGNAL("clicked()"), self.clickFoo)

(obviously the exact object names will differ, but you get the idea)
meh ok maybe i needed more, as that doesnt explain where the function name is that i am calling..... which is where i am getting confused....

That starts a signal...?!(i think?)
I then need to figure out how to catch that and run a function?! lol

or is that the self.clickFoo part? (if the function is not part of the same class is it just clickFoo? )

(Or is it just me being confuzzled?)
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#24
Originally Posted by noobmonkey View Post
meh ok maybe i needed more, as that doesnt explain where the function name is that i am calling..... which is where i am getting confused....

That starts a signal...?!(i think?)
I then need to figure out how to catch that and run a function?! lol

or is that the self.clickFoo part? (if the function is not part of the same class is it just clickFoo? )

(Or is it just me being confuzzled?)
Yes to the last.. I guess my tutorial wasn't clear enough.. this is exactly what it is demonstrating.

That last part in his signal: self.clickFoo() < the function name is clickFoo().

If you use "self." that means within the same class as you are connecting the signal too. So you'll create def clickFoo: within the QT class for the main window.

If you want to call functions from other places.. you would pass the appropriate object to the function call in the self.clickFoo() part. If it's a global function, just "clickFoo()", etc.
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!
 

The Following 2 Users Say Thank You to fatalsaint For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#25
Originally Posted by fatalsaint View Post
Yes to the last.. I guess my tutorial wasn't clear enough.. this is exactly what it is demonstrating.

That last part in his signal: self.clickFoo() < the function name is clickFoo().

If you use "self." that means within the same class as you are connecting the signal too. So you'll create def clickFoo: within the QT class for the main window.

If you want to call functions from other places.. you would pass the appropriate object to the function call in the self.clickFoo() part. If it's a global function, just "clickFoo()", etc.
Ahaaaaaaaaa!!!!
Superb, will finish my commenting so it is a bit tidier! - then give it a go!
Thank you so much for your help
(Would thank by donating towards your N900 - but no way near payday! hehe)
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 

The Following User Says Thank You to noobmonkey For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#26
ok well tried it....
my class is
class Ui_MainWindow(object):

The error is:
Attribute error: 'UI_MainWindow' object has no attribute 'connect'

Button call in class, sub function, def setupUi(self, MainWindow):
self.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.updateTab1)

Function in Class:
def updateTab1(self, MainWindow):
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#27
Originally Posted by noobmonkey View Post
ok well tried it....
my class is
class Ui_MainWindow(object):

The error is:
Attribute error: 'UI_MainWindow' object has no attribute 'connect'

Button call in class, sub function, def setupUi(self, MainWindow):
self.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.updateTab1)

Function in Class:
def updateTab1(self, MainWindow):
If you do it that way You might need self.ui.btnName.connect....

Do it like I do it in my tutorial
Code:
QtCore.QObject.connect(self.ui.btnAdd, QtCore.SIGNAL('clicked()'), self.doAdd)
ETA: Also self.pushButton I don't think is going to work.. do you have a line similar to:
Code:
self.ui = Ui_MainWindow()
Then you need to use self.ui.pushButton...

Wait - looking at your code - are you using pyuic4 or did you write your own qt interface in the code?
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!

Last edited by fatalsaint; 2010-02-17 at 22:02.
 
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#28
Originally Posted by fatalsaint View Post
If you do it that way You might need self.ui.btnName.connect....

Do it like I do it in my tutorial
Code:
QtCore.QObject.connect(self.ui.btnAdd, QtCore.SIGNAL('clicked()'), self.doAdd)
ETA: Also self.pushButton I don't think is going to work.. do you have a line similar to:
Code:
self.ui = Ui_MainWindow()
Then you need to use self.ui.pushButton...

Wait - looking at your code - are you using pyuic4 or did you write your own qt interface in the code?
Lol woulda helped if i had spelt the button name correctly - missed the _hw part!

And yes finally, your qtcore bit worked!! - well i hope it did.... I picked the one thing to try that wasn't going to change - the GPS location! lol....

Will try the accellerometer stuff now!

P.s. have i told you i love you recently?
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#29
Originally Posted by fatalsaint View Post
If you do it that way You might need self.ui.btnName.connect....

Wait - looking at your code - are you using pyuic4 or did you write your own qt interface in the code?
ickle bit of both
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 
Posts: 3,428 | Thanked: 2,856 times | Joined on Jul 2008
#30
Originally Posted by noobmonkey View Post
ickle bit of both
Ew. Note to noobmonkey: If you use pyuic4 to convert a ui.. don't modify that code directly. That gets ugly and messy and then you can't modify it again with QT Designer.

It's just bad mojo.

Have a separate class in your main .py file that calls the UI class and put everything into that. So much cleaner.. and then you can open/edit/save/convert your UI all day long and never have to change a lick of code.
__________________
If I've helped you or you use any of my packages feel free to help me out.
-----------------------------------------------------------------------------------
Maintaining:
pyRadio - Pandora Radio on your N900, N810 or N800!
 
Reply

Tags
code, health check, n900, python


 
Forum Jump


All times are GMT. The time now is 16:38.