Set coordinates of grid using obtained coordinates in wxPython Topic is solved

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
User avatar
pikkip
Knows some wx things
Knows some wx things
Posts: 37
Joined: Mon Sep 26, 2016 6:08 am

Set coordinates of grid using obtained coordinates in wxPython

Post by pikkip »

I have a program which obtaines a set of coordinates from the user and try to display it on a grid in wxPython. How to do this in Python? :(
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Set coordinates of grid using obtained coordinates in wxPython

Post by doublemax »

That's a little vague, what exactly is the problem?

In the simplest form, you just call wxGrid::CreateGrid(numRows, numCols) so that it's big enough to fit all your data.
Then call wxGrid::SetCellValue ( row, col, string ) to fill the cells.
Use the source, Luke!
User avatar
pikkip
Knows some wx things
Knows some wx things
Posts: 37
Joined: Mon Sep 26, 2016 6:08 am

Re: Set coordinates of grid using obtained coordinates in wxPython

Post by pikkip »

I have a grid of dimension x X y. I want to highlight the cell whose coordinates I obtain from the user.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Set coordinates of grid using obtained coordinates in wxPython

Post by doublemax »

Sorry, i still don't understand. What do you mean with "highlight"? And how do you get the coordinates from the user?
Use the source, Luke!
User avatar
pikkip
Knows some wx things
Knows some wx things
Posts: 37
Joined: Mon Sep 26, 2016 6:08 am

Re: Set coordinates of grid using obtained coordinates in wxPython

Post by pikkip »

here coloured cells are the highlighted cells
here coloured cells are the highlighted cells
coord.png (38.77 KiB) Viewed 4328 times
As shown in the figure, some cells are coloured red. These are the highlighted cells. I want to do a program where I have a grid and user gives me the x and y coordinates of some cells in this grid. I have to map these coordinates to corresponding cells in the grid and colour them red.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Set coordinates of grid using obtained coordinates in wxPython

Post by PB »

If I understand you correctly, you need map pixel coordinates to cell coordinates? If so, at least in C++, wxGrid provides a group of methods for that (such as XYToCell): see Cell and Device Coordinate Translation in http://docs.wxwidgets.org/3.1/classwx_grid.html

If you meant that user gives you cell coordinates matching your grid ones, why just don't call SetCellBackgroundColour (int row, int col, const wxColour &colour)?
Post Reply