Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    [Maemo 5] HealthCheck - Pymaemo/Qt - Learning to code (N900)

    Reply
    Page 3 of 20 | Prev |   1     2   3   4     5   13 | Next | Last
    noobmonkey | # 21 | 2010-02-17, 20:11 | Report

    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

    Edit | Forward | Quote | Quick Reply | Thanks

     
    attila77 | # 22 | 2010-02-17, 20:13 | Report

    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)

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to attila77 For This Useful Post:
    noobmonkey

     
    noobmonkey | # 23 | 2010-02-17, 20:15 | Report

    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?)

    Edit | Forward | Quote | Quick Reply | Thanks

     
    fatalsaint | # 24 | 2010-02-17, 20:20 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to fatalsaint For This Useful Post:
    attila77, noobmonkey

     
    noobmonkey | # 25 | 2010-02-17, 20:23 | Report

    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)

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to noobmonkey For This Useful Post:
    fatalsaint

     
    noobmonkey | # 26 | 2010-02-17, 21:58 | Report

    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):

    Edit | Forward | Quote | Quick Reply | Thanks

     
    fatalsaint | # 27 | 2010-02-17, 21:59 | Report

    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?

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by fatalsaint; 2010-02-17 at 22:02.

     
    noobmonkey | # 28 | 2010-02-17, 22:05 | Report

    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?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    noobmonkey | # 29 | 2010-02-17, 22:06 | Report

    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

    Edit | Forward | Quote | Quick Reply | Thanks

     
    fatalsaint | # 30 | 2010-02-17, 22:08 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Page 3 of 20 | Prev |   1     2   3   4     5   13 | Next | Last
vBulletin® Version 3.8.8
Normal Logout