Muutke küpsiste eelistusi

Tcl/Tk: A Developer's Guide 3rd edition [Pehme köide]

(CEO, Noumena Corporation, Dexter, Michigan, USA)
Teised raamatud teemal:
Teised raamatud teemal:

Newly updated with over 150 pages of material on the latest Tcl extensions, Tcl/Tk: A Developer’s Guide is a unique practical tutorial for professional programmers and beginners alike. Starting with a clear picture of the basics, Tcl/Tk covers the variety of tools in this "Swiss army knife" of programming languages, giving you the ability to enhance your programs, extend your application's capabilities, and become a more effective programmer.

This updated edition covers all of the new features of version 8.6, including object-oriented programming and the creation of megawidgets, existing data structure implementations, themed widgets and virtual events. Extensive code snippets and online tutorials in various languages will give you a firm grasp on how to use the Tcl/Tk libraries and interpreters and, most importantly, on what constitutes an effective strategy for using Tcl/Tk.

  • Includes the latest features of Tcl/Tk 8.6
  • Covers Tcl development tools, popular extensions, and packages to allow developers to solve real-world problems with Tcl/Tk immediately
  • Provides straightforward explanations for beginners and offers tips, style guidelines, and debugging techniques for advanced users
  • Companion website includes Tcl/Tk tutorials, applications, distributions, and more tools

Arvustused

