Creating a data source to populate a datagrid.

Discussion about using Python with libRocket.

Creating a data source to populate a datagrid.

Postby montawk on Thu Feb 16, 2012 1:25 pm

I've created a class that inherits from DataSource and created an instance of it, but how do I tell the program that the datasource exists? I tried to follow the tutorial page for as best I could. If it matters, I'm using Panda3D's integration of libRocket. The error I get is: :rocket(error) Bad data source name high_scores.scores, which means that the DataSourceListener couldn't find a data source with the name 'high_scores'. How do I tell the program / DataSourceListener that I've created a DataSource?
Code: Select all
class HighScoreDataSource(DataSource):

   def __init__(self, name):
      DataSource.__init__(self, 'high_scores')

   def GetRow(self, row, tableName, rowIndex, columns):
      if(tableName == 'scores'):

         for col in columns:

            if(col == 'name'):
               row.append('TestName')

            elif(col == 'score'):
               row.append('5')

            elif(col == 'color'):
               row.append('#F00')

            elif(col == 'wave'):
               row.append('testWave')

   def GetNumRows(self, tableName):
      if(tableName == 'scores'):
         return 1

      return 0

Code: Select all
      <script>
import panda3d.rocket as rocket

def OnLoad(window):
   dataSource = HighScoreDataSource()

   datagrid = window.GetElementById('datagrid')
   datagrid.AddEventListener('rowupdate', OnRowAdd, False)
   datagrid.SetDataSource('high_scores.scores')
      </script>

   </head>
   <body template="pywindow" onload="OnLoad(self)" onunload="">
      <datagrid id="datagrid">
         <col fields="name,name_required" formatter="name" width="40%">Pilot:</col>
         <col fields="color" formatter="ship" width="20%">Ship:</col>
         <col fields="wave" width="20%">Wave:</col>
         <col fields="score" width="20%">Score:</col>
      </datagrid>
montawk
 
Posts: 1
Joined: Thu Feb 16, 2012 1:13 pm

Re: Creating a data source to populate a datagrid.

Postby lloydw on Fri Mar 02, 2012 11:51 pm

That code looks correct.

As long as your data source exists, that should be all thats required. Try put a log message inside the C++ DataSource's constructor and it's getting called?
lloydw
Rocket Engineer
Rocket Engineer
 
Posts: 380
Joined: Tue Jan 15, 2008 10:56 pm


Return to libRocket and Python


cron