wxPython: wxGrid vs. wxListCtrl

From: Piet (pit.grinja_at_gmx.de)
Date: 06/29/04


Date: 29 Jun 2004 12:16:11 -0700

Hello.
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 =
wxLC_REPORT|wxLC_VRULES|wxLC_HRULES|wxLC_EDIT_LABELS )

        numberOfAttributes = 0
        attributeNameList = []
        attributeListCtrl.InsertColumn(0,"Number",format=wxLIST_FORMAT_LEFT,
width=-1)
        for attribute in node.attributes.keys():
            attr = node.attributes.get(attribute)
            print attr.nodeName + "\n"
            attributeListCtrl.InsertColumn(numberOfAttributes+2,attr.nodeName,format=wxLIST_FORMAT_LEFT,
width=-1)
            +numberOfAttributes
            attributeNameList.append(attr.nodeName)
        for entry in attributeNameList:
            print entry + " " + str(attributeNameList.index(entry)) +
"\n"
        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:
                    attributeListCtrl.InsertStringItem(numRows,str(numRows))
                    if childs.item(numberOfSiblings).attributes !=
None:
                        for attribute in
childs.item(numberOfSiblings).attributes.keys():
                            attr =
childs.item(numberOfSiblings).attributes.get(attribute)
                            if attributeNameList.count(attr.nodeName)
== 0:
                               
attributeNameList.append(attr.nodeName)
                           
attributeListCtrl.SetStringItem(numRows,attributeNameList.index(attr.nodeName)+1,attr.nodeValue)
                    numRows = numRows + 1

        attributeListCtrl.EnsureVisible(True)
        attributeListCtrl.SetColumnWidth(-1,-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.
Regards
Peter



Relevant Pages

  • Re: TreeView Dynamic XML Binding
    ... Subject: TreeView Dynamic XML Binding ... Expand the ReturnHeader node. ... When I click on the tree node for the select ... I'm simply trying to display the xml element tree ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: TreeView Dynamic XML Binding
    ... Subject: TreeView Dynamic XML Binding ... Expand the ReturnHeader node. ... When I click on the tree node for the select ... I'm simply trying to display the xml element tree ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • RE: How to show Selected treeview nodes attribute,values in listbox t
    ... In AfterSelect and with SelectedNode you can decide ... display something in another control and so on ... ... I have to create a project in C# in which i have to create a XML Tree View, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: TreeCellRenderer.setIcon(null) -> performance loss
    ... don't let the model give it to the tree. ... > don't want to display them? ... Xml DOM commands that would return the information required by the ... displayed in the JTree. ...
    (comp.lang.java.gui)
  • Re: OT? evolution explains what?
    ... > tree ring info but I'm wondering if there is anything more you can add ... > original starting cell, right? ... Best evidence at the moment is that it was RNA, ... sequence 18S rna genes, common to all living things (apart from viruses, ...
    (uk.philosophy.atheism)