"The best computer programmers are astonishingly more productive than average. One reason is that they use good tools, and they use them well. Clif Flynt's Tcl/Tk: A Developer's Guide, Second Edition helps you improve your effectiveness as a developer in both of these ways. Tcl is a software language with a great return on investmentit achieves portable, powerful, economical results with great economy. Just a few lines of Tcl are enough to create applications that are both interesting and useful. Clif draws on his deep experience as a front-line developer to help you get the most out of Tcl. He writes clearly, and has organized his book with instructive examples that teach the essentials of Tcl. He covers the right material too: Tcl/Tk packs in not just such long-standing Tcl strengths such as its easy networking and graphical user interface, but also the latest breakthroughs with internationalization, widget upgrades, and StarPacks. Want to take your programming to the next level? Get Tcl/Tk: A Developer's Guide, Second Edition." Cameron Laird is vice president of Phaseit, Inc. (http://phaseit.net), where he specializes in Rapid Enterprise Integration with Tcl and related tools. His frequent publications on information technology include the popular "Regular Expressions" column (http://regularexpressions.com)

Muu info

Comprehensive tutorial and reference guide to becoming a more effective programmer.
Foreword xvii
Preface xix
Acknowledgments xxi
Introduction xxiii
Chapter 1 Tcl/Tk Features
1(16)
1.1 Tcl Overview
2(4)
1.1.1 The Standard Tcl Distribution
3(1)
1.1.2 Documentation
3(3)
1.2 Tcl as a Glue Language
6(2)
1.2.1 Tcl Scripts Compared with UNIX Shell Scripts
7(1)
1.2.2 Tcl Scripts Compared with MS-DOS .bat Files
7(1)
1.3 Tcl as a General-purpose Interpreter
8(3)
1.3.1 Tcl/Tk Compared to Visual Basic
9(1)
1.3.2 Tcl/Tk Compared to Perl
9(1)
1.3.3 Tcl/Tk Compared to Python
10(1)
1.3.4 Tcl/Tk Compared to Java
10(1)
1.4 Tcl as an Extensible Interpreter
11(1)
1.5 Tcl as an Embeddable Interpreter
11(1)
1.6 Tcl as a Rapid Development Tool
12(1)
1.7 GUI-based Programming
13(1)
1.8 Shipping Products
13(1)
1.9 Bottom Line
13(1)
1.10 Problems
14(3)
Chapter 2 The Mechanics of Using the Tcl and Tk Interpreters
17(18)
2.1 The Tclsh and wish Interpreters
17(5)
2.1.1 Starting the tclsh and wish Interpreters
17(1)
2.1.2 Starting tclsh or wish under UNIX
18(1)
2.1.3 Starting tclsh or wish under Microsoft Windows
19(1)
2.1.4 Starting tclsh or wish on the Mac
20(2)
2.1.5 Exiting Tclsh or wish
22(1)
2.2 Using tclsh/wish Interactively
22(2)
2.2.1 Tclsh as a Command Shell
22(1)
2.2.2 Tk Console (tkcon)---An Alternative Interactive tclsh/wish Shell
23(1)
2.2.3 Evaluating Scripts Interactively
23(1)
2.3 Evaluating Tcl Script Files
24(9)
2.3.1 The Tcl Script File
24(1)
2.3.2 Evaluating Tcl Script Files
25(1)
2.3.3 Evaluating a Tcl Script File under UNIX
26(1)
2.3.4 Evaluating a Tcl Script File under Microsoft Windows
27(5)
2.3.5 Evaluating a Tcl Script on the Mac
32(1)
2.4 Bottom Line
33(1)
2.5 Problems
33(2)
Chapter 3 Introduction to the Tcl Language
35(56)
3.1 Overview of the Basics
36(4)
3.1.1 Syntax
36(1)
3.1.2 Grouping Words
37(1)
3.1.3 Comments
38(1)
3.1.4 Data Representation
38(1)
3.1.5 Command Results
39(1)
3.1.6 Errors
40(1)
3.2 Command Evaluation and Substitutions
40(4)
3.2.1 Substitution
40(1)
3.2.2 Controlling Substitutions with Quotes, Curly Braces, and the Backslash
41(2)
3.2.3 Steps in Command Evaluation
43(1)
3.3 Data Types
44(26)
3.3.1 Assigning Values to Variables
44(1)
3.3.2 Strings
45(2)
3.3.3 String Processing Commands
47(7)
3.3.4 Lists
54(1)
3.3.5 List Processing Commands
55(6)
3.3.6 Dictionaries
61(4)
3.3.7 Associative Arrays
65(1)
3.3.8 Associative Array Commands
65(2)
3.3.9 Binary Data
67(3)
3.3.10 Handles
70(1)
3.4 Arithmetic and Boolean Operations
70(13)
3.4.1 Math Operations
70(4)
3.4.2 Conditionals
74(4)
3.4.3 Looping
78(2)
3.4.4 Exception Handling in Tcl
80(3)
3.5 Modularization
83(3)
3.5.1 Procedures
84(1)
3.5.2 Loading Code from a Script File
84(1)
3.5.3 Examining the State of the Tcl Interpreter
85(1)
3.6 Bottom Line
86(2)
3.7 Problems
88(3)
Chapter 4 Navigating the File System, Basic I/O and Sockets
91(26)
4.1 Navigating the File System
91(5)
4.1.1 Constructing File Paths
93(3)
4.2 Properties of File System Items
96(2)
4.3 Removing Files
98(1)
4.4 Input/Output in Tcl
99(5)
4.4.1 Output
99(1)
4.4.2 Input
100(1)
4.4.3 Creating a Channel
101(3)
4.4.4 Closing Channels
104(1)
4.5 Sockets
104(8)
4.5.1 Using a Client Socket
105(2)
4.5.2 Controlling Data Flow
107(2)
4.5.3 Server Sockets
109(3)
4.6 Bottom Line
112(1)
4.7 Problems
113(4)
Chapter 5 Using Strings and Lists
117(28)
5.1 Converting a String into a List
117(1)
5.2 Examining the List with a for Loop
118(3)
5.3 Using the foreach Command
121(1)
5.4 Using string match Instead of string first
121(1)
5.5 Using lsearch
122(2)
5.6 The regexp Command
124(9)
5.6.1 Regular Expression Matching Rules
124(2)
5.6.2 Examples of Regular Expressions
126(1)
5.6.3 Advanced and Extended Regular Expression Rules
126(5)
5.6.4 Back to the Searching URLs
131(2)
5.7 Creating a Procedure
133(4)
5.7.1 The proc Command
133(1)
5.7.2 A findUrl Procedure
134(1)
5.7.3 Variable Scope
135(1)
5.7.4 Global Information Variables
136(1)
5.8 Making a Script
137(2)
5.8.1 The Executable Script
137(2)
5.9 Speed
139(1)
5.9.1 Comparison of Execution Speeds (Linux P4 @ 1.6 GHz)
140(1)
5.10 Bottom Line
140(1)
5.11 Problems
141(4)
Chapter 6 Complex Data Structures with Lists, Arrays and Dicts
145(36)
6.1 Using the Tcl List
146(5)
6.1.1 Manipulating Ordered Data with Lists
146(2)
6.1.2 Manipulating Data with Keyed Lists
148(3)
6.2 Using the Dict
151(5)
6.2.1 Grouping Related Values
152(4)
6.3 Using the Associative Array
156(1)
6.4 Trees in Tcl
157(2)
6.5 Tcl and SQL
159(16)
6.5.1 SQL Basics
159(3)
6.5.2 Using tdbc
162(5)
6.5.3 Using Referenced Tables
167(8)
6.6 Performance
175(2)
6.7 Bottom Line
177(1)
6.8 Problems
178(3)
Chapter 7 Procedure Techniques
181(24)
7.1 Arguments to Procedures
181(3)
7.1.1 Variable Number of Arguments to a Procedure
182(1)
7.1.2 Default Values for Procedure Arguments
182(2)
7.2 Renaming or Deleting Commands
184(1)
7.3 Getting Information about Procedures
185(2)
7.4 Substitution and Evaluation of Strings
187(3)
7.4.1 Performing Variable Substitution on a String
187(1)
7.4.2 Evaluating a String as a Tcl Command
188(2)
7.5 Working with Global and Local Scopes
190(7)
7.5.1 Global and Local Scope
191(6)
7.6 Making a Tcl Object
197(3)
7.6.1 An Object Example
197(3)
7.7 Bottom Line
200(1)
7.8 Problems
201(4)
Chapter 8 Namespaces, Packages and Modules
205(36)
8.1 Namespaces and Scoping Rules
205(20)
8.1.1 Namespace Scope
206(1)
8.1.2 Namespace Naming Rules
206(2)
8.1.3 Accessing Namespace Entities
208(1)
8.1.4 Why Use Namespaces?
208(1)
8.1.5 The namespace and variable Commands
208(4)
8.1.6 Creating and Populating a Namespace
212(3)
8.1.7 Namespace Nesting
215(7)
8.1.8 Namespace Ensembles
222(3)
8.2 Packages
225(5)
8.2.1 How Packages Work
226(1)
8.2.2 Internal Details: Files and Variables Used with Packages
226(1)
8.2.3 Package Commands
227(1)
8.2.4 Version Numbers
228(1)
8.2.5 Package Cookbook
229(1)
8.3 Tcl Modules
230(1)
8.4 Namespaces and Packages
231(3)
8.5 Hanoi with a Stack Namespace and Package
234(2)
8.6 Conventions and Caveats
236(1)
8.7 Bottom Line
236(1)
8.8 Problems
237(4)
Chapter 9 Basic Object-Oriented Programming in Tcl
241(26)
9.1 Creating a TclOO Class and Object
242(21)
9.1.1 Constructor and Destructor
245(2)
9.1.2 Methods
247(4)
9.1.3 Inheritance
251(9)
9.1.4 Filters
260(3)
9.2 Bottom Line
263(1)
9.3 Problems
264(3)
Chapter 10 Advanced Object-Oriented Programming in Tcl
267(54)
10.1 Modifying Classes and Objects
268(12)
10.1.1 Modifying Classes
268(7)
10.1.2 Modifying Inheritance
275(2)
10.1.3 Modifying Class, Constructor, Variables and Destructor
277(1)
10.1.4 Static Methods and Variables I
278(2)
10.2 Modifying Objects
280(4)
10.2.1 Changing an Object's Class
280(3)
10.2.2 Defining Per-object Mixins
283(1)
10.2.3 Adding a Method to an Object
284(1)
10.3 Examining Classes and Objects
284(17)
10.3.1 Evaluation of Chains
285(7)
10.3.2 Examining Methods
292(6)
10.3.3 Examining Inheritance
298(1)
10.3.4 Getting a List of Base Classes
299(2)
10.4 Examining Objects
301(4)
10.5 Using TclOO with Callbacks
305(3)
10.6 Adding New Functionality to TclOO
308(9)
10.6.1 Static Variables II
308(2)
10.6.2 Static Methods II
310(2)
10.6.3 Aggregated Objects That Modify the Possessor
312(3)
10.6.4 Objects That Grow and Change
315(2)
10.7 Bottom Line
317(1)
10.8 Problems
318(3)
Chapter 11 Introduction to Tk Graphics
321(70)
11.1 Creating a Widget
322(1)
11.2 Conventions
323(1)
11.2.1 Widget Naming Conventions
323(1)
11.2.2 Color Naming Conventions
323(1)
11.2.3 Dimension Conventions
323(1)
11.3 Common Options
324(1)
11.4 Determining and Setting Options
325(2)
11.5 The Basic Widgets
327(1)
11.6 Introducing Widgets: label, button, and entry
328(8)
11.6.1 The label Widget
328(1)
11.6.2 The button Widget
329(1)
11.6.3 The entry Widget
330(3)
11.6.4 Using Namespaces or TclOO with Widgets
333(3)
11.7 Application Layout: Geometry Managers and Container Widgets
336(16)
11.7.1 Container Widgets: frame, label frame, panedwindow
336(8)
11.7.2 Widget Layout: place, pack, and grid
344(8)
11.8 Selection Widgets: radiobutton, checkbutton, menu, and listbox
352(20)
11.8.1 Radiobutton and Checkbutton
353(3)
11.8.2 Pull-down Menus: menu, menubutton, and Menubars
356(11)
11.8.3 Selection Widgets: Listbox
367(5)
11.9 Scrollbar
372(7)
11.9.1 The Basic scrollbar
372(1)
11.9.2 Scrollbar Details
373(3)
11.9.3 Intercepting scrollbar Commands
376(3)
11.10 The scale Widget
379(2)
11.11 New Windows
381(1)
11.12 Interacting with the Event Loop
382(1)
11.13 Scheduling the Future: after
383(3)
11.13.1 Canceling the Future
385(1)
11.14 Bottom Line
386(2)
11.15 Problems
388(3)
Chapter 12 Using the canvas Widget
391(60)
12.1 Overview of the canvas Widget
391(1)
12.1.1 Identifiers and Tags
391(1)
12.1.2 Coordinates
392(1)
12.1.3 Binding
392(1)
12.2 Creating a canvas Widget
392(2)
12.3 Creating Displayable canvas Items
394(4)
12.3.1 The Line Item
394(1)
12.3.2 The Arc Item
395(1)
12.3.3 The Rectangle Item
395(1)
12.3.4 The Oval Item
395(1)
12.3.5 The Polygon Item
395(1)
12.3.6 The Text Item
396(1)
12.3.7 The Bitmap Item
396(1)
12.3.8 The Image Item
397(1)
12.3.9 An Example
397(1)
12.4 More canvas Widget Subcommands
398(14)
12.4.1 Modifying an Item
398(1)
12.4.2 Changing the Display Coordinates of an Item
399(2)
12.4.3 Moving an Item
401(2)
12.4.4 Finding Items, and Raising and Lowering Items
403(4)
12.4.5 Fonts and Text Items
407(3)
12.4.6 Using a Canvas Larger than the View
410(2)
12.5 The bind and focus Commands
412(7)
12.5.1 The bind Command
412(3)
12.5.2 The canvas Widget bind Subcommand
415(3)
12.5.3 Focus
418(1)
12.6 Creating a Widget
419(8)
12.7 A Help Balloon: Interacting with the Window Manager
427(9)
12.8 The image Object
436(11)
12.8.1 The image Command
437(1)
12.8.2 Bitmap Images
438(1)
12.8.3 Photo Images
439(3)
12.8.4 Revisiting the delayButton Widget
442(5)
12.9 Bottom Line
447(1)
12.10 Problems
448(3)
Chapter 13 The text Widget and html lib
451(44)
13.1 Overview of the text Widget
451(4)
13.1.1 Text Location in the text Widget
452(2)
13.1.2 Tag Overview
454(1)
13.1.3 Mark Overview
454(1)
13.1.4 Image Overview
455(1)
13.1.5 Window Overview
455(1)
13.2 Creating a text Widget
455(2)
13.3 Text Widget Subcommands
457(21)
13.3.1 Inserting and Deleting Text
458(2)
13.3.2 Searching Text
460(3)
13.3.3 The mark Subcommands
463(3)
13.3.4 Tags
466(8)
13.3.5 Inserting Images and Widgets into a text Widget
474(4)
13.4 HTML Display Package
478(12)
13.4.1 Displaying HTML Text
478(2)
13.4.2 Using html_library Callbacks: Loading Images and Hypertext Links
480(6)
13.4.3 Interactive Help with the text Widget and htmllib
486(4)
13.5 Bottom Line
490(2)
13.6 Problems
492(3)
Chapter 14 Tk Megawidgets
495(76)
14.1 Standard Dialog Widgets
495(11)
14.1.1 tk_optionMenu
496(1)
14.1.2 tk_chooseColor
497(1)
14.1.3 tk_getOpenFile
498(2)
14.1.4 tk_getSaveFile
500(1)
14.1.5 tk_messageBox
501(1)
14.1.6 tk_dialog
502(1)
14.1.7 tk_popup
503(3)
14.2 Megawidget Building Philosophy
506(3)
14.2.1 Display in Application Window or Main Display?
506(1)
14.2.2 Modal versus Modeless Operation
507(1)
14.2.3 Widget Access Conventions
507(1)
14.2.4 Widget Frames
507(1)
14.2.5 Configuration
507(1)
14.2.6 Access to Subwidgets
508(1)
14.2.7 Following Tk Conventions
509(1)
14.3 Functionality That Makes Megawidgets Possible
509(2)
14.3.1 The rename Command
509(1)
14.3.2 The option Command
510(1)
14.3.3 The - class Option
511(1)
14.4 Building a Megawidget
511(1)
14.5 A Scrolling listbox Megawidget
512(11)
14.5.1 Scrolled listbox Description
512(2)
14.5.2 Using the scrolledLB
514(1)
14.5.3 Implementing the Scrollable listbox
515(2)
14.5.4 The scrolledLB Code
517(6)
14.6 Namespaces and Tk Widgets
523(10)
14.6.1 Creating a Multiple Language Megawidget
524(9)
14.7 Incorporating a Megawidget into a Larger Megawidget
533(9)
14.8 Making a Modal Megawidget: The grab and tkwait Commands
542(8)
14.8.1 The grab Command
543(1)
14.8.2 The tkwait Command
544(1)
14.8.3 The Modal Widget Code
545(5)
14.9 Automating Megawidget Construction
550(1)
14.9.1 Building Namespace Megawidgets Summary
550(1)
14.10 Building Megawidgets with TclOO
550(17)
14.10.1 Using a Wrapper Proc for TclOO-Based Widgets
551(6)
14.10.2 Using a Class Name as a Widget Type
557(3)
14.10.3 Callbacks into TclOO Widgets
560(1)
14.10.4 Combining TclOO Compound Widgets
561(3)
14.10.5 Adding New Functionality to a TclOO Widget
564(3)
14.11 Bottom Line
567(1)
14.12 Problems
568(3)
Chapter 15 Extending Tcl
571(68)
15.1 Functional View of a Tcl Extension
572(14)
15.1.1 Overview
572(1)
15.1.2 Initialize Any Persistent Data Structures
572(1)
15.1.3 Register New Commands with the Interpreter
573(1)
15.1.4 Accept Data from Tcl Interpreter
574(4)
15.1.5 Returning Results
578(3)
15.1.6 Returning Status to the Script
581(1)
15.1.7 Dealing with Persistent Data
582(4)
15.2 Building an Extension
586(3)
15.2.1 Structural Overview of an Extension
586(1)
15.2.2 Naming Conventions
586(3)
15.3 An Example
589(27)
15.3.1 demoInt.h
591(2)
15.3.2 demoInit. c
593(2)
15.3.3 demoCmd. c
595(7)
15.3.4 demoDemo. c
602(14)
15.4 Complex Data
616(10)
15.5 Embedding the Tcl Interpreter
626(7)
15.6 Building Tcl and Tk from Sources
633(1)
15.7 Bottom Line
634(3)
15.8 Problems
637(2)
Chapter 16 Applications with Multiple Environments
639(26)
16.1 Event Loop
640(12)
16.1.1 Using fileevent
640(4)
16.1.2 Using trace
644(2)
16.1.3 Using after
646(1)
16.1.4 Using bind
647(1)
16.1.5 Tcl Interpreters
648(4)
16.2 Threads
652(5)
16.3 Embedded Tcl Interp and Threading
657(5)
16.4 Bottom Line
662(1)
16.5 Problems
663(2)
Chapter 17 Extensions and Packages
665(38)
17.1 [ incr Tcl]
667(3)
17.2 expect
670(5)
17.3 TclX
675(4)
17.4 TDBC
679(7)
17.5 Rivet
686(10)
17.6 BWidgets
696(6)
17.7 Graphics Extensions: Img
702(1)
17.8 Bottom Line
702(1)
Chapter 18 Programming Tools
703(30)
18.1 Code Formatter
705(4)
18.1.1 frink
705(4)
18.2 Code Checkers
709(5)
18.2.1 tcl Check
709(1)
18.2.2 nagelfar
710(4)
18.3 Debuggers
714(3)
18.3.1 debug
714(3)
18.3.2 Graphic Debuggers
717(1)
18.4 Exercising and Regression Testing
717(4)
18.4.1 TkTest
717(4)
18.5 Packaging Tools
721(3)
18.5.1 freewrap
722(1)
18.5.2 Starkit and Starpack
722(2)
18.6 Tcl Extension Generators
724(4)
18.6.1 SWIG
724(3)
18.6.2 CriTcl
727(1)
18.7 Integrated Development Environments
728(4)
18.7.1 KomodoEdit
729(1)
18.7.2 Komodo
730(1)
18.7.3 MyrmecoX
731(1)
18.8 Bottom Line
732(1)
Chapter 19 Tips and Techniques
733(36)
19.1 Debugging Techniques
733(15)
19.1.1 Reading the Error Messages
733(2)
19.1.2 Instrumenting Code to Generate Log Files
735(4)
19.1.3 Run Script in Interactive Mode
739(2)
19.1.4 Use puts to Print the Value of Variables or Lines to Be Evaluated
741(2)
19.1.5 Extract Portions of Script for Unit Testing
743(1)
19.1.6 Attach a tkcon Session to Application
743(1)
19.1.7 Create a Console Window under Windows
744(1)
19.1.8 Create a Command Window to Interact with Your Application
744(3)
19.1.9 Use a Second wish Interpreter for Remote Debugging
747(1)
19.2 Tcl as a Glue Language: The exec Command
748(3)
19.2.1 Creating a G-zipped tar Archive under UNIX
749(1)
19.2.2 Creating a Zip Archive under Windows
750(1)
19.3 Common Mistakes
751(3)
19.3.1 Problems Using the exec Command
751(1)
19.3.2 Calculating the Time: Numbers in Tcl
752(1)
19.3.3 set, lset, lappend, append, and incr Are the Only Tcl Commands That Modify an Argument
753(1)
19.3.4 The incr Command Works Only with Integers
753(1)
19.3.5 The upvar Command Takes a Name, Not a Value
753(1)
19.3.6 Changes to Widgets Do Not Appear Until the Event Loop Is Processed
754(1)
19.3.7 Be Aware of Possible % Sign Reduction
754(1)
19.4 Coding Tips and Techniques
754(5)
19.4.1 Use the Interpreter to Parse Input
754(4)
19.4.2 Handling Platform-Specific Code
758(1)
19.5 Optimization
759(3)
19.6 Techniques for Improving Performance
762(5)
19.7 Bottom Line
767(2)
Index 769
Clif Flynt is a professional programmer and has been a Tcl advocate since 1994. He has developed Tcl applications for the e-commerce, factory control, computer-based education, network analysis, games, firewall configuration, systems administration, and more. He has taught Tcl/Tk seminars in colleges and corporations around the world and writes regularly on Tcl/Tk for the developer community.