View Single Post
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#9
Originally Posted by mikec View Post
ok just to close close this thread off.

Could not get Eval() to work but Exec() worked well , but I decided to rewrite the app using an array of buttons populated from within the application. This was non trivial cause of python arrays peculiarities but here is the code snippet for future ref.

This creates an 8x16 array of buttons in an array declared inside the Qt MainWindow Class (this avoids the use of globals, don't even go three )

Code:
#Here is the MainWindow Class with an array called ledArray declared.
class MainWindow(QMainWindow, Ui_MainWindow):
    ledArray=[]
    def __init__(self, parent = None):
          QMainWindow.__init__(self, parent)
           self.setupUi(self)
Here is the initialization routine to create the array of buttons in the Main.py and inserts them into the UI created by Qt Designer, where I had placed a grid layout in the main window to accept my buttons, all pre-styled to look nice.

Code:
def initled():        
        for r in range(8): 
            MainWindow.ledArray.append([])
            for c in range(16):
                    MainWindow.ledArray[r].append(QtGui.QPushButton())
                    MainWindow.ledArray[r][c].setCheckable(True) 
                    MainWindow.ledArray[r][c].setMinimumSize(QtCore.QSize(45, 45)) 
                    ui.gridLayout.addWidget(MainWindow.ledArray[r][c], r, c)
And I can change all attributes at once now with loop.

Code:
for r in range(8): 
            for c in range(16):
                self.ledArray[r][c].setChecked(self.ledState)
and here is the result



Mike C
that rocks!!!!!
__________________
----------- 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: