pyGridTableBase & Mysql Data

Hi everyone,

  First, thanks for all of the help that you give everyday.

  Second, I'm having a big problem with getting updated data from MySQL
into my pyGridTableBase. Here's the code that I have:

#-------------------------BEGIN CODE

import wx
import wx.grid
import getdataall
import getdata1hr
db = getdata1hr.Eb_db()
db2 = getdataall.Eb_db()

class LineupTable(wx.grid.PyGridTableBase):
    def __init__(self):
        wx.grid.PyGridTableBase.__init__(self)

        #---Grid cell attributes

        self.odd = wx.grid.GridCellAttr()
        self.odd.SetBackgroundColour("grey")
        self.odd.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD))

        self.even = wx.grid.GridCellAttr()
        self.even.SetBackgroundColour("white")
        self.even.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD))

    #---Mandatory constructors for grid

    def GetNumberRows(self):
        return len(db.data)

    def GetNumberCols(self):
        return len(db.fields)

    def GetColLabelValue(self, col):
        return db.fields[col][0]

    def IsEmptyCell(self, row, col):
        if db.data[row][col] == "" or db.data[row][col] is None:
            return True
        else:
            return False

    def GetValue(self, row, col):
        value = db.data[row][col]
        if value is not None:
            return value
        else:
            return ''

    def SetValue(self, row, col, value):
        db.data[row][col] = value

    def GetAttr(self, row, col, kind):
        attr = [self.even, self.odd][row % 2]
        attr.IncRef()
        return attr

class LineupTable2(wx.grid.PyGridTableBase):
    def __init__(self):
        wx.grid.PyGridTableBase.__init__(self)

        #---Grid cell attributes

        self.odd = wx.grid.GridCellAttr()
        self.odd.SetBackgroundColour("grey")
        self.odd.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD))

        self.even = wx.grid.GridCellAttr()
        self.even.SetBackgroundColour("white")
        self.even.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD))

    #---Mandatory constructors for grid

    def GetNumberRows(self):
        return len(db2.data)

    def GetNumberCols(self):
        return len(db2.fields)

    def GetColLabelValue(self, col):
        return db2.fields[col][0]

    def IsEmptyCell(self, row, col):
        if db2.data[row][col] == "" or db2.data[row][col] is None:
            return True
        else:
            return False

    def GetValue(self, row, col):
        value = db2.data[row][col]
        if value is not None:
            return value
        else:
            return ''

    def SetValue(self, row, col, value):
        db2.data[row][col] = value

    def GetAttr(self, row, col, kind):
        attr = [self.even, self.odd][row % 2]
        attr.IncRef()
        return attr

    #---Create frame

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, id=-1, title='DJ Sets',
                          size=(900, 300))

        #---Panel

        panel = wx.Panel(self, -1)

        #---Buttons

        self.btn_1hr = wx.Button(panel, -1, "1-Hour Set", pos=(10, 10),
size=wx.DefaultSize)
        self.Bind(wx.EVT_BUTTON, self.OnClick, self.btn_1hr)

        self.btn_2hr = wx.Button(panel, -1, "2-Hour Set", pos=(10, 35),
size=wx.DefaultSize)

        self.btn_3hr = wx.Button(panel, -1, "3-Hour Set", pos=(10, 60),
size=wx.DefaultSize)

        self.btn_4hr = wx.Button(panel, -1, "4-Hour Set", pos=(10, 85),
size=wx.DefaultSize)

        #---Grid

        grid = wx.grid.Grid(panel, pos=(140, 0), size=(900, 300))

        table = LineupTable()
        grid.SetTable(table, True)

        #---Grid properties

        grid.EnableEditing(False)
        grid.SetDefaultCellAlignment(wx.ALIGN_CENTER, wx.ALIGN_CENTER)
        grid.SetSelectionBackground('red')
        grid.EnableDragColSize(enable=False)
        grid.EnableDragRowSize(enable=False)
        grid.SetLabelBackgroundColour((100, 200, 150))
        grid.SetLabelTextColour((255, 255, 255))

        #---Column Sizes

        grid.AutoSize()

        #---Use below if want to size individual columns (index, size)
        #---Also have SetRowSize
        #grid.SetColSize(0, 150)

    def OnClick(self, event):
        pass

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MyFrame()
    frame.Show()
    app.MainLoop()

#--------------------------END CODE

  The data from LineupTable initializes into my grid just fine (data
comes from getdata1hr.py). What I want to do is press the self.btn_1hr
button, which is attached to getdataall.py, and then have that data
replace (refresh?) onto the grid.

  I've seen some information for the GetTableMessage, but I can't
understand how to structure that, not to mention where I would put it in
my code! If I understand things right, GetTableMessage sends the
updated data to the grid. I tried to just do another SetTable and then
a refresh, but it doesn't work because (apparently?) it's not possible
to SetTable more than once on the same grid.

  If you look at the code, I also attempted to just create a call to
LineupTable2, but that doesn't work, either.

  Would someone please provide a link/tutorial for updating data in a
pyGridTableBase and/or wx.Grid? If not a link, just an explanation?
Thank you.

VR

Telly