libRocket: DataGrid and DataSource issue

Hello everyone, I’m haven’t any clue why my code doesn’t works.

Part 1:

from panda3d.rocket import DataSource
import traceback

class QuestsDS(DataSource):
    def __init__(self, name):
        DataSource.__init__(self, name)
    
    
    def GetNumRows(table):
        print('test')
        try:
            if table == 'list':
                return 1
        except:
            traceback.print_exc()
            return 0
    
    
    def GetRow(row, table, row_index, colums):
        row.append('Das ist ein Test')

instanciated like this:

quests_ds = QuestsDS('quests')

corresponding .rml

<rml>
<head>
        <link type="text/css" href="quests.rcss"/>
        <title>Window</title>
        <style>
                body
                {
                        width: 274px;
                        height: 424px;

                        margin: auto;
                }
        </style>
</head>
<body class="window">
<datagrid source="quests.list">
        <col fields="quests" width="40%">Quests:</col>
</datagrid>
</body>
</rml>

raises this error:

joern@joern-Aspire-V3-571G:~/python/pyrdacor$ sh pyrdacor.sh 
Known pipe types:
  glxGraphicsPipe
(all display modules loaded.)
ATTENTION: default value of option vblank_mode overridden by environment.
ATTENTION: default value of option vblank_mode overridden by environment.
:rocket(warning): Failed to get number of rows from [b]python data source datasource.QuestsDS.[/b]
terminate called after throwing an instance of 'boost::python::error_already_set'
Aborted (core dumped)

Very interesting: as you see the marked passage, libRocket recognizes my DataSource. But it seems to ignore the defined function GetNumRows(table)
I’ve double checked the correct spelling

int HighScores::GetNumRows(const EMP::Core::String& table)

is from the examples of librocket.com

Thanks for your help :slight_smile:

Since it’s a method, shouldn’t the arguments be “self, table”?

Uh, what a stupid mistake - surely occured while translating the examples from c++ which I hardly understand. Reinier, is there an elegant approach to view the python errors? My attempt with traceback does “nothing”. There stands, “core dumped”, is it possible to view this?

I changed the code slightly:

    def GetNumRows(self, table):
        try:
            if table == 'list':
                return 1
        except:
            traceback.print_exc()
            return 0
    
    
    def GetRow(self, row, table, row_index, colums):
        print('test')
        row.append('Das ist ein Test')
:rocket(warning): Failed to get entries for table list row 0 from python data source datasource.QuestsDS.

and the test-printing again isn’t there. Bit annoying don’t to see python errors. Function call now seems correct:

void HighScores::GetRow(EMP::Core::StringList& row, const EMP::Core::String& table, int row_index, const EMP::Core::StringList& columns)

Or isn’t row a normal python list?

I’m not really sure - I have no idea how libRocket wraps this. Might be worth it looking through the boost::python sources in the libRocket source.

Since the crash is happening in C++, there’s no way to get a Python traceback, but you can get a C++ backtrace using “gdb”.

Thanks Reinier, I got the clue. For everyone stumbling about this case:

In C++, there are your arguments:

void HighScores::GetRow(EMP::Core::StringList& row, const EMP::Core::String& table, int row_index, const EMP::Core::StringList& columns)

–> row, table, row_index, columns
and it’s intended to add the columns to the provided row.

In Python, it works like this:

    def GetRow(self, table, row_index, colums):
        row = []
        row.append('Das ist ein Test')
        return row

You have to create the list ‘row’ on your own, append the columns to it and return it.

EDIT: Maybe this should be in the manual? :slight_smile:

Great, I’m glad that you fixed your problem.

I don’t think this material is appropriate for the Panda3D manual, as this question doesn’t directly have anything to do with Panda3D, but with the libRocket library.