Programming Using Tcl/Tk Week 4 Seree Chinodom

Slides:



Advertisements
Similar presentations
Intro to Access 2007 Lindsey Brewer CSSCR September 18, 2009.
Advertisements

Tk Widgets This material is best on several sources –Slides by Dr. Ernest J. Friedman-Hill –various Tcl/Tk books.
KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
The GIMP Simple features tutorial By Mary A White.
Introduction to Microsoft Excel 2010 Chapter Extension 3.
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
Chapter Day 5. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 Posted  Introduction on developing.
Writing Tcl Scripts (cont.) Outline –Variable Scoping –Strings –Eval –File/Channel I/O –Processes –System Info –Errors –Reflection/Debugging –Libraries.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Linux+ Guide to Linux Certification, Second Edition
Building User Interfaces with Tk/Tcl Outline –Basic Structures –Widget Creation –Geometry Management –Widget Commands –Event Bindings –Interprocess Communication.
Guide To UNIX Using Linux Third Edition
There is a certain way that an HTML file should be set up. The HTML section declares a beginning and an ending. Within the HTML, there should be a HEAD.
Introduction To Form Builder
3.2 Presentation Software End Show Creating slide shows including audio,video and digital images End Show.
Reporting Aesthetics An ACEware Webinar 1:00-2:00 pm February 14 th, 2008.
With Alex Conger – President of Webmajik.com FrontPage 2002 Level I (Intro & Training) FrontPage 2002 Level I (Intro & Training)
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Creating a Web Page HTML, FrontPage, Word, Composer.
HTML Tags. Objectives Know the commonly used HTML tags Create a simple webpage using the HTML tags that will be discussed.
 Insert a picture from a file  Move and delete images  Use the Picture Tools tab  Add styles, effects, and captions to images  Resize photos  Use.
Building and managing class pages on our new Web site School Wires Training.
 Using Microsoft Expression Web you can: › Create Web pages and Web sites › Set what you site will look like as you design it › Add text, images, multimedia.
Website design Feng Zhao College of Educatioin California State University, Northridge.
Presented by Chad Kafka This Month’s Topic: Wikispaces Advanced Today’s session is an introduction to what a WIKI is and how they can be used in education.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
Tutorial 1 Getting Started with Adobe Dreamweaver CS3
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
Understanding Web Sites. What is a Web Site A collection of Web pages which you can view on the Internet Contains text, graphics, sound, and video to.
Tcl/Tk: An introduction D. Kim, K. Kundu, and M. Siegel November 26, 2002 CMSC 631.
The New Elements © Main Menu Structure Media Canvas Form Click on one of the categories below to view information about the new HTML5 elements in.
HTML Hyper Text Markup Language A simple introduction.
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
Microsoft Publisher 2010 Chapter 4 Creating a Custom Publication from Scratch.
Magazine Magic!!! Bret Madsen. Today’s Top Headlines Elements of a magazine Formatting pages Adding pictures Tying it all together.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
Designing a Web Page with Tables. A text table: contains only text, evenly spaced on the Web page in rows and columns uses only standard word processing.
Chapter 4 BIE1313/BPROG1203 | Web design Prepared by Mohamed Abdulkarim / Mike Ng Ah Ngan.
Presented By David Speight.  Easy Student Accessibility  Familiar Navigation  Fits Inside the Box  Works Outside the Box  Allows Creativity without.
© 2012 The McGraw-Hill Companies, Inc. All rights reserved. word 2010 Chapter 3 Formatting Documents.
Laboratory Exercise # 9 – Inserting Graphics to Documents Office Productivity Tools 1 Laboratory Exercise # 9 Inserting Graphics to Documents Objectives:
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Binding Basics.
Basic Editing Lesson 2.
Chapter 4 Creating a Custom Publication from Scratch Microsoft Publisher 2013.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Chapter 4 Working with Frames. Align and distribute objects on a page Stack and layer objects Work with graphics frames Work with text frames Chapter.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1.
IWorks Pages. Word Processing  Software that is designed for the entry, editing, and printing of documents.  Mac Version = iWorks Pages  As with Microsoft.
Getting Started with Fireworks A few tips: –Before you begin an assignment, be sure to create a folder on your drive for it. –If your canvas is checkered,
Adobe Photoshop CS5 – Illustrated Unit A: Getting Started with Photoshop CS5.
Walkthrough example including SAS output How to create a mobile WebApp? PhUSE / 12. October 2015 / Katja Glaß BHC 4:3 Template 2010 June 2014Page 1.
9-Nov-97Tri-Ada '971 TASH An Alternative to the Windows API TRI-Ada ‘97 Terry J. Westley
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
HTML Forms.
+ Publishing Your First Post USING WORDPRESS. + A CMS (content management system) is an application that allows you to publish, edit, modify, organize,
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
HTML Hyper Text Markup Language. The Basics u HTML documents contain “tags” which instruct the Browser software on how to present the information within.
Computer Programming with Scratch JAOIT 8. Scratch Scratch is a programming language that makes it easy to create your own interactive stories, animations,
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
HTML Hyper Text Markup Language. Agenda Basics Tools Important tags Tables & databases Forms Publishing at Stern.
1 Word Processing Intermediate Using Microsoft Office 2000.
Microsoft Office 2007-Illustrated
MS 2013 POWERPOINT.
TCL/TK Tool Command Language/Tool Kit.
This Week: Tkinter for GUI Interfaces Some examples
Importing and Editing Images
Embedding Graphics in Web Pages
Introduction to PowerPoint
Presentation transcript:

