First, you can do:
dc = wx.AutoBufferedPaintDC(self)
instead of that code. The “Auto” means it determines when it should or should not provide a double-buffered context.
The reason I don’t do that is because for certain drawing actions I prefer to use GraphicsContext, and “gc = wx.GraphicsContext.Create(dc)” with an wx.AutoBufferedPaintDC() raises an error.
And then I go about drawing things. However, if I’m drawing a certain region and its been indicated that the subclass wants to take over this region-- how best do I pass that on? Should I just call a method, pass it my DC, and perhaps a wxRect indicating what region it should draw upon? That seems sorta un-wx-ish, somehow.
Usually, subclassing is used to override and expand functionality in a base class, but here it sounds like you’re using it to break the functionality of a big class up into smaller logical groups. While I don’t know what you’re trying to accomplish, the first thought that popped into my head was having each owner-drawn region as an object, e.g. MyControlRect(x, y, w, h) with a paint method, then have your main class manage those objects and on paint, iterate through them and draw them in their proper location. If I knew more about what exactly you are trying to do, I could probably give a more detailed explanation, but hopefully you get the idea.
Maybe that won’t be of any help, but when I hear phrases like “big ol’” and “slightly complex portions”, usually it means it’s time to try and break things down a bit.
Basically, I’m using the subclassing to sort of reconfigure the base functionality of the control. The control itself is really a series of “pieces” that get assembled according to a particular subclasses needs. So I am breaking it apart but “the control” is a controller component that puts 'em back together
The general goal, in short? A read-only ListCtrl/Grid hybrid supporting variable multiple-lines-per-record (where Grid called them rows, I call them records as there are multiple rows (I call them lines) in each record), variable row height (per-line), variable cell width (where a single ‘column’ within a line can have a very different width then even the same column of another line), and where a wide range of things can be easily drawn into a particular cell: strings, background colors, checkboxes, and images so far.
A picture’s worth a thousand words – The attached is the current state of the experiment. You can see about 2.1 records on the jpeg; each record has two “lines”. The first line contains status, an icon, slug, flags and keywords… The second line contains a thumbnail, and three check boxes. Each of those items is its own cell. The depth of each line is variable-- in this case the first line’s depth is 20px, the second is 100px (since the thumbnail is defined as 100x100). That’s rare: most uses would not have a thumbnail. But its an experiment so I’m throwing it in Each of those check boxes is its own column/field/cell all by itself-- to show the variable cell-width. The “header” only matches the first line.
Currently, I’m following Robin’s advice and sorta following the Grid model – I have lots of “renderers” and each cell has a distinct data type that matches a registered renderer. It seems to be working good. (So thanks Robin!)
I was going to try to do each region as an object as you suggest-- but that’d be 10-20 thousand objects, which made me cringe But this is all experimental still.
Thanks for your help.
–Stephen
P.S. If this gets past Experimental and into Useful, if anyone else would find it vaguely useful I can get my boss to let me release it as I’ve been doing it off-hours as a sort of fun project. Don’t know if anyone else ever needs this kind of thing, I’ve been trying to twist wxGrid and wxListCtrl into this particular need for years now and have finally given up