1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
Geometry
In wpy, all geometry management is performed by Python methods in wpy.py.
These methods are in class WpyGeometry and are inherited by class CWnd.
You can write your own geometry managers if you wish, and use multiple
inheritance to make them available.
The data attributes object.wpySizeX/Y and object.wpyLocX/Y control the
geometry. These are the requested size and location of the object. But
the exact meaning depends on the type of the object.
For controls, a two-step creation is required. When a control object is
made with "b = CPushButton(...)" for example, a default size is assigned
to b.wpySizeX and b.wpySizeY. You can use this size, or alter it as you see
fit. For example, to make larger buttons, you could multiply the sizes by
1.5. It is non-portable to depend too much on any particular control size,
since these vary among systems. The default location is (0, 0), so you need to
assign a location before you create the button with b.Create(). This is done
with the geometry methods (see below).
For windows, the wpy system is free to ignore the requested sizes and locations.
Dialogs are an exception, and you can set a size, but normal top level window
sizes are assigned by the system. Even if the size request is honoured, the
user may change a window size at any time. To cope with this, all layout
and geometry should be done in response to the
"OnSize" message which has a parameter giving the actual size (but not the location)
of the window. Never depend on wpySizeX/Y to be the window size. If you need
the size, call object.GetClientRect() to get it. This will only work after
the object is created and sized by the underlying window system.
Dialogs are different. They only get an InitDialog() message, and you can set the
size there. Dialogs can not be resized by the user.
Geometry Methods
These methods are currently available for geometry management. They should
be called in response to an "OnSize" message. They work by setting wpySizeX/Y
and wpyLocX/Y to correct values. Some call MoveWindow to notify the
window system of the change.
WpyMakeEqualSize Make a list of buttons or other objects equal to
the size of the largest. No MoveWindow call.
WpyMakeEqualSpaceX Space objects equally along a horizontal line.
No move window call.
WpyPlace Place an object at a specified pixel position, or at a
position relative to a specified reference object.
This calls MoveWindow.
WpyShrinkWrap(self, add_border = 1)
Size an object to be large enough to fit all its children plus
the point (0, 0). Optionally add a border to the right and bottom
equal to the left and top border. This calls MoveWindowSize.
System Independent Layout
Your code must not depend on a particular screen resolution or operating
system. To do system independent layout, you must depend on the native
control sizes. Other convenient metrics are the screen size wpyScreenSizeX/Y
and the system character size available as wpyCharSizeX/Y. To
size a dialog box with a message, for example, make the message object and
buttons first. Recall that all controls are returned with default sizes.
Make the dialog size equal to (for example) 1.2 times the message size plus
3 times the button height. Place the message at (0.1, 0.1) in the dialog,
and place the buttons one button height from the bottom of the dialog using
WpyPlace. For layouts with more controls, it is convenient to have an origin
(x0, y0). Place controls relative to (x0, y0) and update it as you add controls.
If you are drawing into a device context be sure to use the sizes and
attributes of the DC to do layout.
In wpy, geometry is not an attribute of the object (as in Tk) but is a function
executed in response to a message.
Rectangles
Rectangles are used in wpy to do layout and return sizes. The "OnSize" handler
is passed a rectangle giving the window size, for example. And WpyPlace can
place an object relative to any rectangle. In wpy, a "rectangle" is any object
which has wpySizeX/Y and wpyLocX/Y attributes (wpyFlags is needed too). So
all visible objects are all rectangles, and you can make your own rectangles
of class CRect, assign any convenient size and location to them, and use them
class CView, CScrollView, CEditView
|