Chapter 36. The Mouse Odometer
If you read Getting Started with Perl/Tk
and Scoreboard: A 15-Minute Perl/Tk Application,
you should be a seasoned Tk novice by now. Assuming so, let’s move right
along and examine the Perl/Tk implementation of the Mouse Odometer,
named modo
and pictured in Figure 36-1.
modo
has got to be one of the most pointless
programs ever written. But it illustrates numerous Perl/Tk features, so
it does have some value. I first saw similar code for the Mac, written
by Sean P. Nolan, that simply tracked a machine’s cursor. Currently I
have logged well over 51 kilometers on my cursor, and my mouse has
careened around its pad some 14 kilometers.
Measuring Distance
Most of this column is not about modo
and how
it works, but rather the Perl/Tk features it uses. This time we’ll
learn how to schedule asynchronous timer events, and look more closely
at window manager commands, menus, menubuttons, and the ColorEditor.
We’ll also create and explain in detail an object-oriented Perl/Tk
composite widget that we’ll create called the Odometer. Like a car’s
odometer, we want our mouse odometer to record the physical
distance traveled by the mouse, not the number of pixels. In a car, you want to know how many miles you’ve traveled, not merely the number of tire-lengths, which will vary from car to car. In the X window system you can ...
Get Web, Graphics & Perl/Tk Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.