wxPython: wxGrid vs. wxListCtrl

Piet pit.grinja at gmx.de
Tue Jun 29 21:16:11 CEST 2004

I am working on an XML editor that will not display the xml file as
plain text, but will rather work with a combination of a tree view for
the main element nodes and some kind of tabular view to view
attributes. By this way, the user (i.e. me) will only have the
opportunity to change textual contents and attribute values, but
neither element nor attribute names.
Building the tree view was not a problem, but I haven´t found a good
widget for the "grid view" component. wxGrid allows to edit the
content of the table (which will be the attribute values) but I
haven´t found a way to link a specific cell to a certain xml node.
This is important, because when the cell content changes I would like
to be able to directly communicate this change to the underlying xml
tree (in the tree component of the editor, this is already achieved).
wxListCtrl would be the second choice. THis where I first focused on
an wrote the following code:
class ListCtrlWindow(wxFrame):
    def __init__(self, parent, node):
        wxFrame.__init__(self, parent, -1,"Attribute list")
        attributeListCtrl = wxListCtrl(self,-1,style =

        numberOfAttributes = 0
        attributeNameList = []
        for attribute in node.attributes.keys():
            attr = node.attributes.get(attribute)
            print attr.nodeName + "\n"
        for entry in attributeNameList:
            print entry + " " + str(attributeNameList.index(entry)) +
        numberOfSiblings = 0
        if node.parentNode != None:
            childs = node.parentNode.childNodes
            numRows = 0
            for numberOfSiblings in range(len(childs)):
                print childs.item(numberOfSiblings).nodeType
                if childs.item(numberOfSiblings).nodeType == 1:
                    if childs.item(numberOfSiblings).attributes !=
                        for attribute in
                            attr =
                            if attributeNameList.count(attr.nodeName)
== 0:
                    numRows = numRows + 1

But there I have two problems/questions: First, a very general one: I
would like to edit the contents of the table, but when I double click
on the respective line, only the first element is editable.
Second, I have not yet completely understood the "data structure"
behind a list item. Does each line of a listctrl represent a single
item? Is it possible to address the entries in the line in the same
was as "cells" of a "table row"? Can items which are located in
different lines but are positioned in the same "column" be selected
like grid cells which belong to one column?
To me it looks a little as if listctrl was mainly for displaying data
and not for editing. So do I have to use a wxGrid for the attribute
list and define my own mechanism to connect a cell to a data object?
Any hints are appreciated.

More information about the Python-list mailing list