472,121 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

wxPython: wxGrid vs. wxListCtrl

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_LABE LS )

numberOfAttributes = 0
attributeNameList = []
attributeListCtrl.InsertColumn(0,"Number",format=w xLIST_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(num Rows))
if childs.item(numberOfSiblings).attributes !=
None:
for attribute in
childs.item(numberOfSiblings).attributes.keys():
attr =
childs.item(numberOfSiblings).attributes.get(attri bute)
if attributeNameList.count(attr.nodeName)
== 0:

attributeNameList.append(attr.nodeName)

attributeListCtrl.SetStringItem(numRows,attributeN ameList.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
Jul 18 '05 #1
4 5270
Piet wrote on 29 Jun 2004 12:16:11 -0700:

<snip>
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):
ce******@jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
Jul 18 '05 #2
In article <1v****************************@40tude.net>, project5
@redrival.net says...
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
Jul 18 '05 #3
RichH wrote:
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
Jul 18 '05 #4
In article <f4************@home.rogerbinns.com>, ro****@rogerbinns.com
says...
RichH wrote:
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


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

Cheers,
Rich
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by chauhan | last post: by
1 post views Thread by Mark Carter | last post: by
5 posts views Thread by Andrew | last post: by
3 posts views Thread by Piet | last post: by
1 post views Thread by matthiasjanes | last post: by
1 post views Thread by James | last post: by
6 posts views Thread by rbann11 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.