Sorry if this sounds like a whine or a rant. It really isn't.
I continue to be amazed by the wxpython. In ways it is incredibly elegant and powerful. In other ways it is quite poorly thought out.
Here's my current beef. I spent much of the 1990s being a NeXTSTEP programmer. NeXTSTEP is now called Cocoa and it's the basis of the Mac OS X GUI. But I can't use NeXTSTEP because I want my code to run on Linux.
With NeXTSTEP, printing is pretty easy. You just send a message to your object and it prints. Or it makes PDF or PS code that can be saved away. Simple.
After about an hour of work I got printing under wxwidgets to work. I'm amazed that you can't just send a print() message to the Frame class and have the Frame print. The underlying design problem seems to be that EVT_PAINT doesn't send the DC that you are supposed to paint into, so the code that handles the event is separated from the code that actually does the painting. As a result, you need to have different code paths for printing and painting, which then get combined in a lower-level function. My Time Panel does it like this:
class TimePanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
self.SetBackgroundColour(wx.WHITE)
... blah blah blah ...
def Paint(self,dc):
""" Just a dummy paint method """
dc.Clear()
foreground = wx.NamedColour("red")
background = wx.NamedColour("white")
dc.DrawTextList(["Hi Sonia"],[(100,100)],[foreground],[background])
def OnPaint(self, evt):
dc = wx.PaintDC(self)
self.Paint(dc)
So my wx.Printout subclass calls theframe.Paint( self.GetDC()). It's a mess, but at least I can try to hide some of the mess.
My questions:
1. The wxpython demo printing example has something called a canvas, but the canvas just seems to be a frame that implements these three methods:
def getWidth(self):
... blah ...
def getHeight(self):
... blah ...
def DoDrawing(self,dc,ignore):
self.Paint(dc)
I see that wxpython has support for a wx.lib.flatcanvas by Chris Barker (chris.barker@noaa.gov) and for a glcanvas (which doesn't work on my system because I don't have OpenGL installed). floatcanvas looks like a great start, but I'm hadpressed to find some decent examples. Should I use it?
2. I'd like to drop the float canvas into a scrolling view that supports zoom and mouse events. Again, the wxPython demo seems to have the start of a system, but it's really big and intermixes the code that makes the canvas with the code that makes the demo. Do we have anything clean?
Is this an area that people care about?
3. I'm actually interested in some graphical depictions of timelines. Is there anything pre-packaged ready to go?
Thanks.
Simson