wxPython: wxGrid vs. wxListCtrl

P

Piet

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
 
A

Andrei

Piet wrote on 29 Jun 2004 12:16:11 -0700:

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.

Have you looked at the Huge grid table example in the demo, the one with
the 100 million cells? It demonstrates how to use a table for the grid.
I've made an app inspired by that example which loads stuff on demand from
a bsddb and stores changed items immediatly back to the db - seems quite
similar to what you intend to do.
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).

The Grid table is basically sitting in between the grid that the user sees
and whatever storage backend you have. The grid asks the table for data to
be inserted in cell at some coordinates, the table does whatever it deems
necessary and answers. Even better, the grid asks the table about what
attributes each displayed cell should have (color, read-only, custom
editor, the whole lot).

--
Yours,

Andrei

=====
Real contact info (decode with rot13):
(e-mail address removed). Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
 
R

RichH

project5 said:
Piet wrote on 29 Jun 2004 12:16:11 -0700:


The Grid table is basically sitting in between the grid that the user sees
and whatever storage backend you have. The grid asks the table for data to
be inserted in cell at some coordinates, the table does whatever it deems
necessary and answers. Even better, the grid asks the table about what
attributes each displayed cell should have (color, read-only, custom
editor, the whole lot).

I've built a grid in this way and it was slow as I was changing the
data in the table continuously. Is there any way to tell the grid
that just a few cells have changed? My program was redrawing the
whole grid (the visible portion of the grid) each time I changed
any cell.

Cheers,
Rich
 
R

Roger Binns

RichH said:
I've built a grid in this way and it was slow as I was changing the
data in the table continuously. Is there any way to tell the grid
that just a few cells have changed? My program was redrawing the
whole grid (the visible portion of the grid) each time I changed
any cell.

When you send the wxGRIDTABLE_REQUEST_VIEW_GET_VALUES message the
grid will end up requesting all visible values. I couldn't
see any way of doing just a subset of the values.

There are some ways of mitigating this. The simplest would
be to add an idle handler and have it check if the message
should be sent. That way you can continuously update the
table values, but send far fewer messages about the updates.

I would also recommend you post your query on the wxPython-users
mailing list as Robin and many other people respond there
way quicker and in more detail than this group.

I would also recommend you have a sample program illustrating
what you are trying to do and how you have coded it. Robin
usually requests one, and it helps other people to see what
you are seeing.

Roger
 
R

RichH

When you send the wxGRIDTABLE_REQUEST_VIEW_GET_VALUES message the
grid will end up requesting all visible values. I couldn't
see any way of doing just a subset of the values.

There are some ways of mitigating this. The simplest would
be to add an idle handler and have it check if the message
should be sent. That way you can continuously update the
table values, but send far fewer messages about the updates.

I would also recommend you post your query on the wxPython-users
mailing list as Robin and many other people respond there
way quicker and in more detail than this group.

I would also recommend you have a sample program illustrating
what you are trying to do and how you have coded it. Robin
usually requests one, and it helps other people to see what
you are seeing.

Roger

Thanks for your response... I read the source and asked a
question last year on wxPython-users. Got a similar answer.

Cheers,
Rich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top