Hi to all !!!

I'm new here and a newbie at the same time, so please don't be harsh...

I use Python with PyQt4 to develop a program reading a file with numbers and displaying them in a QTableWidget. So far so good.

What I have not accomplished yet, is to select certain columns from the QTableWidget and display them in another table. I would also like to store the selected tables' indexes in a global list.

My main.py file, the one that materializes the GUI and uses the derivative file from pyuic4 looks something like this:

Qt Code:
  1. from PyQt4 import QtGui, QtCore
  2. from tstMain import Ui_tstMain
  3.  
  4. import sys, string
  5. from os.path import isfile
  6. from os import chdir
  7.  
  8. import variousFuncs
  9.  
  10.  
  11. ## Create a dictionary of updateable variables. These will be updated by the various
  12. ## functions of Class startGui
  13. updVars = {"InitialFile": [], "SelectedColumns": []}
  14.  
  15. class startGui(QtGui.QMainWindow):
  16. def __init__(self, parent = None):
  17. QtGui.QWidget.__init__(self, parent)
  18. self.ui = Ui_tstMain()
  19. self.ui.setupUi(self)
  20.  
  21. ## create our slots here
  22. QtCore.QObject.connect(self.ui.btn_SetWorkingDir, QtCore.SIGNAL("clicked()"), self.setWorkingDir)
  23. QtCore.QObject.connect(self.ui.btn_OpenFile, QtCore.SIGNAL("clicked()"), self.openFile)
  24. QtCore.QObject.connect(self.ui.btn_ListShow, QtCore.SIGNAL("clicked()"), self.showList)
  25.  
  26. def setWorkingDir(self):
  27. wd = QtGui.QFileDialog(self)
  28. currentDir = QtCore.QString(wd.getExistingDirectory())
  29. self.ui.lnEdt_WorkingDir.setText(currentDir)
  30. chdir(currentDir)
  31.  
  32. def openFile(self):
  33. fd = QtGui.QFileDialog(self)
  34. self.file = fd.getOpenFileName()
  35.  
  36. if isfile(self.file):
  37. fileToOpen = open(self.file)
  38. initialFile = [line.split() for line in fileToOpen.readlines()]
  39. variousFuncs.dbl_str2num(initialFile)
  40.  
  41. updVars["InitialFile"] = initialFile
  42. variousFuncs.tablePainter(initialFile, self.ui.tbl_OpenFile)
  43.  
  44. updVars["SelectedColumns"] = self.ui.tbl_OpenFile.selectedItems()
  45.  
  46. def showList(self):
  47. tempSelected = updVars["SelectedColumns"]
  48. variousFuncs.tablePainter(tempSelected, self.ui.tbl_ListShow)
To copy to clipboard, switch view to plain text mode 

while the variousFuncs file which contains various functions, looks something like this:

Qt Code:
  1. #!/usr/bin/python
  2.  
  3. import string, random, math
  4. from PyQt4 import QtGui, QtCore
  5.  
  6. ##
  7. def dbl_str2num(lst):
  8. """ This function transforms the items of the list "lst" from strings to numbers.
  9. The list must be a nested list. """
  10. for i in range(len(lst)):
  11. for j in range(len(lst[0])):
  12. lst[i][j] = eval(lst[i][j])
  13.  
  14. def tablePainter(someTwoDimLst, someTbl):
  15. """ This function creates a QTableWidgetItem out of a 2-dimension nested list which contains numbers,
  16. and then uses it to "paint" the someTbl object, which is a QTableWidget """
  17. someTbl.setColumnCount(len(someTwoDimLst[0]))
  18. someTbl.setRowCount(len(someTwoDimLst))
  19.  
  20. for i in range(len(someTwoDimLst)):
  21. for j in range(len(someTwoDimLst[0])):
  22. itemListShow = QtGui.QTableWidgetItem(QtCore.QString.number(someTwoDimLst[i][j]), QtGui.QTableWidgetItem.Type)
  23. someTbl.setItem(i, j, itemListShow)
To copy to clipboard, switch view to plain text mode 

currently, when I select certain columns from the tbl_OpenFile QTableWidget and try to display them in the tbl_ListShow one, the whole thing ends up with the error:
Qt Code:
  1. Traceback (most recent call last):
  2. File "D:\Tutorial\main.py", line 52, in showList
  3. itemListShow = QtGui.QTableWidgetItem(QtCore.QString.number(tempSelected[0][0]))
  4. IndexError: list index out of range
To copy to clipboard, switch view to plain text mode 

which IMHO means that the line

Qt Code:
  1. updVars["SelectedColumns"] = self.ui.tbl_OpenFile.selectedItems()
To copy to clipboard, switch view to plain text mode 
returned nothing in the list (???)

Any help would be much appreciated.
Thank you all in advance,

Thomas