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")
attributeListCt rl = wxListCtrl(self ,-1,style =
wxLC_REPORT|wxL C_VRULES|wxLC_H RULES|wxLC_EDIT _LABELS )
numberOfAttribu tes = 0
attributeNameLi st = []
attributeListCt rl.InsertColumn (0,"Number",for mat=wxLIST_FORM AT_LEFT,
width=-1)
for attribute in node.attributes .keys():
attr = node.attributes .get(attribute)
print attr.nodeName + "\n"
attributeListCt rl.InsertColumn (numberOfAttrib utes+2,attr.nod eName,format=wx LIST_FORMAT_LEF T,
width=-1)
+numberOfAttrib utes
attributeNameLi st.append(attr. nodeName)
for entry in attributeNameLi st:
print entry + " " + str(attributeNa meList.index(en try)) +
"\n"
numberOfSibling s = 0
if node.parentNode != None:
childs = node.parentNode .childNodes
numRows = 0
for numberOfSibling s in range(len(child s)):
print childs.item(num berOfSiblings). nodeType
if childs.item(num berOfSiblings). nodeType == 1:
attributeListCt rl.InsertString Item(numRows,st r(numRows))
if childs.item(num berOfSiblings). attributes !=
None:
for attribute in
childs.item(num berOfSiblings). attributes.keys ():
attr =
childs.item(num berOfSiblings). attributes.get( attribute)
if attributeNameLi st.count(attr.n odeName)
== 0:
attributeNameLi st.append(attr. nodeName)
attributeListCt rl.SetStringIte m(numRows,attri buteNameList.in dex(attr.nodeNa me)+1,attr.node Value)
numRows = numRows + 1
attributeListCt rl.EnsureVisibl e(True)
attributeListCt rl.SetColumnWid th(-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
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")
attributeListCt rl = wxListCtrl(self ,-1,style =
wxLC_REPORT|wxL C_VRULES|wxLC_H RULES|wxLC_EDIT _LABELS )
numberOfAttribu tes = 0
attributeNameLi st = []
attributeListCt rl.InsertColumn (0,"Number",for mat=wxLIST_FORM AT_LEFT,
width=-1)
for attribute in node.attributes .keys():
attr = node.attributes .get(attribute)
print attr.nodeName + "\n"
attributeListCt rl.InsertColumn (numberOfAttrib utes+2,attr.nod eName,format=wx LIST_FORMAT_LEF T,
width=-1)
+numberOfAttrib utes
attributeNameLi st.append(attr. nodeName)
for entry in attributeNameLi st:
print entry + " " + str(attributeNa meList.index(en try)) +
"\n"
numberOfSibling s = 0
if node.parentNode != None:
childs = node.parentNode .childNodes
numRows = 0
for numberOfSibling s in range(len(child s)):
print childs.item(num berOfSiblings). nodeType
if childs.item(num berOfSiblings). nodeType == 1:
attributeListCt rl.InsertString Item(numRows,st r(numRows))
if childs.item(num berOfSiblings). attributes !=
None:
for attribute in
childs.item(num berOfSiblings). attributes.keys ():
attr =
childs.item(num berOfSiblings). attributes.get( attribute)
if attributeNameLi st.count(attr.n odeName)
== 0:
attributeNameLi st.append(attr. nodeName)
attributeListCt rl.SetStringIte m(numRows,attri buteNameList.in dex(attr.nodeNa me)+1,attr.node Value)
numRows = numRows + 1
attributeListCt rl.EnsureVisibl e(True)
attributeListCt rl.SetColumnWid th(-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
Comment