473,465 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

WxPYTHON GetValue from wxGrid HELP

dear all,

I just need a little help.

could anyone give real code example (simple) how to read the value of
a grid cell.

i could not figure it out and really would like to do a simple
spreadsheet application in wxpython (my first try with wxpython gui)

so, if any one knows just how to read the value of a cell - a real
working example would be greatly appriciated

Matthias Janes
Jul 18 '05 #1
1 7053
All you do is:

self.GetCellValue(row, column)

Where self is a wxGrid class instance.

Sample class from working program:

class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin):
def __init__(self, parent):
wxGrid.__init__(self, parent, -1)
#
# Get shortcuts to some editors for different types of cells
#
bEditor=wxGridCellBoolEditor()
bRenderer=wxGridCellBoolRenderer()
tEditor=wxGridCellTextEditor()
tRenderer=wxGridCellStringRenderer()
fEditor=wxGridCellFloatEditor()
fRenderer=wxGridCellFloatRenderer()
fRenderer.SetPrecision(2)
#
# Define and set the column sizes and labels
#
# Display
#--Column Heading, Width, Alignment,read-only, editor, renderer
self.columndefs=(
("?", 20, wxALIGN_LEFT, false, bEditor, bRenderer),
("Cust#", 50, wxALIGN_LEFT, true, tEditor, tRenderer),
("Cust Name", 180, wxALIGN_LEFT, true, tEditor, tRenderer),
("Reference", 100, wxALIGN_LEFT, true, tEditor, tRenderer),
("DocType", 50, wxALIGN_CENTRE,true, tEditor, tRenderer),
("Inv. #", 75, wxALIGN_CENTRE,true, tEditor, tRenderer),
("InvDate", 60, wxALIGN_CENTRE,true, tEditor, tRenderer),
("L#", 35, wxALIGN_CENTRE,true, tEditor, tRenderer),
("Item #", 65, wxALIGN_CENTRE,true, tEditor, tRenderer),
("Description",300, wxALIGN_LEFT, false, tEditor, tRenderer),
("Qty", 50, wxALIGN_RIGHT, false, tEditor, tRenderer),
("Price", 50, wxALIGN_RIGHT, true, fEditor, fRenderer),
("Cost", 50, wxALIGN_RIGHT, true, fEditor, fRenderer),
("OMMC?", 60, wxALIGN_CENTRE,false, tEditor, tRenderer),
("OMMC $", 70, wxALIGN_RIGHT, false, tEditor, tRenderer),
("S#", 35, wxALIGN_CENTRE,false, tEditor, tRenderer),
("Serial #'s", 300, wxALIGN_LEFT, false, tEditor, tRenderer)
)

self.columncount=len(self.columndefs)
self.CreateGrid(0, self.columncount)
#
# Set column widths
#
map(self.SetColSize, range(self.columncount),
[a[1] for a in self.columndefs])

#
# Set custom column labels
#
map(self.SetColLabelValue, range(self.columncount),
[a[0] for a in self.columndefs])

#
# Sheet will toggle between these two colors on change of invoice
number
#
# LightGray
self._backgroundcolors=[wxWHITE,"#CCCCCC"]
self._toggleBGC=0
#
# Register event handlers
#
#EVT_GRID_CELL_LEFT_DCLICK(self, self.OnCellLeftDClick)
#EVT_GRID_CELL_LEFT_CLICK(self, self.OnCellLeftClick)
#EVT_GRID_CELL_RIGHT_CLICK(self, self.OnCellRightClick)
#EVT_GRID_RANGE_SELECT(self, self.OnRangeSelect)
EVT_GRID_CELL_CHANGE(self, self.OnCellChange)
return

def OnCellChange(self, evt):
row=evt.GetRow()
col=evt.GetCol()
#
# Special handlers for some columns
#
if col == 13:
self.SetCellValue(row, col, self.GetCellValue(row,col).upper())
if self.GetCellValue(row, col) not in ("Y","N"):
self.SetCellValue(row, col, "Y")
if self.GetCellValue(row, col) == "N":
self.SetCellTextColour(row, 13, wxBLACK)

if self.GetCellValue(row, col) == "Y" and \
self.GetCellValue(row, 14) == "0.00":
self.SetCellTextColour(row, col, wxRED)

elif col == 14:
if self._trace: self.logf.writelines("T","Col=14 functions")
equation=self.GetCellValue(row, col)
if equation[0] == "=": equation=equation[1:]
try: value="%.2f" % eval(equation)
except: value="0.00"
self.SetCellValue(row, col, value)
if value != "0.00" and self.GetCellValue(row, 13) == "Y":
self.SetCellTextColour(row, 13, wxBLACK)
elif value == "0.00" and self.GetCellValue(row, 13) == "Y":
self.SetCellTextColour(row, 13, wxRED)
elif col == 15:
self.SetCellValue(row, col, self.GetCellValue(row,col).upper())
if self.GetCellValue(row, col) not in ("Y","N"):
self.SetCellValue(row, col, "Y")
if self.GetCellValue(row, col) == "N":
self.SetCellTextColour(row, col, wxBLACK)
self.SetCellTextColour(row, 9, wxBLACK)

if self.GetCellValue(row, col) == "Y" and \
not self.GetCellValue(row, 16):
self.SetCellTextColour(row, col, wxRED)
self.SetCellTextColour(row, 9, wxRED)

else: return

self.ForceRefresh()
return

Hope it helps. I pretty much got this from the wxWindows demos
that come with standard installation.

Regards,
Larry Bates
Syscon, Inc.

"matthiasjanes" <ma***********@gmx.net> wrote in message
news:d5**************************@posting.google.c om...
dear all,

I just need a little help.

could anyone give real code example (simple) how to read the value of
a grid cell.

i could not figure it out and really would like to do a simple
spreadsheet application in wxpython (my first try with wxpython gui)

so, if any one knows just how to read the value of a cell - a real
working example would be greatly appriciated

Matthias Janes

Jul 18 '05 #2

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

Similar topics

3
by: Tom Lee | last post by:
# # Python 2.2.3, wxWindows/wxPython 2.4.1 # # The code: # from wxPython.wx import * class TestFrame( wxFrame ): def __init__( self ):
0
by: Dean Marodi | last post by:
Hi! I want to use Crystal Reports Viewer with wxPython. Can anyone help (example)? Thanks, Dean
1
by: James | last post by:
wxpython 2.5.3 hi, anyone know how to make a multiline cell editor for wxgrid? thank you :) best regards, James
1
by: Sam the Cat | last post by:
using "from wxPython.wx import *" under python2.3 I cannot seem to find the wxGrid class -- it says its undefined -- am I missing something obvious ? I know the globalspace import is not the best,...
10
by: lux | last post by:
Hi, How can I capture the EVT_SET_FOCUS on a wxGrid? Tank's in advance Luca
5
by: Jared Russell | last post by:
I've recently decided to try my hand at GUI programming with wxPython, and I've got a couple questions about the general conventions regarding it. To mess around with it, I decided to create a...
9
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the...
8
by: ohyea | last post by:
Essentially I am developing a voip phone using a SDK and wxpython. Well I've gotten all the phone stuff to work but for some reason the video has been giving me a lot of trouble. I have been told to...
0
by: oyster | last post by:
I am porting www.rmchart.com to python, now the code is almost finished, and I have supplied some examples.py which write to picturefiles directly, but the example to draw the chart on GUI stops...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.