Programming Using Tcl/Tk Week 4 Seree Chinodom

First Things First ฉ Homework #1: Only 4 out of 10? –Don't have software? –Not for credit? –Need more help? ฉ Homework #2: Hand them in, if you've got 'em ฉ The story about the readers…

TkCal Example ############################## # initialize global variables set months {January February March April May June July \ August September October November December} # figure out the current month and year # date returns a string like Sun Sep 22 22:26:10 PDT 1996 set d [exec date] set month [lindex $d 1] set year [lindex $d 5] # expand the abbreviation that date gave us foreach m $months { if {[string match ${month}* $m] == 1} { set month $m break }

TkCal (continued) ############################## # Menu action proc doMenu {m} { global month set month $m.f.mb configure -text $m } ############################## # run cal and collect output proc showCalendar {} { global month year months set m [expr [lsearch $months $month] + 1] if {[catch {set cal [exec cal $m $year]} err] == 1} { set cal $err }.t delete 1.0 end.t insert 1.0 $cal }

TkCal (continued) ############################## # set up widgets frame.f pack.f -side top -fill x -expand 1 menubutton.f.mb -text $month -menu.f.mb.m -width 12 pack.f.mb -side left menu.f.mb.m foreach m $months {.f.mb.m add command -label $m -command "doMenu $m" }

TkCal (continued) entry.f.e -textvariable year -width 5 pack.f.e -side left button.b -text "See Calendar" -command showCalendar pack.b -side top -pady 3 -fill x text.t -width 21 -height 8 pack.t -side bottom -fill x ############################## # initial display showCalendar

What We'll Do Today ฉ A Few Miscellaneous Details ฉ Using the Text and Canvas Widgets ฉ More Advanced Examples ฉ Writing 'Tclets' for the World Wide Web

Tcl/Tk Addendum ฉ cget widget command to query configuration options.w cget -foreground => black Much easier than.w configure -foreground! ฉ env array containing environment variables cd $env(HOME) exec $env(EDITOR)

The Text Widget ฉ Multiline text area widget with 1001 features: –Editing ท (Emacs key bindings: ^A, ^E, ^K, ^Y, ^F, ^B, etc) –Scrolling (manual and from code; X and Y axes) –Flexible text formatting: multiple fonts and colors –Text tags: content-sensitve formats and behaviors –Selection manipulation ฉ Arranges text and embedded widget in lines; lines can wrap but not flow

The Text Widget ฉ Special widget commands: setgetdeleteselectmark tagsearchseewindowyview xviewbind ฉ Special widget configuration options -state-height-width -spacing1-spacing2-spacing3 -state-tabs -insertbackground-selectbackground

The Text Widget ฉ Referring to text within a text widget –index: line.char (line starts at 1, char starts at 0) (character closest to pixel x,y) –mark: Basically a name for an index..t mark set myplace 6.23 –tag: Names for sets of ranges of text.t tag add mywords t tag add mywords

