Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am trying to send some data from a gui i am working on to python. what i want to do ist write a row (gui) to a list (python) or something similar... (directly to a numpy array would be the best)...

my gui has a table widget i created in the QtDesigner i have a python program building this gui:

from PyQt4 import QtGui, QtCore  
from Main_window import Ui_Dialog as Dlg

class MyDia(QtGui.QDialog, Dlg): 
    def __init__(self): 
        QtGui.QDialog.__init__(self) 
        self.setupUi(self)
...
        self.tableWidget.cellChanged.connect(self.cellchanged) #connects a signal when
        #value in cell should be updated
    def cellchanged(self):
        col=self.tableWidget.currentColumn()
        row=self.tableWidget.currentRow()        
        text = self.tableWidget.currentItem().text()
        list=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        list[col]=text
...

this is my idea - i want the list (or array) to be updated/changed when the user has has changed the entry of a cell. I have only one row so it does not have to be a 2D array.

I need this cause i am sending an array to my actual calculation program where "list" is an input:

...    exec(open("./calculation.py").read())

or

...    from calculator import calc
       calc(list)

i hope someone can help me with this...

share|improve this question
    
If you installed spyder, you can use spyderlib.widgets.arrayeditor to do this. –  HYRY Dec 7 '13 at 23:03
    
What is your actual question? I understand what you are trying to do, but don't understand what specific problem you are asking for help with... –  three_pineapples Dec 8 '13 at 3:11

1 Answer 1

up vote 0 down vote accepted

After trying to use a "numpy" array i succeded- i changed the "cellchanged" section and defined a button the user has to click after he has input all the cells

"tableWidget" is the object name defined in QtDesigner or the "..." section import numpy as np from PyQt4 import QtGui, QtCore
from Main_window import Ui_Dialog as Dlg

class MyDia(QtGui.QDialog, Dlg): 
    def __init__(self): 
        QtGui.QDialog.__init__(self)
... 
        self.setupUi(self)
self.connect(self.buttonOK, 
                QtCore.SIGNAL("clicked()"), self.onOK)# the button signal
    def onOK(self):#event when user clicks
        list=np.zeros((1,16))
        for i in range(0,16,1):               
               list[0,i]= float(self.tableWidget.item(0,i).text())
               #reads in the first row the User has input before

thanks anyway guys!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.