473,769 Members | 3,329 Online
Bytes | Software Development & Data Engineering Community
+ 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 7087
All you do is:

self.GetCellVal ue(row, column)

Where self is a wxGrid class instance.

Sample class from working program:

class SimpleGrid(wxGr id): ##, wxGridAutoEditM ixin):
def __init__(self, parent):
wxGrid.__init__ (self, parent, -1)
#
# Get shortcuts to some editors for different types of cells
#
bEditor=wxGridC ellBoolEditor()
bRenderer=wxGri dCellBoolRender er()
tEditor=wxGridC ellTextEditor()
tRenderer=wxGri dCellStringRend erer()
fEditor=wxGridC ellFloatEditor( )
fRenderer=wxGri dCellFloatRende rer()
fRenderer.SetPr ecision(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.columncoun t=len(self.colu mndefs)
self.CreateGrid (0, self.columncoun t)
#
# Set column widths
#
map(self.SetCol Size, range(self.colu mncount),
[a[1] for a in self.columndefs])

#
# Set custom column labels
#
map(self.SetCol LabelValue, range(self.colu mncount),
[a[0] for a in self.columndefs])

#
# Sheet will toggle between these two colors on change of invoice
number
#
# LightGray
self._backgroun dcolors=[wxWHITE,"#CCCCC C"]
self._toggleBGC =0
#
# Register event handlers
#
#EVT_GRID_CELL_ LEFT_DCLICK(sel f, self.OnCellLeft DClick)
#EVT_GRID_CELL_ LEFT_CLICK(self , self.OnCellLeft Click)
#EVT_GRID_CELL_ RIGHT_CLICK(sel f, self.OnCellRigh tClick)
#EVT_GRID_RANGE _SELECT(self, self.OnRangeSel ect)
EVT_GRID_CELL_C HANGE(self, self.OnCellChan ge)
return

def OnCellChange(se lf, evt):
row=evt.GetRow( )
col=evt.GetCol( )
#
# Special handlers for some columns
#
if col == 13:
self.SetCellVal ue(row, col, self.GetCellVal ue(row,col).upp er())
if self.GetCellVal ue(row, col) not in ("Y","N"):
self.SetCellVal ue(row, col, "Y")
if self.GetCellVal ue(row, col) == "N":
self.SetCellTex tColour(row, 13, wxBLACK)

if self.GetCellVal ue(row, col) == "Y" and \
self.GetCellVal ue(row, 14) == "0.00":
self.SetCellTex tColour(row, col, wxRED)

elif col == 14:
if self._trace: self.logf.write lines("T","Col= 14 functions")
equation=self.G etCellValue(row , col)
if equation[0] == "=": equation=equati on[1:]
try: value="%.2f" % eval(equation)
except: value="0.00"
self.SetCellVal ue(row, col, value)
if value != "0.00" and self.GetCellVal ue(row, 13) == "Y":
self.SetCellTex tColour(row, 13, wxBLACK)
elif value == "0.00" and self.GetCellVal ue(row, 13) == "Y":
self.SetCellTex tColour(row, 13, wxRED)
elif col == 15:
self.SetCellVal ue(row, col, self.GetCellVal ue(row,col).upp er())
if self.GetCellVal ue(row, col) not in ("Y","N"):
self.SetCellVal ue(row, col, "Y")
if self.GetCellVal ue(row, col) == "N":
self.SetCellTex tColour(row, col, wxBLACK)
self.SetCellTex tColour(row, 9, wxBLACK)

if self.GetCellVal ue(row, col) == "Y" and \
not self.GetCellVal ue(row, 16):
self.SetCellTex tColour(row, col, wxRED)
self.SetCellTex tColour(row, 9, wxRED)

else: return

self.ForceRefre sh()
return

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

Regards,
Larry Bates
Syscon, Inc.

"matthiasja nes" <ma***********@ gmx.net> wrote in message
news:d5******** *************** ***@posting.goo gle.com...
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
4245
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
1213
by: Dean Marodi | last post by:
Hi! I want to use Crystal Reports Viewer with wxPython. Can anyone help (example)? Thanks, Dean
1
4948
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
1506
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, but that how I got started ;) -- any help owuld be appreciated
10
4654
by: lux | last post by:
Hi, How can I capture the EVT_SET_FOCUS on a wxGrid? Tank's in advance Luca
5
1426
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 small app to check my Gmail. I want something that will just sit in my system tray checking for new emails every ten minutes or so. As such, I have no need for an actual window anywhere. So I'm wondering if I should still use a Frame or not. ...
9
4449
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 "Run" button, the GUI would close, and the 12 input variables would then be available for the rest of the program. So far, what I have been able to do is mostly a reverse engineering job to get the frame to look right and return the text variable...
8
2325
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 use ActiveXWindow to call the clsid but that doesn't seem to work. I also tried using mediactrl passing in a URI but either I wasn't supplying the correct one or wasn't using it correctly. All I would like is to be able to see video that is coming...
0
955
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 me. that is the vb declaration nResult (LONG) = RMC_CreateChartOnDC( ByVal nParentDC (LONG), ByVal nCtrlId (LONG), ByVal nX (LONG),
0
9587
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3958
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 we have to send another system

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.