Practical Programming in Tcl and Tk
This is the third edition of Brent Welch's best-seller Practical Programming in Tcl and Tk. The book needs to be revised to cover Tcl/Tk 8.1., which will be made available.
- Mixed media product | 832 pages
- 178 x 230 x 32mm | 1,401.61g
- 10 Nov 1999
- Pearson Education (US)
- Prentice Hall
- Upper Saddle River, United States
- 3rd edition
Table of contents
I. TCL BASICS. 1. Tcl Fundamentals. Tcl Commands. Hello, World! Variables. Command Substitution. Math Expressions. Backslash Substitution. Grouping with Braces and Double Quotes. Square Brackets Do Not Group. Grouping before Substitution. Grouping Math Expressions with Braces. More Substitution Examples. Procedures. A Factorial Example. More about Variables. Funny Variable Names. The unset Command. Using info to Find Out about Variables. More about Math Expressions. Comments. Substitution and Grouping Summary. Fine Points. Reference. Backslash Sequences. Arithmetic Operators. Built-in Math Functions. Core Tcl Commands.2. Getting Started. The source Command. UNIX Tcl Scripts. Windows 95 Start Menu. The Macintosh and ResEdit. The console Command. Command-Line Arguments. Command-Line Options to Wish. Predefined Variables.3. The Guestbook CGI Application. A Quick Introduction to HTML. CGI for Dynamic Pages. The guestbook.cgi Script. Using a Script Library File. Beginning the HTML Page. Simple Tags and Hypertext Links. Using a Tcl Array for the Database. Sample Output. Defining Forms and Processing Form Data. The newguest.html Form. The newguest.cgi Script. The cgi.tcl Package. Next Steps.4. String Processing in Tcl. The string Command. String Indices. Strings and Expressions. String Matching. Character Classes. Mapping Strings. The append Command. The format Command. The scan Command. The binary Command. Format Templates. Examples. Binary Data and File I/O. Related Chapters.5. Tcl Lists. Tcl Lists. Constructing Lists. The list command. The lappend Command. The concat Command. Getting List Elements: llength, lindex, and lrange. Modifying Lists: linsert and lreplace. Searching Lists: lsearch. Sorting Lists: lsort. The split Command. The join Command. Related Chapters.6. Control Structure Commands. If Then Else. Switch. Comments in switch Commands. While. Foreach. Multiple Loop Variables. Multiple Value Lists. For. Break and Continue. Catch. Catching More Than Errors. Error. Return.7. Procedures and Scope. The proc Command. Changing Command Names with rename. Scope. The global Command. Call by Name Using upvar. Variable Aliases with upvar. Associating State with Data. Namespaces and upvar. Commands That Take Variable Names.8. Tcl Arrays. Array Syntax. Complex Indices. Array Variables. The array Command. Converting Between Arrays and Lists. Passing Arrays by Name. Building Data Structures with Arrays. Simple Records. A Stack. A List of Arrays. A Simple In-Memory Database.9. Working with Files and Programs. Running Programs with exec. The auto_noexec Variable. Limitations of exec on Windows. AppleScript on Macintosh. The file Command. Cross-Platform File Naming. Building up Pathnames: file join. Chopping Pathnames: split, dirname, tail. Manipulating Files and Directories. Copying Files. Creating Directories. Deleting Files. Renaming Files and Directories. File Attributes. Input/Output Command Summary. Opening Files for I/O. Opening a Process Pipeline. Expect. Reading and Writing. The puts and gets Commands. The read Command. Platform-Specific End of Line Characters. Random Access I/O. Closing I/O Channels. The Current Directory Ã· cd and pwd. Matching File Names with glob. Expanding Tilde in File Names. The exit and pid Commands. Environment Variables. The registry Command.II. ADVANCED TCL. 10. Quoting Issues and Eval. Constructing Code with the list Command. The eval Command. Commands That Concatenate Their Arguments. Commands That Use Callbacks. Command Prefix Callbacks. Constructing Procedures Dynamically. Exploiting the concat inside eval. Using eval in a Wrapper Procedure. Correct Quoting with eval. The uplevel Command. The subst Command. String Processing with subst.11. Regular Expressions. When to Use Regular Expressions. Avoiding a Common Problem. Regular Expression Syntax. Matching Characters. Character Sets. Quantifiers. Alternation. Anchoring a Match. Backslash Quoting. Matching Precedence. Capturing Subpatterns. Advanced Regular Expressions. Compatibility with Patterns in Tcl 8.0. Backslash Escape Sequences. Character Classes. Nongreedy Quantifiers. Bound Quantifiers. Back References. Look-ahead. Character Codes. Collating Elements. Equivalence Classes. Newline Sensitive Matching. Embedded Options. Expanded Syntax. Syntax Summary. The regexp Command. A Pattern to Match URLs. Sample Regular Expressions. The regsub Command. Transforming Data to Program with regsub. URL Decoding. CGI Argument Parsing. Decoding HTML Entities. A Simple HTML Parser. Stripping HTML Comments. Other Commands That Use Regular Expressions.12. Script Libraries and Packages. Locating Packages: The auto_path Variable. Using Packages. Loading Packages Automatically. Packages Implemented in C Code. Summary of Package Loading. The package Command. Libraries Based on the tclIndex File. The unknown Command. How Auto Loading Works. Disabling the Library Facility: auto_noload. Interactive Conveniences. Auto Execute. History. Abbreviations. Tcl Shell Library Environment. Locating the Tcl Script Library. tcl_findLibrary. Coding Style. A Module Prefix for Procedure Names. A Global Array for State Variables. The Official Tcl Style Guide.13. Reflection and Debugging. The clock Command. The info Command. Variables. Procedures. The Call Stack. Command Evaluation. Scripts and the Library. Version Numbers. Execution Environment. Cross-Platform Support. Tracing Variable Values. Read-Only Variables. Creating an Array with Traces. Interactive Command History. History Syntax. A Comparison to C Shell History Syntax. Debugging. Scripticsa TclPro. TclPro Debugger. TclPro Checker. TclPro Compiler. TclPro Wrapper. Other Tools. The tkinspect Program. The Tuba Debugger. The bgerror Command. The tkerror Command. Performance Tuning. Time stamps in a Log. The Tcl Compiler.14. Namespaces. Using Namespaces. Namespace Variables. Qualified Names. Command Lookup. Nested Namespaces. Importing and Exporting Procedures. Callbacks and Namespaces. Introspection. The namespace Command. Converting Existing Packages to use Namespaces. [incr Tcl] Object System. Notes. Names for Widgets, Images, and Interpreters. The variable command at the global scope. Auto Loading and auto_import. Namespaces and uplevel. Naming Quirks. Miscellaneous.15. Internationalization. Character Sets and Encodings. The System Encoding. File Encodings and fconfigure. Scripts in Different Encodings. Unicode and UTF-8. The Binary Encoding. Conversions Between Encodings. The encoding Command. Message Catalogs. Specifying a Locale. Managing Message Catalog Files. Message Catalogs and Namespaces. The msgcat package.16. Event-Driven Programming. The Tcl Event Loop. The after Command. The fileevent Command. The vwait Command. The fconfigure Command. Nonblocking I/O. The fblocked Command. Buffering. End of Line Translations. End of File Character. Serial Devices. Character Set Encodings. Configuring Read-Write Channels.17. Socket Programming. Client Sockets. Client Socket Options. Server Sockets. Server Socket Options. The Echo Service. Fetching a URL with HTTP. Proxy Servers. The HEAD Request. The GET and POST Requests. The fcopy Command. The http Package. http::config. http::geturl. http::formatQuery. http::reset. http::cleanup. Basic Authentication.18. TclHttpd Web Server. Integrating TclHttpd with your Application. TclHttpd Architecture. Domain Handlers. Connection State and Query Data. Returning Results. Application Direct URLs. Using Query Data. Returning Other Content Types. Document Types. HTML + Tcl Templates. Where to put your Tcl Code. Templates for Site Structure. Form Handlers. Application Direct Handlers. Template Form Handlers. Self Posting Forms. The form package. Programming Reference. Standard Application-Direct URLs. Status. Debugging. Administration. Sending Email. The TclHttpd Distribution. Quick Start. Inside the Distribution. Server Configuration. Command Line Arguments. Server Name and Port. User and Group ID. Webmaster Email. Document Root. Other Document Settings. Document Templates. Log Files. CGI Directories.19. Multiple Interpreters and Safe-Tcl. The interp Command. Creating Interpreters. The Interpreter Hierarchy. The Interpreter Name as a Command. Use list with interp eval. Safe Interpreters. Command Aliases. Alias Introspection. Hidden Commands. Substitutions. I/O from Safe Interpreters. The Safe Base. Security Policies. Limited Socket Access. Limited Temporary Files. Safe after Command.20. Safe-Tk and the Browser Plugin. Tk in Child Interpreters. Embedding Tk Windows. Safe-Tk Restrictions. The Browser Plugin. The embed_args and plugin Variables. Example Plugins. Setting Up the plugin. Plugin Environment Variables. UNIX Configuration. Windows Configuration. Macintosh Configuration. Security Policies and Browser Plugin. The Browser Package. Configuring Security Policies. The config/plugin.cfg File. Policy Configuration Files. Security Policy Features. Creating New Security Policies.III. TK BASICS. 21. Tk Fundamentals. Hello, World! in Tk. Naming Tk Widgets. Configuring Tk Widgets. Tk Widget Attributes and the Resource Database. The Tk Manual Pages. Summary of the Tk Commands.22. Tk by Example. ExecLog. Window Title. A Frame for Buttons. Command Buttons. A Label and an Entry. Key Bindings and Focus. A Resizable Text and Scrollbar. The Run Procedure. The Log Procedure. The Stop Procedure. Cross-Platform Issues. The Example Browser. More about Resizing Windows. Managing Global State. Searching through Files. Cascaded Menus. A Read-Only Text Widget. A Tcl Shell. Text Marks, Tags, and Bindings. Multiple Interpreters. Native Look and Feel.23. The Pack Geometry Manager. Packing toward a Side. Shrinking Frames and pack propagate. Horizontal and Vertical Stacking. The Cavity Model. Packing Space and Display Space. The -fill Option. Internal Padding with -ipadx and -ipady. External Padding with -padx and -pady. Resizing and -expand. Anchoring. Packing Order. Introspection. Pack the Scrollbar First. Choosing the Parent for Packing. Unpacking a Widget. Packer Summary. The pack Command. Window Stacking Order.24. The Grid Geometry Manager. A Basic Grid. The -sticky Setting. External Padding with -padx and -pady. Internal Padding with -ipadx and -ipady. Multiple Widgets in a Cell. Spanning Rows and Columns. Row and Column Constraints. Row and Column Padding. Minimum Size. Managing Resize Behavior. The grid Command.25. The Place Geometry Manager. place Basics. The Pane Manager. Parsing Arguments and Maintaining State. Sticky Geometry Settings. Event Bindings. Managing the Layout. The place Command.26. Binding Commands to Events. The bind Command. The bindtags Command. Focus and Key Events. Using break and continue in Bindings. Defining New Binding Tags. Event Syntax. Keyboard Events. Mouse Events. Other Events. Bindings on Top-level Windows. Modifiers. Event Sequences. Virtual Events. Event Keywords.IV. TK WIDGETS. 27. Buttons and Menus. Button Commands and Scope Issues. Buttons Associated with Tcl Variables. Button Attributes. Button Operations. Menus and Menubuttons. A Menu Bar. System Menus. Pop-Up Menus. Option Menus. Multicolumn Palette Menus. Keyboard Traversal. Manipulating Menus and Menu Entries. Menu Attributes. A Menu by Name Package. Menu Accelerators.28. The Resource Database. An Introduction to Resources. Resource Patterns. Loading Option Database Files. Adding Individual Database Entries. Accessing the Database. User-Defined Buttons. User-Defined Menus. Application and User Resources. Expanding Variables.29. Simple Tk Widgets. Frames and Toplevel Windows. Attributes for Frames and Toplevels. Embedding Other Applications. Toplevel Window Styles. The Label Widget. Label Width and Wrap Length. Label Attributes. The Message Widget. Message Attributes. Arranging Labels and Messages. The Scale Widget. Scale Bindings. Scale Attributes. Programming Scales. The bell Command.30. Scrollbars. Using Scrollbars. The Scrollbar Protocol. The Scrollbar set Operation. The xview and yview Operations. The Tk 3.6 Protocol. The Scrollbar Widget. Scrollbar Bindings. Scrollbar Attributes. Programming Scrollbars.31. The Entry Widget. Using Entry Widgets. Tips for Using Entry Widgets. The Entry Widget. Entry Attributes. Programming Entry Widgets.32. The Listbox Widget. Using Listboxes. Programming Listboxes. Listbox Bindings. Browse Select Mode. Single Select Mode. Extended Select Mode. Multiple Select Mode. Scroll Bindings. Listbox Attributes. Geometry Gridding.33. The Text Widget. Text Indices. Inserting and Deleting Text. Indexs Arithmetic. Comparing Indices. Text Marks. Mark Gravity. Text Tags. Tag Attributes. Mixing Attributes from Different Tags. Line Spacing and Justification. Tab Stops. The Selection. Tag Bindings. Searching Text. Embedded Widgets. Embedded Images. Looking inside the Text Widget. Looking at Tags. Looking at Marks. Dumping the Contents. Text Bindings. Text Operations. Text Attributes.34. The Canvas Widget. Canvas Coordinates. Hello, World! Canvas Tags. The Min Max Scale Example. Canvas Objects. Arc Items. Bitmap Items. Image Items. Line Items. Oval Items. Polygon Items. Rectangle Items. Text Items. Window Items. Canvas Operations. Generating Postscript. Canvas Attributes. Hints. Screen Coordinates vs Canvas Coordinates. Large Coordinate Spaces. Scaling and Rotation. Resources. Objects with Many Points. Selecting Canvas Items.V. TK DETAILS. 35. Selections and the Clipboard. The Selection Model. The selection Command. The clipboard Command. Selection Handlers. A Canvas Selection Handler.36. Focus, Grabs, and Dialogs. Standard Dialogs. Message Box. File Dialogs. Color Dialog. Custom Dialogs. Input Focus. The focus Command. Keyboard Focus Traversal. Grabbing the Focus. The tkwait Command. Destroying Widgets. The focus, grab, tkwait sequence. Prompter Dialog. Keyboard Shortcuts and Focus. Animation with the update Command.37. Tk Widget Attributes. Configuring Attributes. Size. Borders and Relief. The Focus Highlight. Padding and Anchors. Putting It All Together.38. Color, Images, and Cursors. Colors. Color Palettes. Color Values. Colormaps and Visuals. Bitmaps and Images. The image Command. Bitmap Images. The bitmap Attribute. Photo Images. The Text Insert Cursor. The Mouse Cursor.39. Fonts and Text Attributes. Naming a Font. Named Fonts. System Fonts. Unicode Fonts. X Font Names. Font Failures before Tk 8.0. Font Metrics. The font Command. Text Attributes. Layout. Selection Attributes. Gridding, Resizing, and Geometry. A Font Selection Application.40. Send. The send Command. Send and X Authority. The Sender Script. Communicating Processes. Remote eval through Sockets.41. Window Managers and Window Information. The wm Command. Size, Placement, and Decoration. Icons. Session State. Miscellaneous. The winfo Command. Sending Commands between Applications. Family Relationships. Size. Location. Virtual Root Window. Atoms and IDs. Colormaps and Visuals. The tk Command.42. Managing User Preferences. App-Defaults Files. Defining Preferences. The Preferences User Interface. Managing the Preferences File. Tracing Changes to Preference Variables. Improving the Package.43. A User Interface to Bindings. A Pair of Listboxes Working Together. The Editing Interface. Saving and Loading Bindings.VI. C PROGRAMMING. 44. C Programming and Tcl. Basic Concepts. Getting Started. C Command Procedures and Data Objects. SWIG. Tcl Initialization. Calling Out to Tcl Scripts. Using the Tcl C Library. Creating a Loadable Package. The load Command. The Package Initialization Procedure. Using Tcl_PkgProvide. A C Command Procedure. The String Command Interface. Result Codes from Command Procedures. Managing the String Result. The Tcl_Obj Command Interface. Managing Tcl_Obj Reference Counts. Modifying Tcl_Obj Values. Pitfalls of Shared Tcl_Obj Values. The blob Command Example. Creating and Destroying Hash Tables. Tcl_Alloc and Tcl_Free. Parsing Arguments and Tcl_GetIndexFromObj. Creating and Removing Elements from a Hash Table. Building a List. Keeping References to Tcl_Obj Values. Using Tcl_Preserve and Tcl_Release to Guard Data. Strings and Internationalization. The DString Interface. Character Set Conversions. Tcl_Main and Tcl_AppInit. Tk_Main. The Event Loop. Invoking Scripts from C. Variations on Tcl_Eval. Bypassing Tcl_Eval.45. Compiling Tcl and Extensions. Standard Directory Structure. The Source Distribution. The Installation Directory Structure. Building Tcl from Source. Configure and Autoconf. Standard Configure Flags. Installation. Using Stub Libraries. Using autoconf. The tcl.m4 File. Makefile Templates. The Sample Extension. configure.in. Makefile.in. Standard Header Files. Using the Sample Extension.46. Writing a Tk Widget in C. Initializing the Extension. The Widget Data Structure. The Widget Class Command. The Widget Instance Command. Configuring and Reconfiguring Attributes. Specifying Widget Attributes. Displaying the Clock. The Window Event Procedure. Final Cleanup.47. C Library Overview. An Overview of the Tcl C Library. Application Initialization. Creating and Deleting Interpreters. Creating and Deleting Commands. Dynamic Loading and Packages. Managing the Result String. Memory Allocation. Lists. Command Parsing. Command Pipelines. Tracing the Actions of the Tcl Interpreter. Evaluating Tcl Commands. Reporting Script Errors. Manipulating Tcl Variables. Evaluating Expressions. Converting Numbers. Tcl Objects. Primitive Object Types. String Object Types. ByteArrays for Binary Data. Dynamic Strings. Character Set Encodings. AssocData for per Interpreter Data Structures. Hash Tables. Option Processing. Regular Expressions and String Matching. Event Loop Implementation. File Handlers. Timer Events. Idle Callbacks. Input/Output. I/O Channel Drivers. Manipulating File Names. Examining the File System. Thread Support. Working with Signals. Exit Handlers. An Overview of the Tk C Library. Main Programs and Command-Line Arguments. Creating Windows. Application Name for Send. Configuring Windows. Window Coordinates. Window Stacking Order. Window Information. Configuring Widget Attributes. The Selection and Clipboard. Event Loop Interface. Handling Window Events. Event Bindings. Handling Graphic Protocol Errors. Using the Resource Database. Managing Bitmaps. Creating New Image Types. Using an Image in a Widget. Photo Image Types. Canvas Object Support. Geometry Management. String Identifiers (UIDS). Colors, Colormaps, and Visuals. 3D Borders. Mouse Cursors. Fonts and Text Display. Graphics Contexts. Allocate a Pixmap. Screen Measurements. Relief Style. Text Anchor Positions. Line Cap Styles. Line Join Styles. Text Justification Styles. Atoms. X Resource ID Management.VII. CHANGES. 48. Tcl 7.4/Tk 4.0. wish. Obsolete Features. The cget Operation. Input Focus Highlight. Bindings. Scrollbar Interface. pack info. Focus. The send Command. Internal Button Padding. Radiobutton Value. Entry Widget. Menus. Listboxes. No geometry Attribute. Text Widget. Color Attributes. Color Allocation and tk colormodel. Canvas scrollincrement. The Selection. The bell Command.49. Tcl 7.5/Tk 4.1. Cross-Platform Scripts. File Name Manipulation. Newline Translations. The tcl_platform Variable. The console Command. The clock Command. The load Command. The package Command. Multiple foreach loop variables. Event Loop Moves from Tk to Tcl. Network Sockets. info hostname. The fconfigure Command. Multiple Interpreters and Safe-Tcl. The grid Geometry Manager. The Text Widget. The Entry Widget.50. Tcl 7.6/Tk 4.2. More file Operations. Virtual Events. Standard Dialogs. New grid Geometry Manager. Macintosh unsupported1 Command.51 Tcl/Tk 8.0. The Tcl Compiler. Compile-Time Errors. Binary String Support. Namespaces. Safe-Tcl. New lsort. tcl_precision Variable. Year 2000 Convention. Http Package. Serial Line I/O. Platform-Independent Fonts. The tk scaling Command. Application Embedding. Native Menus and Menubars. CDE Border Width. Native Buttons and Scrollbars. Images in Text Widgets. No Errors from destroy. grid rowconfigure. The Patch Releases. fconfigure -error. tcl_platform(debug). tcl_findLibrary. auto_mkindex_old. Windows Keysyms for Start and Menu Keys. The MouseWheel Event. Transparent Fill on Canvas Text. safe::loadTk.52 Tcl/Tk 8.1. Unicode and Internationalization. fconfigure -encoding. The encoding Command. The msgcat Package. UTF-8 and Unicode C API. Thread Safety. The testthread Command. Advanced Regular Expressions. New String Commands. The DDE Extension. Miscellaneous. Serial Line I/O. tcl_platform(user).53 Tcl/Tk 8.2. The Trf Patch. Faster String Operations. Empty Array Names. Browser Plugin Compatibility.54 Tcl/Tk 8.3. Proposed Tcl Changes. Octal Numbers. file channels. Changing File Modify Times. regsub -subst or -command. New glob options. Internationalization. Proposed Tk Changes. The Img Patch. Canvas Improvements. Pointer Warping. Hidden Text. Entry Widget Validation.55 About The CD-ROM. Index.