The Text Widget ฉ Tagged text can be configured.t tag configure mywords -foreground red ฉ Tagged text can have bindings!.t tag bind mywords { exec TkEdit mywordlist.txt }

The Text Widget ฉ Text widgets can serve as geometry managers for other widgets: image create photo -file bart.gif label.t.l -image image1.t window create 1.5.t.l

A Syntax-Coloring Mini-Editor ฉ "TkEmacs" does customizable syntax coloring using regular expressions, like Emacs' hilit-19 package ฉ One text widget ฉ One scroll widget ฉ Can read and save files ฉ About 100 lines of well-commented code

TkEmacs (continued) proc forAllMatches {w pattern script} { # determine number of lines in widget scan [$w index end] %d numLines ;# returns e.g for {set i 1} {$i < $numLines} {incr i} { $w mark set last $i.0 while {[regexp -indices $pattern \ [$w get last "last lineend"] context indices]} { $w mark set first "last + [lindex $indices 0] chars" $w mark set last "last + 1 chars + \ [lindex $indices 1] chars" uplevel $script } forAllMatches Routine

TkEmacs (continued) proc doColor {w} { global syntax_patterns global syntax_colors foreach name [array names syntax_patterns] { $w tag delete $name forAllMatches $w $syntax_patterns($name) \ "$w tag add $name first last".t tag configure $name \ -foreground $syntax_colors($name) } doColor Routine

TkEmacs (continued) proc loadFile {w file} { $w delete 1.0 end set f [open $file] while {![eof $f]} { \$w insert end [read $f 1000] } close $f } proc writeFile {w file} { set f [open $file "w"] puts $f [$w get 1.0 end] close $f } File Routines

TkEmacs (continued) set syntax_patterns(types) \ {[^A-Za-z0-9"](char|short|int|long|unsigned|signed|float|double)} set syntax_colors(types) yellow set syntax_patterns(directives) \ {((#include|#ifdef|#ifndef|#if|#elseif|#else|#pragma|#endif).*$)} set syntax_colors(directives) purple set syntax_patterns(newline_types) \ {^(char|short|int|long|unsigned|signed|float|double)} set syntax_colors(newline_types) yellow set syntax_patterns(keywords) \ {[^"A-Za-z0-9]+(if|then|else|for|goto|while|struct)([^A-Za-z0- 9"]|$)} set syntax_colors(keywords) red set syntax_patterns(comment1) {(/\*.*\*/)} set syntax_colors(comment1) pink set syntax_patterns(comment2) {(//.*$)} set syntax_colors(comment2) pink set syntax_patterns(strings) {("[^"]+")} set syntax_colors(strings) orange

TkEmacs (continued) # Set up the widgets text.t \ -yscrollcommand ".s set" \ -insertbackground white \ -width 50 -height 18 pack.t -side left -fill x \ -expand 1.t configure -tabs { }.t configure -background black.t configure -foreground white scrollbar.s -command \ ".t yview" pack.s -side right -fill y # Key bindings bind.t {doColor.t} bind.t \ {writeFile.t $FILENAME} bind.t {exit} # Run a little demo set FILENAME [lindex $argv 0] loadFile.t $FILENAME wm title. "TkEmacs $FILENAME" doColor.t

The Canvas Widget ฉ Does for drawing primitives what text does for words ฉ Special widget commands: addtagbindcreate deletedtagfind focusgettagsitemconfiguremove postscript ฉ Special widget configuration options -closeenough-scrollregion -xscrollincrement -yscrollincrement

The Canvas Widget ฉ Canvases can be "drawn on".c create oval \ -fill yellow -outline black.c create oval \ -fill black -outline black.c create oval fill black -outline black.c create arc outline black \ -extent style arc -width 4 -start 5.c create arc outline black \ -extent style arc -width 4 -start 320.c create arc outline black \ -extent style arc -width 4 -start 320

The Canvas Widget ฉ Each drawing primitive or embedded window is an 'item' with a numeric index.c create oval \ -fill yellow -outline black => 1 ฉ Items can be tagged, as in text widget. c itemconfigure 2 -tag eyes. c itemconfigure 3 -tag eyes

The Canvas Widget ฉ Items can be searched for in many ways.c find closest ;# canvas coords => 2 ;# left eye ฉ Items and tags can have bindings.c bind eyes {Wink %W %x %y}.c bind eyes {Unwink %W %x %y}

Furniture Arranger ฉ A simple app to help you decide how to arrange your furniture ฉ Uses drawing primitives to represent pieces of furniture ฉ Uses multiple tags per item ฉ Implements behaviors based on tags

Furniture Arranger proc setupCanvas {} { catch {destroy.c} canvas.c pack.c # create chairs foreach i { } {.c create rect $i 100 [expr $i+20] 120 \ -fill red -tags {chair furniture} } # setup Chair behavior.c bind chair {.c itemconfigure current -fill blue}.c bind chair {.c itemconfigure current -fill red}... setupCanvas, part 1

Furniture Arranger... #create Table.c create oval fill pink \ -tags {table rotatable furniture} # setup Table behavior.c bind table {.c itemconfigure current -fill skyblue}.c bind table {.c itemconfigure current -fill pink} #create Couch.c create rect fill orange \ -tags {couch rotatable furniture} # setup Couch behavior.c bind couch {.c itemconfigure current -fill green}.c bind couch {.c itemconfigure current -fill orange}... setupCanvas, part 2

Furniture Arranger... # setup 'rotatable' behavior.c bind rotatable rotate # setup Furniture behavior.c bind furniture { set curX %x set curY %y }.c bind furniture {.c move current [expr (%x-$curX)] [expr (%y-$curY)] set curX %x; set curY %y } setupCanvas, part 3

Furniture Arranger proc rotate {} { set r [.c find withtag current] set coords [.c coords $r] set x2 [expr ([lindex $coords 2] - [lindex $coords 0]) / 2] set y2 [expr ([lindex $coords 3] - [lindex $coords 1]) / 2] set xc [expr [lindex $coords 0] + $x2] set yc [expr [lindex $coords 1] + $y2].c coords $r [expr $xc - $y2] \ [expr $yc - $x2] \ [expr $xc + $y2] \ [expr $yc + $x2] } setupCanvas bind. setupCanvas wm title. "Furniture Arranger" rotate and mainline

Tclets ฉ Sun has released a Netscape 'plug-in' for Tcl/Tk ฉ Your Tcl/Tk programs can run as 'Tclets' inside Netscape if you remember a few simple things –Filesystem access is severely restricted –Exec'ing is prohibited –Network access is prohibited –Grabbing display prohibited –direct window manager interaction prohibited –No menu widgets ฉ What can you do with this? –Tools like a calculator –Graphical demonstrations –Games

Tclets ฉ Only users who ahev installed the plug-in can use your Tclets ฉ Tclet filesystem access is limited to: –Using source and load in script directories only –Using open (read only) in script directories –Using the new command maketmp to create read- write temporary files –You can't get a file listing! –No stdout, stdin ฉ Some commands have extensions to help –image data can come from a MIME encoded string

Making 'Furniture Mover' a Tclet ฉ The Furniture Mover app makes a perfect Tclet. Anyone in the world could rearrange your furniture! ฉ One change to source: if {[info exists embed_args] == 0} { wm title. "Furniture Arranger" } ฉ embed_args is an array containing parameters from HTML - you can use them as command line args for your Tclet

Making 'Furniture Mover' a Tclet ฉ Next, create a page of HTML: Furniture Moving Tclet Friedman-Hill Home Furniture Planning Kit This Tclet lets you rearrange the furniture in an imaginary room from the Friedman-Hill mansion. See what you can do to improve the work of a decorating genius!

Deploying Tclets ฉ Place furniture.tcl and furniture.html in the same directory in your area or on a web server ฉ Visiting the html file with Netscape will show the Tclet (if the plug-in is installed). ฉ Tip: include a link to the Tcl Plug-in home page and a brief explanation on each of your Tclet-enhanced pages

For Next Week... ฉ Review today's material in Ousterhout, Chapter 19 ฉ Read Ousterhout Chapter to prepare for next week's lecture on extending Tcl with C ฉ Also next week: a look at some Tcl extensions ฉ Projects due next week –Bring screenshots if you can (as vugraphs if possible) –Please be prepared to talk for five minutes or so