Tcl/Tk lecture. What is the Wish Interpreter? CIS 410/510 User Interface Programming

Similar documents
Tcl/Tk for XSPECT a Michael Flynn

Introduction to Tcl/Tk. TraNese Christy U.S. Army Research Laboratory

When to use the Grid Manager

Scripting Languages TCL: Tool Command Language

Getting Started p. 1 Obtaining Tcl/Tk p. 1 Interactive Execution p. 1 Direct Execution p. 4 Reading this Book p. 6 Requirements for Networking

CS 520 Principles of Programming Languages. A Report on Tcl/Tk. TABLE of CONTENTS The interpreted nature of Tcl

Configuring CSM Scripts

Graphical user interface software

Programming Training. This Week: Tkinter for GUI Interfaces. Some examples

By now, most folks have heard about Tcl and Tk, but it seems only fair to introduce a new column with an introduction to the topic.

An X11 Toolkit Based on the Tcl Language

Scripting or - How to Control Your AVR From Your PC

inside: THE MAGAZINE OF USENIX & SAGE June 2002 volume 27 number 3 PROGRAMMING THE TCLISH SPOT by Clif Flynt

February 16, 1995 To: Stan Hilinski From: Alex Measday Subject: C est Moi!

Visualization of Biomolecular Structures

Eagle: Tcl Implementation in C# Alt.NET 2011 (Seattle) Joe Mistachkin

Windows and Events. created originally by Brian Bailey

Python Scripting for Computational Science

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

itcl and TclOO From the perspective of a simple user

Creating Custom Stars Derived from TclScript. Your parameters are accessible in your Tcl script:

Syllabus- Java + Android. Java Fundamentals

Lesson 2: First Java Programs

TKproE 2.20 Documentation

Object-Oriented Programming

Operating Systems 2 nd semester 2016/2017. Chapter 4: Threads

Python Scripting for Computational Science

Chapter 6 Introduction to Defining Classes

Event Dispatch. Dispatching events to windows and widgets.

Pace University. Fundamental Concepts of CS121 1

Collaborative Data Collection with BLU-ICE

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. 2.4 Event Dispatch 1

Hello Button. An Introduction to Tcl/Tk

Distributed Control Systems at SSRL Constraints for Software Development Strategies. Timothy M. McPhillips Stanford Synchrotron Radiation Laboratory

Review. Designing Interactive Systems II. Review. Base Window System. Apps UITK BWS GEL. 4-Layer Model Graphics and Event Library BWS GEL

Tcl/Tk Advanced Tutorial (Tk toolkit)

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

Murach s Beginning Java with Eclipse

C++ Important Questions with Answers

Chapter 2 First Java Programs

TkRibbon: Windows Ribbons for Tk

This text is used together with Mark Pilgrims book Dive Into Python 3 for the Arthead course Python Fundamentals.

GUI Event Handlers (Part I)

GUI Design for Android Applications

Bourne Shell Reference

Lecture 9: UI Software Architecture. Fall UI Design and Implementation 1

Visual Ada Developer

Java Application Development

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Android Essentials with Java

Programming in Python

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. Event Architecture. A pipeline: Event Capture

Graphical User Interfaces with Perl/Tk. Event Driven Programming. Structure of an Event-Driven Program. An introduction

CSC209 Review. Yeah! We made it!

Regression testing GUIs New features for tktest

Today. Review. Unix as an OS case study Intro to Shell Scripting. What is an Operating System? What are its goals? How do we evaluate it?

Model-view-controller View hierarchy Observer

(Refer Slide Time: 01:40)

GNU ccscript Scripting Guide IV

The Racket Graphical Interface Toolkit

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Lecture 1 Introduction to Android. App Development for Mobile Devices. App Development for Mobile Devices. Announcement.

SubArctic UI Toolkit User's Manual St. Paul Release (Beta version 0.8e) Table of Contents

MOBILE COMPUTING 1/20/18. How many of you. CSE 40814/60814 Spring have implemented a command-line user interface?

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

ENGR/CS 101 CS Session Lecture 15

