Pen and Brush Styles

A useful demonstration of DC drawing of patterned pens and background patterns was submitted to the wxPython-users group help board by Andrea Gavana. Keep in mind that any particular platform may not implement all the patterned lines and backgrounds. I've added to Andrea's demo a bit to show diagonal lines. Here's what it looks like running on MS Windows :

PenAndBrushStyles.py

PenAndBrushStyles.png

When dc.DrawRectangle() is called both a wx.Pen and a wx.Brush are used. Each should be set appropriately beforehand according to how you want the appearance to be. Each can have its own color or be set to transparent. All the brush styles except for the last use a transparent pen set by

Notice the the wx.STIPPLE style for pens and brushes repeatedly applies the pattern from a bitmap. The original pattern is a 32x32 bitmap encoded and embedded into the demo program, but it could just as easily have been read in from a disk file or even generated by a program using DC draws of lines, geometric shapes and points of your own design. I shrunk the bitmap to 16x16 to use as the Frame's title bar icon. It was reduced to a 10x10 pattern for use in the pen and the brush. Notice how the 32x32 pattern's original interior lines were obliterated by the size reduction to a 10x10 pattern. To preserve its fidelity you should create your own 10x10 pattern rather than simply reducing a larger one. Either way can produce interesting results. A variety of geometric shapes can be drawn by a DC onto a wx.Panel or wx.Window

There's no point (no pun intended !) to show a drawn line with its style set to wx.TRANSPARENT, but a rectangle drawn with its brush set this way produces an empty, see-through box. Dots (points) can be drawn by calling dc.DrawLine() with the same starting and ending coordinate.


rdp 2011-08-11

PenAndBrushStyles (last edited 2011-08-11 07:26:12 by 195)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.