wxPython: wxGrid vs. wxListCtrl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Piet

    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")
    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
  • Andrei

    #2
    Re: wxPython: wxGrid vs. wxListCtrl

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

    <snip>[color=blue]
    > 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.[/color]

    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.
    [color=blue]
    > 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).[/color]

    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):
    cebwrpg5@jnanqb b.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
    gur yvfg, fb gurer'f ab arrq gb PP.

    Comment

    • RichH

      #3
      Re: wxPython: wxGrid vs. wxListCtrl

      In article <1v4erg10g7cds. y7kspsysjyuy.dl g@40tude.net>, project5
      @redrival.net says...[color=blue]
      > 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).
      >
      >[/color]

      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


      Comment

      • Roger Binns

        #4
        Re: wxPython: wxGrid vs. wxListCtrl

        RichH wrote:[color=blue]
        > 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.[/color]

        When you send the wxGRIDTABLE_REQ UEST_VIEW_GET_V ALUES 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


        Comment

        • RichH

          #5
          Re: wxPython: wxGrid vs. wxListCtrl

          In article <f4dkr1-edd.ln1@home.ro gerbinns.com>, rogerb@rogerbin ns.com
          says...[color=blue]
          > RichH wrote:[color=green]
          > > 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.[/color]
          >
          > When you send the wxGRIDTABLE_REQ UEST_VIEW_GET_V ALUES 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
          >
          >[/color]

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

          Cheers,
          Rich


          Comment

          Working...