PYTHON TRAINING COURSE CONTENT

inside: THE MAGAZINE OF USENIX & SAGE October 2001 Volume 26 Number 6 PROGRAMMING The Tclsh Spot By Clif Flynt

Command-driven, event-driven, and web-based software

PTN-202: Advanced Python Programming Course Description. Course Outline

TCL Scripting for Cisco IOS

Packages: Putting Classes Together

Lecture 8. Introduction to Shell Programming. COP 3353 Introduction to UNIX

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

Programming Assignment IV Due Monday, November 8 (with an automatic extension until Friday, November 12, noon)

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Laying Out Components. What is Widget Layout?

GUI in C++ PV264 Advanced Programming in C++ Nikola Beneš Jan Mrázek Vladimír Štill. Faculty of Informatics, Masaryk University.

Pointers and Terminal Control

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Widgets. Widgets Widget Toolkits. 2.3 Widgets 1

- learnability. - efficiency. - graphic design

Interface Builders and Interface Description Languages

We will talk about Alt-Tab from the usability perspective. Think about: - Is it learnable? - Is it efficient? - What about errors and safety?

Editor s Note: Cross references in the text refer to chapters in the companion book,

Introduction p. 1 Basic Programming Introduction p. 7 Introduction to Python p. 7 Why Use Python? p. 10 Main Technical Features p.

Marthon User Guide. Page 1 Copyright The Marathon developers. All rights reserved.

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

ACT-R Environment Manual

! The Process Control Block (PCB) " is included in the context,

Working with JavaScript

Introduction to Java

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.

bufdump - A utility for dumping NSCL event buffers Ron Fox

Tkinter Part II: Buttons, Lambda & Dynamic Content

CP150 - Advanced Perl Programming

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

Beginning Silverlight 5 in C #

Transcription:

Tcl/Tk lecture CIS 410/510 User Interface Programming Tool Command Language TCL Scripting language for developing & using GUIs Allows generic programming variables, loops, procedures Embeddable into an application Extensible Interpreter written in C called Wish Advantages? Disadvantages? What is the Wish Interpreter? Read - Eval - Print Loop You type in a function, interpreter reads it Interpreter immediately evaluates it produces a result error message result of evaluation Has a memory which you add to or change Can t print out or save the source listing Advantage: Can immediately test the result of a function 1

