Hello!
I have designed a dialog with a grid widget. I would like to populate it with data from a MySQL table which has 10396 rows and 5 columns, as the grid widget. How can I do it? Then, how can I select a row from the grid widget and store it in a variable?
Cheers!
#! /usr/bin/env python
# TestDialogs.py
import wx, MySQLdb, wx.lib.intctrl, wx.grid
class Ornithobase(wx.Frame):
def __init__(self, parent, id, title = 'Select species'):
wx.Frame.__init__(self, parent, id, title, size=(800,650))
db= MySQLdb.connect(host='localhost', user='acrocephalus' , passwd='acrsci00', db='Ornithobase')
cursor = db.cursor()
#Define main panel
panel = wx.Panel(self, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
#Define sizers
#Horizontal sizers
SpeciesTableSizer = wx.BoxSizer(wx.HORIZONTAL)
BtnSizer = wx.BoxSizer(wx.HORIZONTAL)
#Add species table widget
Species = wx.grid.Grid(panel, -1, size=(750,550))
Species.CreateGrid(10396,5)
Species.SetColLabelValue(0, 'Order')
Species.SetColLabelValue(1, 'Family')
Species.SetColLabelValue(2, 'Genus')
Species.SetColLabelValue(3, 'Species')
Species.SetColLabelValue(4, 'English name')
Species.SetRowLabelSize(0)
SpeciesTableSizer.Add(Species, wx.ALIGN_CENTER | wx.ALL,0 )
#Add buttons
useBtn = wx.Button(panel, -1, 'Use')
rmvBtn = wx.Button(panel, -1, 'Remove')
doneBtn = wx.Button(panel, -1, 'Done')
BtnSizer.Add(useBtn, 0, wx.ALL, 5)
BtnSizer.Add(rmvBtn, 0, wx.ALL, 5)
BtnSizer.Add(doneBtn, 0, wx.ALL, 5)
vbox.Add(SpeciesTableSizer, 0, wx.ALIGN_CENTER | wx.ALL, 5)
vbox.Add(BtnSizer, 0, wx.ALIGN_CENTER | wx.ALL, 5)
panel.SetSizer(vbox)
self.Centre()
self.Show(True)
app = wx.App()
Ornithobase(None, -1)
app.MainLoop()