creating a listbox with PyQt from XML

kenshin770

New Member
I'm not sure if this is a Python XML thing or a PyQt thing, but I am trying to build a GUI for navigating through a large XML database on a Mac running OS 10.7, Python 3.3, PyQt 4. I want to get a list of the text in all of the nodes called "Orth" and put them into a QListWidget called "hLexNav". To do this, I wrote the following bit of code (this isn't the whole thing, just the parts that are supposed to add items to the listbox):\[code\]import sysfrom PyQt4 import QtCore, QtGuifrom xml.dom import minidomimport xml.etree.ElementTree as etreefrom fieldbookGui import Ui_Fieldbookimport imagesimport btnCmdsclass MyForm(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Fieldbook() self.ui.setupUi(self) xmltree = etree.parse('BabyDb.xml') root = xmltree.getroot() for child in root: self.ui.hLexNav.addItem(child.findtext('Orth'))\[/code\]The results of this are a listbox that shows a few correctly-added items interspersed with blank lines. It looks to me as if the items that do appear are in the correct line of the listbox (item 1 shows up and is in the first line, item 19 shows up and is in line 19, etc.), but most lines are blank and the content of most of the nodes is ignored.If I modify the code to output the results of the iterative findtext() to a list, the list seems fine to me. Here's the output for the first 25 items in the list created by\[code\]for child in root: navList.append(child.findtext('Orth'))print(navList[0:25])\[/code\]['a:', 'a:ch
 
Back
Top