Four Basic Things about Tcl 1. Consistent Syntax procname?argument??argument? where procname is a function, command or procedure?argument? is a series of arguments to pass to the function. % set a 15 15 <---- this is the return value of the "set" function. % expr 4 + 5 + 2 11 <---- return value 2. To evaluate a command and return the value inline use brackets [] % set a [expr 5 + 7] 12 Four Basic Things about Tcl cont. 3. To evaluate a variable, put a $ in front of its name % puts "hello world" hello world % set a [expr 11 + 12] 23 % puts "The value of a is $a" The value of a is 23 Four Basic Things about Tcl cont. 4. To prevent variables from being evaluated, enclose them in curly braces { % set a hello hello % set b "$a world" hello world % set c {$a world $a world % set d {"a string with quotes" "a string with quotes Seems simple, but can get very complex when you nest them in "lists" 2

More about Tcl Can define a new procedure proc name args body Control structure If then else for, foreach, while catch traps errors Variables either string or list use of global variables common Toolkit for Tcl TK Cross-Platform UI Widgets X Window, Microsoft Windows, Mac Can program widgets with Tcl scripts Written in C Extensible new UI widgets new geometry managers Programming in Tk Create instance of widget class Specify attributes of widget instance Arrange with geometry manager Bind actions to widget events 3

More on Tk Class hierarchy of widgets UNIX Motif look & feel; each widget is an X window Tcl script invoked when event occurs allows application specific code Example: if left mouse button pressed when cursor over a Button widget, then exit. More on Tk 4 Types of special commands creating & destroying widgets widget command: change color, etc..b geometry management: size & location widgets on screen packer, placer, grid interconnecting widgets within and between applications Example: scrollbar changes canvas view Tcl/Tk Benefits Rapid development interpreter wish (windowing shell) higher level language than C, C++ or Motif Tk 1/10 less time to code easier to learn Can call Java or C programs Can glue together many library packages Convenience cross-platform shareware, freeware supported by SUN 4

Tcl/Tk Disadvantages Interpreter creates slow code 8.0 has compiler Replace with Java? probably not: Tcl/Tk is much faster to learn and code Not multi-threaded working on it Text oriented GuiBuilders available: SpecTcl (see /local/apps/tcltk/spectcl-1.1 directory and Visual Tcl Implicit Main Event Loop Tcl/Tk Each Tk widget is a window Each widget has pre-defined event handlers Example: Button widget responds to mouse button Can attach a Tcl script to an event handler to process application semantics for widget Example: Bind command Other events in event queue after generates timer event (used for animation, etc.) fileevent when file descriptor becomes readable or writable Process redraws after input events Tcl/Tk Event Processing Countdown Program Example label.countdown text Ready pack.countdown -padx 4 -pady 4 button. -text -command { for {set i 10 {$I >= 0 {incr I -1 {.countdown configure -text $1 after 1000 pack. -padx 4 -pady 4 (THIS has bugs. Can you find them?) 5

Tcl/Tk Event Processing Countdown Program Example label.countdown -text Ready pack.countdown -padx 4 -pady 4 button. -text -command { for {set i 10 {$i >= 0 {incr i -1 {.countdown configure -text $i after 1000 pack. -padx 4 -pady 4 Expected Output of Countdown Program Ready 10 9 0 Actual Output of Countdown Program Ready 0 6

Why? Process redraws after input events To get expected output, add update command button. -text -command { for {set i 10 {$i >= 0 {incr i -1 {.countdown configure -text $i update after 1000 Another quirk of Tcl/Tk event processing proc wait_for_click {win { ; # BUG ALERT! set x 0 bind $win <ButtonPress-1? {set x 1 bind $win <ButtonPress-2? {set x 2 vwait x return $x What is the result? after mouse click get 0 Why? Any code invoked from event loop is executed at global level!!! Why? Any code invoked from event loop is executed at global level!!! There are two variables called x proc wait_for_click {win { ; # BUG ALERT! set x 0 bind $win <ButtonPress-1? {set x 1 bind $win <ButtonPress-2? {set x 2 vwait x return $x 7

Solution To make program work properly, declare x global within the procedure Caution!!! This same logic applies to any script that is invoked from the event loop after fileevent -command Widget Composite Objects Composite Object can have children not a subclass-class relation, i.e. not specializations instead, part-whole relation Containers More on Composite Objects Composite object allows run-time hierarchy in which position of child is specified relative to parent, therefore movement occurs automatically Container object has size, position, children, but no interaction of its own Example: Frame in Tcl/Tk Containers can be children of other containers Event propagation by parent notification If user generates move event that is not of interest ot a particular object, it gets passed up the hierarchy Example: move to dialog box passed to container which is parent 8

Composite Object Tcl/Tk Dialog Box Tcl/Tk Geometry Managers packer for layouts with rows and columns placer for layouts with fixed position slaves relative or absolute to master grid part of the canvas widget, allows mixing embedded widgets with other elements such as lines and text Packer Arranges slaves by positioning them one at a time in the master window, working from edges toward center Maintains a packing list for a given master window Packer arranges the slaves by processing the list in order Current slave is positioned by allocate a parcel of unused space stretch the slave position in the parcel 9

Packer Process Master Slave 1) Available Space 2) Parcel for slave 3) 4) Available Space Packer Options -side button.ok -text OK button.cancel -text Cancel button.help -text Help pack.ok.cancel.help -side left pack.ok.cancel.help -side top OK Cancel Help OK Cancel Help Other Packer Options -padx & -pady specifies extra space (distance) outside slave -ipadx & -ipady specifies extra space (distance) inside slave -expand slave s parcel grows to absorb extra space left over in master -fill whether and how to grow slave if its parcel is larger than the slave s requested size 10