By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

wxgrid append question

P: 46
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.GetCellValue(row -1, col)
IndexError: list index out of range

This is the part of the code that generates the error

Expand|Select|Wrap|Line Numbers
  1. def OnCellChange(self, evt):
  2.         row = self.GetGridCursorRow()
  3.         col = self.GetGridCursorCol()
  4.         try:
  5.           self.rows[row][col] = self.GetCellValue(row, col)  
  6.         except:
  7.           self.rows.append  
  8.           self.rows[row][col] = self.GetCellValue(row -1, col)  
  9.  
This is the part of the code that adds an extra line to the grid (on screen only apartently)

Expand|Select|Wrap|Line Numbers
  1.  
  2. def addline(self):
  3.         "add line to the grid"
  4.         self.AppendRows(1) 
  5.         self.rows.append(row[1])  
  6.  
  7.  
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
Nov 14 '06 #1
Share this Question
Share on Google+
10 Replies


bartonc
Expert 5K+
P: 6,596
You've got to keep everything lined up. so


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

subtracting 1 from row in GetCellValue() probably throws things off for self.rows indexing.
Nov 14 '06 #2

P: 46
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.
Nov 14 '06 #3

bartonc
Expert 5K+
P: 6,596
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.GetCellValue(row -1, col)
IndexError: list index out of range

This is the part of the code that generates the error

Expand|Select|Wrap|Line Numbers
  1. def OnCellChange(self, evt):
  2. row = self.GetGridCursorRow()
  3. col = self.GetGridCursorCol()
  4. try:
  5. self.rows[row][col] = self.GetCellValue(row, col) 
  6. except:
  7. self.rows.append 
  8. self.rows[row][col] = self.GetCellValue(row -1, col) 
  9.  
This is the part of the code that adds an extra line to the grid (on screen only apartently)

Expand|Select|Wrap|Line Numbers
  1.  
  2. def addline(self):
  3. "add line to the grid"
  4. self.AppendRows(1) 
  5. self.rows.append(row[1]) 
  6.  
  7.  
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
Expand|Select|Wrap|Line Numbers
  1.  self.rows.append 
  2. self.rows[row][col] = self.GetCellValue(row -1, col) 
  3.  
should be

Expand|Select|Wrap|Line Numbers
  1.  self.rows.append(['' for a in range(nCols)])
where nCols is the number of columns, this appends a list of empty strings.

also,
Expand|Select|Wrap|Line Numbers
  1.  
  2. except: 
  3.  
should be

Expand|Select|Wrap|Line Numbers
  1.  
  2. except IndexError: 
  3.  
When you use except without specifying which error you have "over wrapped" the block and risk missing important errors of other types.
Nov 14 '06 #4

P: 46
That does work better...

self.rows.append(['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..
Nov 15 '06 #5

bartonc
Expert 5K+
P: 6,596
That does work better...

self.rows.append(['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.
Nov 15 '06 #6

bartonc
Expert 5K+
P: 6,596
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).
Nov 15 '06 #7

P: 46
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
Nov 19 '06 #8

bartonc
Expert 5K+
P: 6,596
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)
Nov 19 '06 #9

P: 46
I made a small change to the variable and that nailed it.. thanks for the help. wxgrid has been pretty tricky
Nov 21 '06 #10

bartonc
Expert 5K+
P: 6,596
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
Nov 22 '06 #11

Post your reply

Sign in to post your reply or Sign up for a free account.