473,378 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how to refresh grid on a notebook?

Hello,
To be honest, I also posted this on the wxPython mailing list. But I
thought maybe some of you on the python list can help me...

I am trying to refresh a pane of a notebook that contains a grid that
contains data from a MySQL database. Here is the code (sorry, it's
quite long):

#!/usr/bin/env python
import wx
import wx.grid
import getdata
# getdata.py is a module I wrote to connect to the MySQL database, it works

db = getdata.Eb_db("www.serpia.com", "gedrag5")

class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.notebook_1 = wx.Notebook(self, -1, style=0)
self.notebook_1_pane_2 = wx.Panel(self.notebook_1, -1)
self.notebook_1_pane_1 = wx.Panel(self.notebook_1, -1)
self.label_1 = wx.StaticText(self.notebook_1_pane_1, -1, "Input")
self.text_ctrl_1 = wx.TextCtrl(self.notebook_1_pane_1, -1, "")
self.button_1 = wx.Button(self.notebook_1_pane_1, -1, "submit")
self.button_2 = wx.Button(self.notebook_1_pane_2, -1, "refresh")
self.grid_1 = wx.grid.Grid(self.notebook_1_pane_2, -1, size=(1, 1))

self.__set_properties()
self.__do_layout()
# create an event for button_2
wx.EVT_BUTTON(self, self.button_2.GetId(), self.fillGrid)

def __set_properties(self):
self.SetTitle("frame_1")
self.SetSize((400, 400))

def fillGrid(self, event):
# fill grid with data from database
self.grid_1.CreateGrid(len(db.data), len(db.fields))
index = 0
for item in db.fields:
self.grid_1.SetColLabelValue(index, item[0])
index += 1

for row in range(len(db.data)):
for col in range(len(db.data[row])):
value = db.data[row][col]
self.grid_1.SetCellValue(row,col,value)

def __do_layout(self):
sizer_1 = wx.BoxSizer(wx.VERTICAL)
grid_sizer_3 = wx.GridSizer(2, 1, 0, 0)
grid_sizer_2 = wx.GridSizer(2, 2, 0, 0)
grid_sizer_2.Add(self.label_1, 0, wx.FIXED_MINSIZE, 0)
grid_sizer_2.Add(self.text_ctrl_1, 0, wx.FIXED_MINSIZE, 0)
grid_sizer_2.Add(self.button_1, 0, wx.FIXED_MINSIZE, 0)
self.notebook_1_pane_1.SetAutoLayout(True)
self.notebook_1_pane_1.SetSizer(grid_sizer_2)
grid_sizer_2.Fit(self.notebook_1_pane_1)
grid_sizer_2.SetSizeHints(self.notebook_1_pane_1)
grid_sizer_3.Add(self.button_2, 0, wx.FIXED_MINSIZE, 0)
grid_sizer_3.Add(self.grid_1, 1, wx.EXPAND, 0)
self.notebook_1_pane_2.SetAutoLayout(True)
self.notebook_1_pane_2.SetSizer(grid_sizer_3)
grid_sizer_3.Fit(self.notebook_1_pane_2)
grid_sizer_3.SetSizeHints(self.notebook_1_pane_2)
self.notebook_1.AddPage(self.notebook_1_pane_1, "Output")
self.notebook_1.AddPage(self.notebook_1_pane_2, "Input")
sizer_1.Add(wx.NotebookSizer(self.notebook_1), 1, wx.EXPAND, 0)
self.SetAutoLayout(True)
self.SetSizer(sizer_1)
self.Layout()

if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()

As you can see, I use "button_2" on the second pane of the notebook to
fill the grid. But what I really want to do is to click on the pane
itself to update the grid.
And there is another problem, when I use "button_2 ", it works only
once. I get the following error:
C++ assertion "wxAssertFailure" failed in
.../src/generic/grid.cpp(4018): wxGrid::CreateGrid or wxGrid::SetTable
called more than once.
I think maybe I should destroy the grid first, but I don't know how to
do this properly. I 've tried several things.

I hope that I explained my problem well enough and that somebody can
give some clues on how to solve this.
--
Please visit dimitri's website: www.serpia.com
Jul 18 '05 #1
0 1424

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Scott Lyon | last post by:
I am having a strange problem. The program is a bit complex, but I'll try to simplify what I can. I apologize if this is complicated, but I think this would still be simpler than posting a bunch of...
2
by: Jeronimo Bertran | last post by:
Hi, I have a page with a very data intensive grid which needs to be automatically refreshed constantly if a change is detected. In order to not refresh the complete page so often, I created an...
3
by: Eitan M | last post by:
Hello, I have a datagrid object. I have my own button on the grid, but after I am doing something after clicking on the button, I don't want to refresh the contents of the grid. the contents...
7
by: Juan Romero | last post by:
Hey guys, please HELP I am going nuts with the datagrid control. I cannot get the damn control to refresh. I am using soap to get information from a web service. I have an XML writer output...
3
by: David Cartwright | last post by:
Hi all, I'm having a weird time with a call to the Refresh() method of a DataGridView. I have a VB.NET 2005 Windows application with a main form and a "worker" thread. The main form delegates a...
3
by: bijaysalotry | last post by:
I have created a page which contains 2 grid and other controls. There is a button which is used to update one grid but on the basis of grid one which contains key column.page Default.aspx My...
1
by: Orit | last post by:
Hi . I am creating an ASP.NET 2.0 web site and have the following problem : 1. I have a GridView which bound to the object data source. 2. This object data source is SQL Table adapter that I...
3
by: Dave | last post by:
I have an GridView on one page that will open a popup for the selected record. I've been told that there is a way that when the popup record is updated the GridView can be refreshed or Databind. ...
6
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi - I'm having trouble refreshing a datagrid control bound to a dataset that was created from the New Data Source wizard. What is the code required to refresh the datagrid with data from the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.