From: Kevin A. <al...@se...> - 2004-09-24 23:46:21
|
I have been getting sort of annoyed at the extra vertical whitespace that you have to stick into a static layout for GTK and the Mac in order for the layout to not have the components chopped off vertically on Windows. This is somewhere around 13-20 pixels of extra whitespace at the bottom. OTOH, on the Mac, you typically need extra whitespace around components so that the selection rectangle that is used on the currently selected component won't run into the edge of the frame. I haven't dug into the Apple HIG yet, but I think that is probably at least 7-10 pixels given how much whitespace most Mac apps seem to use for layout. Anyway, I wrote up a prototype fitToComponents method that calculates the minimum size needed for the panel and then adds some padding. I stuck it in the Background class of model.py to see whether we might auto-compensate for the whitespace needs of each platform when a layout is loaded without having to resort to using a sizer for something so basic. Here's the method minus the comments and print statements. def fitToComponents(self, widthPadding=None, heightPadding=5): width = 0 height = 0 for c in self.components.itervalues(): x, y = c.position w, h = c.size width = max(x + w, width) height = max(y + h, height) newWidth, newHeight = self.panel.size if widthPadding is not None: newWidth = width + widthPadding if heightPadding is not None: newHeight = height + heightPadding self.panel.SetSize((newWidth, newHeight)) self.SetClientSize((newWidth, newHeight)) I tested on Windows and the Mac using the dialogs sample in cvs by adding the following method: class Dialogs(model.Background): def on_initialize(self, event): self.fitToComponents(None, 5) Then I ran the sample in various forms, adding a statusBar, removing the menubar and menus, etc. and it appears to behave as expected in all cases and looks better than the extra whitespace the sample would have by default on GTK and Mac. It works for changing the width of the window as well, but I'm not sure about how I feel on changing that automatically. One obvious issue is that human interface guidelines for each platform probably specify the amount of whitespace that should be used, the Mac is likely more than Windows, etc. so it might make more sense to have a default arg that will end up using what is appropriate for each platform, while still allowing the user code or resource to override that value. My current thinking is that I would add an option to the Background resource format that takes a tuple and PythonCard would "fix" the layout when it adds the components. Since you might not want it to do this fix, it will be settable via the Background Info dialog and people generating layouts on the fly will always be able to call it manually as well. There might be a bit of overlap with some of the experiments that Alex has been doing on auto-generating sizer wrappers on a layout. If you have any comments or suggestions related to this idea, I would like to hear them. ka |