If themouse cursor is outside the Canvas widget or not over an item, the "current" Tags can also be logical expressions by using the operators: &&, ||, ^, !, andparenthetical subexpressi
Trang 2Symbols & Numbers | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q |
R | S | T | U | V | W | X | Y | Z
Copyright © 2002 O'Reilly & Associates, Inc All Rights Reserved.
Trang 3R | S | T | U | V | W | X | Y | Z
Trang 6Copyright © 2002 O'Reilly & Associates, Inc All Rights Reserved.
Trang 7R | S | T | U | V | W | X | Y | Z
Trang 10insert method and: 8.6 Inserting Text
Trang 13R | S | T | U | V | W | X | Y | Z
Trang 15Button widgets and: 4.3 Table of Options for Button-Type Widgets4.5 Displaying an Image or Bitmap
Trang 20R | S | T | U | V | W | X | Y | Z
Trang 22Button widgets and: 4.2 Standard Options for Each Button Type4.3 Table of Options for Button-Type Widgets
Trang 23syntax: 14.3.8.2 Subroutine Callback
CALLBACK value: 14.3.6 Subroutine ConfigSpecs
callbacks (see <-seealso>-also xscrollcommand-option">-xscrollcommandoption also -xscrollcommand option)
Trang 26clipboardAppend method: 13.14.1 Clipboard Methods
clipboardClear method: 13.14.1 Clipboard Methods
clipboardColumnCopy method: 8.5.6.1 The Perl/Tk Text widget extendedbindings
8.16.1 Setting and Getting the Gravity
clipboardColumnCut method: 8.5.6.1 The Perl/Tk Text widget extendedbindings
8.16.1 Setting and Getting the Gravity
clipboardColumnPaste method: 8.5.6.1 The Perl/Tk Text widget extendedbindings
Trang 31R | S | T | U | V | W | X | Y | Z
Trang 33-disabledoutlinestipple option: 9.5.1 Common Canvas Dash, Stipple, and TileOptions
-disabledoutlinetile option: 9.5.1 Common Canvas Dash, Stipple, and TileOptions
Trang 36R | S | T | U | V | W | X | Y | Z
Copyright © 2002 O'Reilly & Associates, Inc All Rights Reserved.
Trang 37R | S | T | U | V | W | X | Y | Z
Trang 41R | S | T | U | V | W | X | Y | Z
Trang 47R | S | T | U | V | W | X | Y | Z
Trang 51R | S | T | U | V | W | X | Y | Z
Trang 55R | S | T | U | V | W | X | Y | Z
Trang 63R | S | T | U | V | W | X | Y | Z
Trang 64Symbols & Numbers | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q |
R | S | T | U | V | W | X | Y | Z
Copyright © 2002 O'Reilly & Associates, Inc All Rights Reserved.
Trang 65R | S | T | U | V | W | X | Y | Z
Trang 67R | S | T | U | V | W | X | Y | Z
Trang 71R | S | T | U | V | W | X | Y | Z
Trang 72Menubutton widgets: 12.4.1 Menubutton Options
modular menubars example: 12.2.2 Menubars the Slick, Sophisticated,New-Fashioned Way
Trang 73menu indexes: 12.1.2 Menu Indexes
menu items
Trang 74creating via Perl/Tk 8: 12.2.1 Menubars the Clunky, Casual, Old-FashionedWay
Trang 75associated with pack geometry manager: 2.1.10 Methods Associated withpack
Trang 77R | S | T | U | V | W | X | Y | Z
Trang 79R | S | T | U | V | W | X | Y | Z
Trang 83R | S | T | U | V | W | X | Y | Z
Trang 86PerlPlus Browser Plug-in: 13.3 Widget's ID
22.2 The PerlPlus Browser Plug-in
Trang 87coding style: 1.5.1 Programming Style
customizing: 16 User Customization
debugging and prototyping: 1.6 Debugging and PrototypingPerl/TkPrograms
Trang 89PPM (Perl Package Manager)
packaging for: 14.6.2 Packaging for PPM
packaging for distribution: 14.6 Packaging a Mega-Widget for PublicDistribution
ProgressBar widget: 23.10 The ProgressBar Widget
propagation: 2.1.1 Options for pack
properties, window manager: 11.3 Options
Trang 91R | S | T | U | V | W | X | Y | Z
Trang 93R | S | T | U | V | W | X | Y | Z
Trang 98R | S | T | U | V | W | X | Y | Z
Trang 101createLine method and: 9.6.4 The Line Item
createOval method and: 9.6.5 The Oval Item
createPolygon method and: 9.5.3 Canvas Widget Option List
Trang 103Listbox example: 7.1 Creating and Filling a Listbox
Scrollbars example: 6.4.2 Listbox, Text, and Canvas Widgets
Trang 105SetCursor method: 8.16.1 Setting and Getting the Gravity
setmode method: 18.4.4 Tree Methods
SGI Ports, OpenGL and: 15.9.2 Flying the Enterprise
Trang 106shared memory
as IPC mechanisms: 19 Interprocess Communicationwith Pipes andSockets
Trang 107commands as: 20 IPC with send
delimiters for: 1.3.3 Specifying Options
example inserting into selections: 13.14.3 Exporting the Selection to theOutside World
Trang 109R | S | T | U | V | W | X | Y | Z
Trang 11222.2 The PerlPlus Browser Plug-in
Text widgets and: 8.5 Text Tags
tainted data: 13.20 Interapplication Communication
Trang 114Tiler widget: 6.1 Defining Scrollbar Parts
tiles, Canvas widgets and: 9.5.1 Common Canvas Dash, Stipple, and TileOptions
timeofday method: 13.24 Really Miscellaneous Methods
13.24 Really Miscellaneous Methods
timeouts, fetching web content and: 22.1.2 Fetching Web Content withLWP::UserAgent
Trang 11516.1 Using the Command Line
16.2.2 Manipulating Resources with Tk::CmdLine Subroutines
Tk::CmdLine::SetResources subroutine: 16.2 Using the Option Database16.2.2 Manipulating Resources with Tk::CmdLine Subroutines
Trang 116Toplevel widget
as containers for popups: 12.5.2 The Popup Method
Trang 119R | S | T | U | V | W | X | Y | Z
Trang 122R | S | T | U | V | W | X | Y | Z
Trang 124setting for Scales: 10.4 Minimum and Maximum Values
10.12 Setting the Value of a Scale
variables (see <-seealso>-also labelVariable-option">-labelVariable option also-labelVariable option)
Trang 126R | S | T | U | V | W | X | Y | Z
Trang 128Don Hopkins': 12.8 Pie Menus
Trang 133R | S | T | U | V | W | X | Y | Z
Trang 136R | S | T | U | V | W | X | Y | Z
Trang 138R | S | T | U | V | W | X | Y | Z
Trang 140Printed in the United States of America
Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North,Sebastopol, CA 95472
O'Reilly & Associates books may be purchased for educational, business, orsales promotional use Online editions are also available for most titles
(http://safari.oreilly.com) For more information contact our
corporate/institutional sales department: 800-998-9938 or
corporate@oreilly.com
Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo areregistered trademarks of O'Reilly & Associates, Inc Many of the designationsused by manufacturers and sellers to distinguish their products are claimed astrademarks Where those designations appear in this book, and O'Reilly &Associates, Inc was aware of a trademark claim, the designations have beenprinted in caps or initial caps The association between the image of an emu andPerl/Tk is a trademark of O'Reilly & Associates, Inc
While every precaution has been taken in the preparation of this book, the
publisher and authors assume no responsibility for errors or omissions, or fordamages resulting from the use of the information contained herein
Copyright © 2002 O'Reilly & Associates All rights reserved.
Trang 142Each item can also have a tag (or more than one tag) associated with it We haveseen tags used before in the Text widget, where sections of text could be
assigned a tag A tag can be assigned when the item is created, or you can usethe addtag method to assign a tag after the item has been created
There are two special tags that are assigned and maintained automatically:
"current" and "all" The "all" tag refers to all the items in the Canvas The
"current" tag refers to the topmost item that the mouse cursor is over If themouse cursor is outside the Canvas widget or not over an item, the "current"
Tags can also be logical expressions by using the operators: &&, ||, ^, !, andparenthetical subexpressions For example:
display list is created as you add items to the Canvas and can be
manipulated with the raise and lower methods
$canvas->addtag("newtag", "all");
Trang 143"newtag" in their tag lists
$canvas->addtag("newtag", "below", tag/id);
The "newtag" tag is added to the item that is directly below the tag/id
item If more than one item matches the below tag/id search, the lowestitem in the list will be used
$canvas->addtag("newtag", "closest", x, y);
Use the "closest" tag to select the item closest to the (x, y) coordinates (inCanvas coordinates) If more than one item matches, the last one found isused
There are two more possible arguments for this form of addtag You can specify
a number that indicates how far out from the (x, y) coordinates items are to beconsidered For instance, if you want an item that is within 10 pixels to be
considered "closest", make the call as follows:
$canvas->addtag("newtag", "closest", 50, 100, 10);
You can also specify a starting tag or ID to start a search The call would thenlook like this:
$canvas->addtag("newtag", "closest", x, y, 10, $tag_or_id);
Using this form, you can loop through all the closest items
$canvas->addtag("newtag", "enclosed", x1, y1, x2, y2);
You can use the "enclosed" form of addtag to assign the same tag to
several items within the area bounded by (x1, y1) to (x2, y2) Items will begiven "newtag" only if they are completely within the area The coordinatesmust make sense when you specify them: x1 < x2 and y1 < y2
$canvas->addtag("newtag", "overlapping", x1, y1, x2, y2);
To assign tags to any item that has any part inside a bounded region, use
"overlapping" instead of "enclosed" Even if the item has only one pixelinside this area, it will still count All other rules for the bounding area arethe same as for "enclosed"
$canvas->addtag("newtag", "withtag", tag/id);
Assigns "newtag" to all the items with the tag or ID specified
9.9.1 Binding Items Using Tags
Trang 144(Remember, if you want to add a normal binding to the Canvas widget itself, youmust use CanvasBind instead of just bind.)
The general form of bind is as follows:
Here is an example that changes the color of any items tagged with "blue" whenthe mouse is over them:
Trang 145Copyright © 2002 O'Reilly & Associates All rights reserved.
Trang 147The final geometry manager we want to cover is form Recently added into thePerl/Tk distribution, form is a very different geometry manager than those we'veseen so far To try and compare it with what we already know, it behaves like acombination of pack and place Using form, it is legal to overlap widgets (asyou would with place), but you can also display the widgets relative to eachother and stretch them out to fill the entire available area and resize with thewindow (as you would with pack) The combination of all these abilities results
in a powerful geometry manager
When using form, each edge of a widget can be attached to something: the
container's grid, another widget, or nothing at all You can also use springs topush your widgets around in the window based on the strength (or weight) of thespring As with the other geometry managers, you can add padding to your
Trang 149demonstrates using a grid attachment:
foreach (1 5) {
# Create Buttons and attach them to grid at intervals of 5 $mw->Button(-text => $_ * 5)->form(-left => '%' $_ * 5, -top => '%' $_ * 5); }
This code creates five widgets, putting them on the grid at (5, 5), (10, 10), (15,15), and so on Take a look at
Figure 2-48 and you'll see what happens when we resize this window Noticethat the widgets overlap each other and move as the window is resized Thisdemonstrates that the grid size stays the same as the window resizes, and thewidgets move with the grid If you make the window large enough, the widgets
no longer overlap
Figure 2-48 How the form grid works (both windows have grid sizes of 100x100)
For the previous example, we used the -top and -left options to specify where
to locate the widgets in the window If you call form with no options at all, eachwidget is put at (0, 0), piled one on top of the other The order in which the
widgets are created is important in this case, because the last one created is
placed on top of the pile
You can change the size of the widget by attaching opposite sides to differentpoints in the grid The widget will resize with the window (see
Figure 2-49):
Trang 150$b1 = $mw->Button(-text => "small")->form(-left => '%10');
# Second Button is attached to $b1 on left, and grid 70 on right
$mw->Button(-text => "BIG")->form(-left => $b1, -right => '%70', -top => '%0', -bottom => '%80');
To shift your widget 10 pixels to the right of the grid coordinate (5, 5), you
would use an anonymous array to specify the whole attachment:
$mw->Button(-text => "shifted right")->form(-left => ['%5', 10], -top => '%5');
If the offset is 0, you don't need to specify it at all
2.4.2.2 Widget-to-widget attachments
There are two ways to attach one widget to another: by using the same side (bothtop, both bottom, and so on), or by using opposite sides Any widgets attached toone another must be managed by form in the same parent container
Here's an example of opposite side attachment:
$thisbutton->form(-left => $b1);
You would read that in English as "Attach the left side of $thisbutton to the
Trang 151-right, -top, or -bottom) applies to the widget on which you are currently
calling form If you want a bit of space between two widgets, add an offset to the
Trang 155if ($rightspring ne '') { push (@args, ('-rightspring', $rightspring)); }
if ($rightspring ne '') { push (@args, ('-rightspring', $rightspring)); } print "ARGS: @args\n";
Trang 156print "Widgets in $parent are @widgets\n";
2.4.4.5 Circular dependency check
You need to be careful that you don't end up with a circular reference whendoing widget attachments To check your setup, you can call $parent-
>formCheck This will return true if it finds a circular dependency and false if itdoesn't
2.3 The place Geometry Manager 2.5 GeometryManagement Summary
Copyright © 2002 O'Reilly & Associates All rights reserved.
Trang 158Contents:
Using the Command Line Using the Option Database
When writing Perl/Tk applications, we can change the look of the applicationdramatically by using different options when creating widgets We can give our
users a similar type of control using the resource database or command-line
options The user has the ability to change the appearance of almost anything,
from the width of widget edges and the fonts used to display text to the cursorshown as the mouse passes over a widget A change can be global to every
application that honors the option database or so specific that it changes a singleoption of a single widget
In the first part of this chapter, we'll cover the ways users can change these
visual aspects from the command line Later in the chapter, we'll give you moreideas on how to utilize a resource database
The term resource database originated in the X Window System Essentially, theresource database provides user-specified values for widget configuration
options When creating a new widget, Tk queries the resource database for alloptions that the programmer did not explicitly specify on the widget creation
command If an option/value pair (sometimes called a resource) isn't found in
the resource database, Tk uses the option's default value provided by the widget'sclass
Actually, a resource is a bit more complicated Although the resource identifies asingle option/value pair, it may apply to more than a single widget Using classnames and the wildcard character (*), it's possible to pattern match multiplewidgets Each of those widgets subsequently has that particular option
configured
So, an option database resource is really a pattern/value pair Resources have thisgeneral syntax:
pattern : value