From: Alex T. <al...@tw...> - 2005-08-02 23:01:24
|
Kevin Altis wrote: > IIRC, z-order and overlapping widgets is going to be a problem on the > Mac in the foreseeable future. wx doesn't really support overlapping > widgets anyway, it is just that there are certain situations you can > get away with them on Windows and Linux. Oh boy, am I glad you said that now. I was just about to set off on a project that would have utterly failed because it was completely dependent on reliable z-order and overlapping components. And of course I'd have been developing on Win, so it would probably have worked *most* of the time - leaving me baffled why sometimes I didn't get away with it. And eventually, I'd have put it on a Mac and discovered I'd wasted a lot of time. So I'm really glad you said that now - thanks Kevin. > Another possibility might be to use a background image which has the > rectangles you want and will be drawn instead of the normal background > window pattern; see the proof sample for an example of the use of a > background image. The downside is that the background image you create > will need to be tweaked as your layout changes, window grows, etc. but > it should work on all platforms. Using an image and adjusting it for changes sounds like a nuisance, so I kept looking .... Brad, Another approach (not quite so simple, I'm afraid) would be to define your own background handler (this idea and code stolen from the resourceEditor's way of doing gridlines). This works fine (as far as I can tell) on Windows - and should, I hope, work on other systems as well (assuming the resourceEditor's gridlines work) For this demo, I just defined Image components called "colouredArea1", "colouredArea2", etc. and defined their fore & backgroundColor (remember they're not going to be actually visible, so shouldn't be any platform-specific issues) - but doing this let me see in the resourceEditor how it should look. And using simple components like this means that you can use them in sizers, or adjust their size in your own geometry handlers. class MyBackground(model.Background): def on_initialize(self, event): # if you have any initialization # including sizer setup, do it here for comp in self.components.itervalues(): if comp.name[:12] == "colouredArea": comp.visible = False self.panel.Bind(wx.EVT_ERASE_BACKGROUND, self.drawBackgroundAreas) self.panel.Refresh() pass def on_close(self, event): # Not sure why this is needed - resourceEditor doesn't appear to have an equivalent # but without this, we get attempts to use "dead" C++ objects self.panel.Unbind(wx.EVT_ERASE_BACKGROUND) event.skip() def drawBackgroundAreas(self, event): dc = event.GetDC() if not dc : dc = wx.ClientDC(self.panel) r = self.panel.GetUpdateRegion().GetBox() dc.SetClippingRegion(r.x, r.y, r.width, r.height) # need to set the background color to the default panel color brush = dc.GetBackground() brush.SetColour(self.panel.GetBackgroundColour()) dc.SetBackground(brush) dc.Clear() for comp in self.components.itervalues(): if comp.name[:12] == "colouredArea": dc.SetPen(wx.Pen(comp.backgroundColor, 1, wx.SOLID)) dc.SetBrush(wx.Brush(comp.backgroundColor, wx.SOLID)) x,y = comp.position sx,sy = comp.size dc.DrawRectangle(x,y, sx,sy) Good luck ... -- Alex Tweedly http://www.tweedly.net -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.338 / Virus Database: 267.9.9/62 - Release Date: 02/08/2005 |