Dealing with device contexts

As we discussed earlier in this chapter, drawing to the screen is the most basic thing that a UI toolkit does. Most of the drawing that wxPython does is encapsulated within the paint methods of each widget, because that encapsulation is perhaps the second most basic thing that a UI toolkit does. That won't always be enough for you, though. Sometimes, as in chapter 6, you'll need to draw in response to a user command. Sometimes you'll want some fancy animation. Sometimes you'll want to draw your screen to a nonstandard display like a printer. Sometimes, you'll want a widget with a custom look, and sometimes you'll just want to be decorative. In wxPython, all these tasks are managed by manipulating an appropriate device context.

A device context is the abstraction that wxPython uses to allow you to draw on a graphical device, such as the screen or a printer, without knowing the details of that device. This is managed by providing an abstract parent class, wx.DC, which defines a common API used by a series of subclasses, each of which represents a different graphic device. Chapter 6 presents device contexts, with an extended example of how to use them. In the following sections we'll discuss device contexts in more detail.

Was this article helpful?

0 0

Post a comment