[wxPython-users] First wxpython program: a sudoku program
Christopher Barker
Chris.Barker at noaa.gov
Wed Sep 20 16:14:53 PDT 2006
Jason Wang wrote:
> the code (GridWindow class) is only about 100 lines of code, it does
> alot more than java swing library back when i was still using Java. I
> don't think i learnt enough about wxpython to learn how to use
> floatcanvas,
In theory, you need to know less about wxPython to use floatcanvas, but
if you need to add to or alter it, then you're right, you do need to
know a fair bit.
I guess it's not really full featured yet!
> I would just like someone with some spare time to take a look at my
> code and see what i am doing wrong and what area could be improved,
Only a quick perusal, but:
looping through all the rects to find the one clicked on is unnecessary.
With a rectangular grid, it should be easy to calculate which grid box
you're in by knowing the origin of the gird, and the size of the boxes.
My tendency would be to calculate the geometry of the grid in the OnSize
handler, and then use that geometry both to draw the grid, and to figure
out what box the mouse is in. You could also use it to figure out what
part of the grid needed to be re-drawn, as Robin suggested.
On Linux, the black font on blue background is very hard to see, and the
font is pretty small. It looks like you're using defaults. You might
want to pick a font size based on your grid box size, and use:
wx.FontFromPixelSize to set the size. That should give similar results
regardless of screen resolution. I've enclosed a version that does this.
Why not have the grid fill the Window? you could even re-size the window
to stay square. If not that, then it should at least be centered.
I still don't understand why you're re-init-ing the buffer in an IDLE
event. I guess it's not a big deal but there are a LOT of IDLE events!
I'd tend to want to store your values in some kind of 2-d structure:
either nested lists, or better yet, a numpy array.
It does look pretty slick though. Nice job.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the wxpython-users
mailing list