2017-10-18 14 views
0

我有一個遠程節點,它保存60個不同寄存器中的值。我需要用點擊按鈕來填充一個網格。我一次只能得到一個值。這工作,但它很混亂。每次我收到另一個值添加到列表中,我得到此錯誤:「gridArray = np.array(table).reshape(15,4) ValueError:無法重新設置大小數組(列表中的值的數量) (15,4)wxPython;從遠程節點發送的值填充網格一次一個值

def onGetValues(self, event): 
    self.grid.ClearGrid() 
    for i in range(129,189): #number of registers will never change 
     #send me the data in each of these registers 

#Then I build a list as the values are received: 

def buildList(self, val): 
    global myList 
    myList.append(val)  # this gives me a list with one value, then two values, etc 
    self.makeArray() # go to the next step 

#Then I turn the final list into an array: 

def makeArray(self): 
    global myList, gridArray 
    gridArray = np.array(myList).reshape(15,4) # grid will never be bigger 

#Then use the array to populate the grid: 

def popGrid(self): 
    global gridArray 
    for row in gridArray: 
     row_num = row[0] 
     cells = row[0:4] 
     for i in range(len(cells)): 
      if cells [i] != None and cells[i] != "null": 
       self.grid.SetCellValue(row_num-1, i, str(cells[i])) 

是否有更好的方法來做到這一點?我可以填充從最後一個列表我使電網並跳過陣列一起?這能凝聚成一個功能?

回答

0

由於列表的長度將始終爲60:

def buildList(self, val): 
    global myList 
    myList.append(val) 
    if len(myList) == 60: 
     self.makeArray()