An Overview of Tcl and Tk John Ousterhout Sun Microsystems Laboratories john.ousterhout@eng.sun.com Tcl/Tk Tutorial, Part I.

Презентация:



Advertisements
Похожие презентации
An Introduction To Tcl Scripting John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part II.
Advertisements

© 2005 Cisco Systems, Inc. All rights reserved. IPTX v Configuring Cisco Unity Express Automated Attendant and Voice Mail Understanding Cisco Unity.
WEB SERVICES Mr. P. VASANTH SENA. W EB SERVICES The world before Situation Problems Solutions Motiv. for Web Services Probs. with Curr. sols. Web Services.
© 2002 IBM Corporation Confidential | Date | Other Information, if necessary © Wind River Systems, released under EPL 1.0. All logos are TM of their respective.
© 2005 Cisco Systems, Inc. All rights reserved.INTRO v Managing Your Network Environment Managing Cisco Devices.
Comparison of Lotus Notes Designer, Domino Workflow Architect and AdHoc Workflow Builder 2003 (c) AdHoc.
© 2009 Avaya Inc. All rights reserved.1 Chapter Three, Voic Pro Advanced Functions Module One – Text to Speech.
© 2009 Avaya Inc. All rights reserved.1 Chapter Four, UMS Web Services Module One – UMS.
© 2005 Cisco Systems, Inc. All rights reserved.INTRO v Module Summary The Cisco Discovery Protocol is an information-gathering tool used by network.
© 2005 Cisco Systems, Inc. All rights reserved.INTRO v Building a Simple Serial Network Understanding the OSI Model.
Designing Network Management Services © 2004 Cisco Systems, Inc. All rights reserved. Designing the Network Management Architecture ARCH v
The waterfall model is a popular version of the systems development life cycle model for software engineering. Often considered the classic approach to.
SSD1: Introduction to Information Systems SSD1: Introduction to Information Systems ISS, Wuhan University.
© 2006 Cisco Systems, Inc. All rights reserved. SND v Configuring a Cisco IOS Firewall Configuring a Cisco IOS Firewall with the Cisco SDM Wizard.
Evgeniy Krivosheev Andrey Stukalenko Vyacheslav Yakovenko Last update: Nov, 2013 Spring Framework Module 1 - Introduction.
CSTA is a kind of standard communication protocol used between PBX and computer that is famous in Europe. What is CSTA ? Control Requests Event Notifications.
Copyright 2003 CCNA 1 Chapter 9 TCP/IP Transport and Application Layers By Your Name.
© 2009 Avaya Inc. All rights reserved.1 Chapter Nine, Voic Pro in SCN Module Four – Distributed Voic Pro.
Standard I/O and Pipes. Standard Input and Output Linux provides three I/O channels to Programs Standard input (STDIN) - keyboard by default Standard.
XjCharts A C++ / Java Statecharts Tool for Developers Experimental Object Technologies
Транксрипт:

