Search code examples
pythonwxpython

setting column names in wxPython custom table


I have a custom wxPython table for storing large grid data. I based my implementation on the wiki and on the wxPython demo. In order to make it work, I overwrite several of the GridTableBase methods. I am storing my grid data in a pandas dataframe, so GetColLabel looks like this:

class HugeTable(gridlib.GridTableBase):
....

 def GetColLabelValue(self, col):
    """                                                                                               
    Get col label from dataframe                                                                      
    """                                                                            
    if len(self.dataframe):
        return self.dataframe.columns[col]
    return ''

I have overwritten SetColLabelValue with the following code:

def SetColLabelValue(self, col, value):
    """                                                                                               
    Set col label value in dataframe                                                                  
    """
    if len(self.dataframe):
        col_name = str(self.dataframe.columns[col])
        self.dataframe.rename(columns={col_name: str(value)}, inplace=True)
        return ''
    return ''

This code works to change the column name, but it generates this error:

TypeError: invalid result from HugeTable.SetColLabelValue()

I'm not sure why this error is happening.

I have two questions. 1. How do I find out what kind of return value is expected? 2. How do I prevent this error?

Version note: I am using wxPython Phoenix 4.0.0a1 on OS X.


Solution

  • Docs are here: https://wxpython.org/Phoenix/docs/html/index.html.

    Editing SetColLabel to return None instead of '' fixes this problem.