View Single Post
mikec's Avatar
Posts: 1,366 | Thanked: 1,185 times | Joined on Jan 2006
#13
Originally Posted by attila77 View Post
Great stuff ! Two notes, though (not as discouragement, just as advices):

Avoid things like MainWindow.ledArray[r].append(QtGui.QPushButton())

The problem is that Python handles Qt object lifetimes/references differently than C++ and this (calling a constructor as a parameter for another function) can cause all sorts of nastiness if you're not careful. I know it's uglier to allocate a local variable for this, but you'll understand when you meet the first segfaults

The other note is python style - when dealing arrays it's recommended to use the 'in' operator. Faster, IMHO prettier and less error-prone than index based stuff. So, something like:

Code:
# c-ish
for r in range(8): 
            for c in range(16):
                self.ledArray[r][c].setChecked(self.ledState)

# pythonic
for row in self.ledArray: 
            for led in row:
                led.setChecked(self.ledState)
See ?

The Pythonic way rocks, so much easier when you know how
__________________
N900_Email_Options Wiki Page