wxgrid append question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eric dexter
    New Member
    • Sep 2006
    • 46

    #1

    wxgrid append question

    I seem to be creating an extra line on my grid that doesn't exist and doesn't save back to the file.

    The error I get is

    self.rows[row][col] = self.GetCellVal ue(row -1, col)
    IndexError: list index out of range

    This is the part of the code that generates the error

    Code:
    def OnCellChange(self, evt):
            row = self.GetGridCursorRow()
            col = self.GetGridCursorCol()
            try:
              self.rows[row][col] = self.GetCellValue(row, col)  
            except:
              self.rows.append  
              self.rows[row][col] = self.GetCellValue(row -1, col)
    This is the part of the code that adds an extra line to the grid (on screen only apartently)

    Code:
    def addline(self):
            "add line to the grid"
            self.AppendRows(1) 
            self.rows.append(row[1])
    The rest of the (older code) is here in the csound routines module if it is helpfull (probily not needed)


    Dex Tracker

    THis is python 2.4 with wxpython 2.6
    Last edited by eric dexter; Nov 14 '06, 07:00 PM. Reason: more info
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    You've got to keep everything lined up. so


    self.rows[row][col] = self.GetCellVal ue(row -1, col)
    IndexError: list index out of range

    subtracting 1 from row in GetCellValue() probably throws things off for self.rows indexing.

    Comment

    • eric dexter
      New Member
      • Sep 2006
      • 46

      #3
      It was giving me that error befour I changed it by trying to take the previous item from the grid. I even tried some of the stuff from the wxwiki and couldn't get it to work.. I think it is the other side of it causing me trouble (but I could be wrong) self.rows[row][col] I supose I could subtract 1 from both sides of it to see if I still get the error.
      Last edited by eric dexter; Nov 14 '06, 10:56 PM. Reason: revise and extend my remarks

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by eric dexter
        I seem to be creating an extra line on my grid that doesn't exist and doesn't save back to the file.

        The error I get is

        self.rows[row][col] = self.GetCellVal ue(row -1, col)
        IndexError: list index out of range

        This is the part of the code that generates the error

        Code:
        def OnCellChange(self, evt):
        row = self.GetGridCursorRow()
        col = self.GetGridCursorCol()
        try:
        self.rows[row][col] = self.GetCellValue(row, col) 
        except:
        self.rows.append 
        self.rows[row][col] = self.GetCellValue(row -1, col)
        This is the part of the code that adds an extra line to the grid (on screen only apartently)

        Code:
         
        def addline(self):
        "add line to the grid"
        self.AppendRows(1) 
        self.rows.append(row[1])
        The rest of the (older code) is here in the csound routines module if it is helpfull (probily not needed)


        Dex Tracker

        THis is python 2.4 with wxpython 2.6
        Code:
         self.rows.append 
        self.rows[row][col] = self.GetCellValue(row -1, col)
        should be

        Code:
         self.rows.append(['' for a in range(nCols)])
        where nCols is the number of columns, this appends a list of empty strings.

        also,
        Code:
         
        except:
        should be

        Code:
         
        except IndexError:
        When you use except without specifying which error you have "over wrapped" the block and risk missing important errors of other types.

        Comment

        • eric dexter
          New Member
          • Sep 2006
          • 46

          #5
          That does work better...

          self.rows.appen d(['1' for a in range(row + 1)])

          I am playing around with this for debug purposes
          I believe that '' may not be the same as ' ' (with the space). when I was
          playing around I was getting charecters that graphed that I could not see
          so there may be some sort of null value. when I replaced it with 1 it went out
          to arb way to the side so that is probily not the answer except to look at behavior. I will try space next, I have training stuff to do so I will look at that more in the daytime tommorow it does apear that I get a 1 in the first spot (where it triggers the command) written over what I have typed. thanks for the command I'll let you know tommorow if I have the complete answer to it..

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by eric dexter
            That does work better...

            self.rows.appen d(['1' for a in range(row + 1)])

            I am playing around with this for debug purposes
            I believe that '' may not be the same as ' ' (with the space). when I was
            playing around I was getting charecters that graphed that I could not see
            so there may be some sort of null value. when I replaced it with 1 it went out
            to arb way to the side so that is probily not the answer except to look at behavior. I will try space next, I have training stuff to do so I will look at that more in the daytime tommorow it does apear that I get a 1 in the first spot (where it triggers the command) written over what I have typed. thanks for the command I'll let you know tommorow if I have the complete answer to it..
            I wouldn't use row + 1 in the list comprehension. You should have a variable for the number of colunms in each row. USE THAT or you will be appending weird length lists to your self.rows list.

            Comment

            • bartonc
              Recognized Expert Expert
              • Sep 2006
              • 6478

              #7
              How 'bout this idea:
              Don't update (or keep for that matter) self.rows.
              instead
              1) read the file the way that you do now
              2) create the grid as you do now

              3) when it's time to save the grid, create a new list of all the rows in the grid and write that.
              ?
              Also, do you have Robin Dunn's book? There is a "table" object for use with grids. It adds a data oriented view to your grid (which is considered to be the control view).

              Comment

              • eric dexter
                New Member
                • Sep 2006
                • 46

                #8
                I bought a couple of books but I ran out of jobs. No work no books but I will put it on my reading list maybe they have it at the college

                Comment

                • bartonc
                  Recognized Expert Expert
                  • Sep 2006
                  • 6478

                  #9
                  Originally posted by eric dexter
                  I bought a couple of books but I ran out of jobs. No work no books but I will put it on my reading list maybe they have it at the college
                  Yes. This is a highly recommended reference. Also, it's how Mr. Dunn supports the work he is doing on wxPython. (and it's not very expensive)

                  Comment

                  • eric dexter
                    New Member
                    • Sep 2006
                    • 46

                    #10
                    I made a small change to the variable and that nailed it.. thanks for the help. wxgrid has been pretty tricky

                    Comment

                    • bartonc
                      Recognized Expert Expert
                      • Sep 2006
                      • 6478

                      #11
                      Originally posted by eric dexter
                      I made a small change to the variable and that nailed it.. thanks for the help. wxgrid has been pretty tricky
                      You are quite welcome. I really appreciate you keeping up-to-date on your progress. Thanks for that and keep posting,
                      Barton

                      Comment

                      Working...