An Overview of Tcl and Tk John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part I

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 2 Introduction u Component technologies: –Tcl: embeddable scripting language –Tk: GUI toolkit and widgets based on Tcl. u The principle: universal scripting language controls everything: functions, interfaces, communication. u Results: –Raise the level of X programming: simpler, 5-10x faster application development. –Greater power: more things programmable, applications work together. –Active objects: replace data with scripts.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 3 Outline u Tcl scripting language. u Tk toolkit. u Tk applications. u Survey of applications and extensions. u Conclusions.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 4 Tcl: Tool Command Language u Interactive programs need command languages: –Typically redone for each application. –Result: weak, quirky. – emacs and csh powerful, but can't reuse. u Solution: reusable scripting language. –Interpreter is a C library. –Provides basic features: variables, procedures, etc. –Applications extend with additional features.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 5 Scripting Language Philosophy u Large, complex applications: –Performance important. –Need structure. –Goal: prevent bad things. u Interactive commands, scripting: –Performance less important. –Minimum structure: less overhead, easy interchange. –Goal: enable good things. Program size, complexity, reuse 1 Ґ One language can't meet all needs?

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 6 Two-Language Approach u Use Tcl for scripting, C or C++ for large things. u Goals for Tcl: –Minimal syntax: easy to learn and type. –Minimal structure: make things play together. –Simple interfaces to C: extensibility. Program size, complexity, reuse 1 Ґ CTcl

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 7 Tcl: Tool Command Language u Simple syntax (similar to sh, C, Lisp): set a 47н47 u Substitutions: set b $aн47 set b [expr $a+10] н57 u Quoting: set b "a is $a" нa is 47 set b {[expr $a+10]} н[expr $a+10]

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 8 More On The Tcl Language u Rich set of built-in commands: –Variables, associative arrays, lists. –C-like expressions. –Conditionals, looping: if "$x < 3" { puts "x is too small" } –Procedures. –Access to UNIX files, subprocesses. u Only representation is strings: –Easy access from C. –Programs and data interchangeable.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 9 Factorial Procedure proc fac x { if $x<=1 {return 1} expr $x*[fac [expr $x-1]] } fac 4 н24

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 10 Embedding Tcl In Applications u Application generates scripts. u Tcl parses scripts, passes words to command procedures. u Application extends built-in command set: –Define new object types in C. –Implement primitive operations as new Tcl commands. –Build complex features with Tcl scripts. Parser Init Command Loop Application Commands Built-In Commands TclApplication

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 11 Extensions u Extensions can be developed independently: –Network communication, database access, security,... u Applications can include combinations of extensions. Parser Init Command Loop Application Commands Built-In Commands TclApplication Extension Commands Extension

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 12 The Tk Toolkit u The problem: –Too hard to build applications with nice user interfaces. u The wrong solution: –C++, object-oriented toolkits. –Only small improvement (10-20%?): must still program at a low level. u The right solution: –Raise the level of programming. –Create interfaces by writing Tcl scripts.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 13 Creating User Interfaces With Tk u Additional Tcl commands: –Create Motif-like widgets. –Arrange widgets. –Bind events to Tcl commands. –Manipulate X selection, focus, window manager, etc. u Library of C procedures: –Create new widget classes. –Create new geometry managers.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 14 u The Tcl interpreter. u The Tk toolkit. u Application-specific C code (primitives!): –New object types. –New widgets. u Tcl scripts (compose primitives): –Build user interface. –Respond to events. What's A Tk-Based Application? Tcl commands

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 15 Wish: Windowing Shell u Create user interfaces by writing Tcl scripts. u Hello, world: button.hello -text "Hello, world" -command exit pack.hello u Simple directory browser: 30 lines u Web browser: 2000 lines u 10x less code for simple things.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 16 Browser Wish Script #!/usr/local/bin/wish4.0 listbox.list -yscroll ".scroll set" \ -width 20 -height 20 pack.list -side left scrollbar.scroll -command \ ".list yview" pack.scroll -side right -fill y if {$argc > 0} { set dir [lindex $argv 0] } else { set dir. } foreach i [lsort [glob *.*]] {.list insert end $i } bind.list { browse $dir [selection get] } bind all {destroy.} proc browse {dir file} { if {$dir != "."} { set file $dir/$file } if {file isdirectory $file] { exec browse $file & } else { if [file isfile $file] { exec xedit $file & } else{ error "can't browse $file" }

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 17 Other Uses For Tcl u Data representation: –Store data on disk as Tcl scripts. –To load information, evaluate script. u Active objects: –Store scripts in objects. –Evaluate scripts at interesting times to give objects behavior. u Communication: send Tcl scripts between applications. u Executable content: –Active messages, Web pages. –Agents.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 18 Status u Runs on all UNIX/X platforms. u PC/Mac alpha releases: September u Source and documentation freely available. u 100,000 developers world-wide? u Hundreds of commercial products, free extensions. u Newsgroup: comp.lang.tcl. u 2 introductory books (Ousterhout, Welch).

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 19 Representative Applications u Multimedia, groupware. u Active messages. u System administration. u Testing. u Scientific applications: instrument control, simulation, visualization, CAD. u Real-time control system for offshore platform. u British teletext system. u Feature animation at Walt Disney Studios. u On-air broadcast control system for NBC.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 20 Popular Extensions u Available via public FTP: ftp://ftp.aud.alcatel.com/tcl Expect: remote control for interactive programs such as ftp, telnet, crypt, and fsck : #!/usr/local/bin/expect spawn rlogin [lindex $argv 0] expect -re "($|#|%) " send "cd [pwd]\r" expect -re "($|#|%) " send "setenv DISPLAY $env(DISPLAY)\r" interact

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 21 Popular Extensions, cont'd u TclX: general-purpose extensions: –POSIX system calls. –Keyed lists. –File scanning (similar to awk). –Date/time manipulation. –Debugging, help, profiling. u Oratcl and Sybtcl: access to commercial databases. u Incr tcl: object-oriented programming in Tcl.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 22 Popular Extensions, cont'd u Tcl-DP: socket-based remote procedure calls, distributed objects. –Sample server: set myId 0 proc GetId {} { global myId incr myId return $myId } dp_MakeRPCServer 4545 –Sample client: set server [dp_MakeRPCClient foo.bar.com 4545] dp_rpc $server GetId

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 23 Where You Might Use Tcl and Tk u Creating graphical user interfaces. u Testing. u Applications that need scripting or extension facilities. u Platform-independent applications.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 24 Drawbacks u Must learn new language (substitution rules confusing to some people). u Interpreted language has performance limits (but surprisingly high). u C interfaces incompatible with Xt, Motif library.

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 25 Plans For The Future u Increase accessibility: –More work on PC/Mac ports (native look and feel). –SpecTcl: interactive GUI builder. –Better development tools (debugger, etc.) u Improve the language/toolkit: –Incremental on-the-fly compiler. –Better support for modules, data structures. –Better internationalization (Asian character sets). u Create exciting Internet applications: –Active documents?

Tcl/Tk Tutorial Part I: OverviewDecember 12, 1995, slide 26 Conclusions u High-level programming: –Less to learn. –Build applications more quickly. u Universal scripting language: –Extend and modify applications at run-time. –Make many things work together. u Use scripts instead of data: –Active objects, executable content. Tcl + Tk = shell of the 1990's?