Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Prof. Yitzchak Rosenthal
Chapter 3 – Web Design Tables & Page Layout
Tk. Toolkit n Wish - windowing shell –touch fileName –chmod +x fileName –xedit fileName & –#!/usr/local/bin/wish n Widgets - eg Buttons, Labels, Frames.
Tk Widgets This material is best on several sources –Slides by Dr. Ernest J. Friedman-Hill –various Tcl/Tk books.
DEVELOPING ICT SKILLS PART -TWO
Computer and Communication Fundamental Basic web programming Lecture 8 Rina Zviel-Girshin.
Tutorial on Basic Usage
Microsoft Word 2010 Lesson 1: Introduction to Word.
© by Pearson Education, Inc. All Rights Reserved.
Chapter 6 Multiform Projects Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Customizing Forms and Writing QuickBooks Letters Lesson 15.
Laboratory Exercise # 3 – Basic File Management Office Productivity Tools 1 Laboratory Exercise # 3 Basic File Management Objectives: At the end of the.
Programming a GUI Hanan sedaghat pisheh. For calling GUI, we need a function with no inputs or outputs First We create a m.file m file has the same name.
Customizing forms and writing QuickBooks Letters Lesson 15.
Graphical User Interfaces with Perl/Tk An introduction.
Lesson 1 – Microsoft Excel The goal of this lesson is for students to successfully explore and describe the Excel window and to create a new worksheet.
Key Applications Module Lesson 16 — Excel Essentials Computer Literacy BASICS.
Inspire students to develop ideas & organize thinking
Ch 11: Userforms CP212 Winter Topics Designing User Forms o Controls Setting Properties o Tab Order o Testing Writing Event Handlers o Userform_Initialize.
Microsoft PowerPoint Getting Started Guide Prepared for Towson University Dr. Jeff M. Kenton Amy Chase Martin 2007.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
Mentor Tools tutorial Bold Browser Design Manager Design Architect Library Components Quicksim Creating and Compiling the VHDL Model.
Guide to Programming with Python Chapter Ten GUI Development: The Mad Lib Program.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
1 Performing Spreadsheet What-If Analysis Applications of Spreadsheets.
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
Windows Tutorial Common Objects ACOS: 1, 4. Using the Taskbar 1. Using the taskbar, you can switch between open programs and between open documents within.
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Multiform Projects.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
Synopsys Custom Designer Tutorial for a chip integration using the University of Utah Standard Cell Libraries In ON Semiconductor 0.5u C5 CMOS Version.
Exploring Windows and Essential Computing Concepts 1 Windows Desktop u Windows Basics u Icon u Start Button u My Computer u Network Neighborhood u Recycle.
Basic Editing Lesson 2.
Python Programming Graphical User Interfaces Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Designer Basics.
Lecture 10: Toolkits: Intrinsics, Callbacks, Resources, Widget hierarchies, Geometry management Brad Myers Advanced User Interface Software 1© 2013.
PERL TK. 4.Use an IDE 3. Use the documentation! 2. Experiment. 1.Learn the basics.
CIS111 PC Literacy Getting Started with Windows XP.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 9 GUI Programming Using Tkinter 1.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
How the Session Works Outline Practical on arrival Talk 1 Reflect on practical Clarify concepts Practical exercises at your own pace Talk 2: Further concepts.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Creating visual interfaces in python
The Excel model for information processing The Excel model is a grid of cells in which items of information are stored and processed. Any information that.
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
Creating and Editing a Web Page
Guide to Programming with Python
Agency Web Site Navigation Structure. Building the agency web site Agency Web Site Navigation Structure, Slide 2Copyright © 2004, Jim Schwab, University.
Creating and Editing a Web Page Using Inline Styles
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
COMPSA Exam Prep Session by Paul Allison On: April 8th from 1:30-3:00 Location TBA Winter 2016CISC101 - Prof. McLeod1.
MS WORD INFORMATION TECHNOLOGY MANAGEMENT SERVICE Training & Research Division.
Fundamentals of Windows Mouse n 4 Basic Operations: –Pointing –Clicking –Double Clicking –Dragging.
Topics Graphical User Interfaces Using the tkinter Module
Chapter 21 – Graphics/Tk Outline 21.1 Introduction 21.2 GD Module: Creating Simple Shapes 21.3 GD Module: Image Manipulation 21.4 Chart Module 21.5 Introduction.
CMIP5 Questionnaire Roadmap – beta
GUI Using Python.
Fundamentals of Python: From First Programs Through Data Structures
This Week: Tkinter for GUI Interfaces Some examples
Tkinter GUIs Computer Science and Software Engineering
DREAMWEAVER MX 2004 Chapter 3 Working with Tables
Whatcha doin'? Aims: Begin to create GUI applications. Objectives:
Topics Graphical User Interfaces Using the tkinter Module
Presentation transcript:

Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc TM Dov Levenglick Jason Elbaum Perl::Tk December 14, 2005

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk What is Perl::Tk? Perl::Tk is Perl’s GUI module written in both Perl and C. Perl::Tk is event driven, which means that is sits around waiting for something to happen so that it can react to it. What can I do with Perl::Tk? Create GUI for your scripts Where can I find documentation for Perl::Tk? (Mastering Perl/Tk (the Emu book), O’Reilly)

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk Main concepts in Perl::Tk: 1. Main window. A main window is a window as one is used to seeing. This window contains various widgets. 2. Widgets. A widget is an element in the (hierarchy of the) main window that enables some functionality to the GUI (menu, button, text entry…). A widget will generate an event when the user does something with the GUI (moves the mouse, presses a button…) that will perform an action. 3. Event driven. The programmer does not have to be aware at every moment what is happening with the GUI, rather you register the effect of each event with the library and allow the library to deal with it. 4. Main loop. The Perl::Tk library runs a constant loop (MainLoop) that constantly monitors the events happening on the GUI. As long as the MainLoop isn’t exited, the GUI will still respond to events.

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk Basic example: Notice MainWindow, MainLoop and the use of OOP As seen in windows: As seen in UNIX: #!/usr/local/bin/perl5.6.1 use Tk; my $mw = MainWindow->new; $mw->title("Basic Example"); $mw->Button( -text=> "That's all folks", -command =>[sub {exit}] )->pack(); MainLoop;

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk As demonstrated in the previous slide, each GUI must have at least one instance of MainWindow and one call MainLoop. In the MainWindow there can be a variety of widgets, which can nest other widgets. The user must place the widget in it's place in order to have it displayed. In the previous slide this was done with pack, however there are various ways. Until placed, the widget won't be visible.

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk – Geometry Management There are 4 forms of geometry management: 1. pack – the most commonly used. Places a widget in the next available place in the parent widget (MainWindow or other), based on the placing of all other packed widgets. Overlapping of widgets is prohibited. 2. grid – used for creating a grid of widgets such as in a spreadsheet. Not covered in this course. 3. place – places the widget at absolute or relative coordinates in the parent widget. Not covered in this course. 4. form – can be seen as a combination of place and pack. That is, the widgets may overlap however they are placed relative to each other. Not covered in this course.

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk – pack Overlapping is prohibited. A packed widget is fitted “around” previously packed widgets, thus the order in which the widgets are packed effects the way that the widgets are displayed. A widget is packed against the top available space in the containing widget unless otherwise specified. Each widget is placed in an “allocation rectangle”. A widget is placed in the center of the allocation rectangle unless otherwise specified. An allocation rectangle will take up the size required by it (with no padding and/or resizing) unless otherwise specified.

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk – pack The pack function is performed on the reference to the widget and can be called with 0 or more parameters. As you can see, $button holds a reference to a button packed inside the MainWindow. The button is packed with the default parameters (side and anchor). #!/usr/local/bin/perl5.6.1 use Tk; my $mw = MainWindow->new; $mw->title("Basic Example"); my $button = $mw->Button( -text=> "That's all folks", -command =>[sub {exit}], ); $button->pack( -side =>’top’, -anchor =>’center’, ); MainLoop;

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk – pack -side => 'left' | 'right' | 'top' | 'bottom  Puts the widget against the specified side of the window or Frame -fill => 'none' | 'x' | 'y'| 'both'  Causes the widget to fill the allocation rectangle in the specified direction -expand => 1 | 0  Causes the allocation rectangle to fill the remaining space available in the window or Frame -anchor => 'n' | 'ne' | 'e' | 'se' | 's' | 'sw' | 'w' | 'nw' | 'center'  Anchors the widget inside the allocation rectangle -after => $otherwidget  Puts $widget after $otherwidget in packing order -before => $otherwidget  Puts $widget before $otherwidget in packing order

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk – pack -in => $otherwindow  Packs $widget inside of $otherwindow rather than the parent of $widget, which is the default -ipadx => amount  Increases the size of the widget horizontally by amount -ipady => amount  Increases the size of the widget vertically by amount -padx => amount  Places padding on the left and right of the widget -pady => amount  Places padding on the top and bottom of the widget

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk – pack When the widget is packed against the top or the bottom side of the containing widget, the allocation rectangle is as wide as the containing widget and as tall as the packed widget. When the widget is packed against the right or the left side of the containing widget, the allocation rectangle is as tall as the containing widget and as wide as the packed widget. Once a widget has been packed, the remaining space in the containing widget is reduced. For more information on the pack geometry management, refer to :

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk In this session we will incrementally build a Perl::Tk GUI that displays the contents of selected files as well as browses through a directory tree.

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk – Widgets The following list is of the most commonly used widgets: Frame Menubutton Label Button Checkbutton Radiobutton Entry FileSelect Scrolled Text All these widgets are incorporated in to the demo.

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - Frame In order to help you organize your widgets, the frame widget exists. It is basically an empty placeholder for other widgets to be put in to. Generally speaking, when designing a GUI, you place frames in the main window (a frame per area) and the widgets in that frame. Frames can be nested

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - Frame #!/usr/local/bin/perl5.6.1 use Tk; ####################### my $mw = MainWindow->new; $mw->title("Perl::Tk Demo"); my $menuFrame = $mw->Frame->pack(-fill=>'x'); my $fileSelectFrame = $mw->Frame->pack; my $manualFileFrame = $fileSelectFrame->Frame->pack(-side => 'left'); my $autoFileFrame = $fileSelectFrame->Frame->pack(-side => 'right', -fill => 'y'); my $fileDisplayFrame = $mw->Frame->pack; ####################### MainLoop;

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk Menubutton The menu widget allows you to create menus for your GUI. my $mainMenu = $menuFrame->Menubutton( -tearoff => 0, -text=>'Menu', )->pack( -side =>'left', ); $mainMenu->command( -label=>'Exit', -command=>'exit', );

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - Label A label is simply a place where you can put text (or an image) to be displayed. $menuFrame->Label( -text=>File Display GUI', -font=>'-adobe-courier-bold-r-normal-*-*-120-*-*-m-*-koi8-1' )->pack( -padx=>10 );

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - Buttons The Button widget creates a standard “pressable” button. The Checkbutton widget creates a button that can either be checked or not. The value of each Checkbutton is saved in a scalar variable (by default: checked=1, not checked=0). The Radiobutton widget creates a button that can either be checked or not. The value of all related Radiobuttons is saved in a scalar variable. As all grouped Radiobuttons are related by using the same scalar variable, only one Radiobutton in a group can be checked at any given time.

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - Buttons The following few slides will demonstrate Buttons, Radiobuttons and Checkbuttons. The demonstration of these buttons will be implemented in a subroutine for reasons that will become clear later on. Assume that $text has been declared. It will be explained on the slide titled Perl::Tk – TextPerl::Tk – Text &displayDirAndFiles($manualFileFrame, \$curdir, \%curfiles, \$text);

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - Buttons my $curdir = cwd; my %curfiles; &displayDirAndFiles($manualFileFrame, \$curdir, \%curfiles, \$text); sub displayDirAndFiles { my $parent = shift; my $dirRef = shift; my $filesRef = shift; my $textRef = shift; Tk::destroy($_) for ($parent->children); chdir $$dirRef; opendir(DIR,".") or die $!; = sort readdir DIR; closedir DIR; = grep {-d = grep {-f my $mainFrame = $parent->Frame->pack; my $entryFrame =$parent->Frame->pack; my $dirFrame = $mainFrame->Frame->pack(-side => 'left', -anchor => 'n',); my $fileFrame = $mainFrame->Frame->pack(-side => 'right', -anchor => 'n');

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - Buttons foreach { $dirFrame->Radiobutton( -value => $_, -variable => $dirRef, -text => $_, )->pack( -anchor => 'nw' ); } $dirFrame->Button( -text => 'Change Dir', -command => [sub {&displayDirAndFiles($parent, $dirRef, $filesRef, $textRef)}], )->pack( -side => 'left', );

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - Buttons Assume that displayFileContents has been defined. It will be shown on Perl::Tk – End of ExamplePerl::Tk – End of Example %$filesRef = (); foreach my $fl { my $cb= $fileFrame->Checkbutton; $cb -> configure( -text => $fl, -command => [ sub{if (${$_[0]->cget(-variable)}) {$filesRef->{$fl} = 1} else {delete $filesRef->{$fl}} }, $cb], ); $cb->pack( -anchor => 'nw', ); } $fileFrame->Button( -text => 'Display Files', -command => [sub{&displayFileContents($text, $filesRef)}], )->pack( -anchor => 'w', );

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - Entry An entry is a widget that is most commonly used in order to enable the user to enter a value in to a variable. Note: we are still in the subroutine we started for the buttons my $entry = $entryFrame->Entry->pack(-side=>'left'); $entryFrame->Button( -text => 'Manual Select', -command => [ sub{%$filesRef = (); $filesRef->{$entry->get}=1; &displayFileContents($text, $filesRef) }], )->pack(-side=>'right');

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk The following slides uses labels again, once again in the subroutine, in order to make it clear to the user what he/she is seeing This marks the end of displayDirAndFiles $dirFrame->Label( -text => File::Spec->rel2abs("."), )->pack; $fileFrame->Label( -text => 'Files' )->pack; } # end of the subroutine

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - FileSelect The FileSelect widget allows the user to browse through a directory tree and choose single file. It receives as an input the directory from which to start browsing. This widget will only be displayed when the Show() method is called on it's reference. The widget returns either when a file is selected (in which case it return filename of the selected file) or until the 'cancel' button is pressed (in which case it returns an empty string)

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - FileSelect my $fileSel = $autoFileFrame->FileSelect( -directory => $curdir, ); $autoFileFrame->Button( -textvariable => \$curdir, -width => 40, -relief => 'groove', -command => [ sub { %curfiles = (); my $file = $fileSel->Show; if ($file) { $curfiles{$file} = 1; &displayFileContents($text, \%curfiles); } }], )->pack( -side => 'bottom', );

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - FileSelect

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - Scrolled The Scrolled widget adds scroll bars to whichever widget is passed to it as a parameter at the places indicated. This widget can't be used on its own. We will demonstrate it together with the Text widget (next slide).

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk – Text The Text widget creates a window within the parent widget and allows text to be displayed and edited Notice that this is the $text that we assumed to be declared on slide Perl::Tk - ButtonsPerl::Tk - Buttons my $text = $fileDisplayFrame->Scrolled( 'Text', -scrollbars => 'se', -wrap => 'none', )->pack( -fill => 'x', );

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk – End of Example In order to neatly wrap thing us, we have to implement the subroutine displayFileContents that we assumed to be defined on slide Perl::Tk - ButtonsPerl::Tk - Buttons

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk – End of Example sub displayFileContents{ my $textWinRef = shift; my $filesRef = shift; my $fileContents = ''; $textWinRef->delete('1.0','end'); local $/ = undef; foreach (sort keys %$filesRef) { if (-T) { open (FILE,"$_") or next; $fileContents.= ; close FILE; } else { $fileContents.= "$_ is not a text file\n" } $fileContents.= '*' x 10; $fileContents.= " End of file: $_ "; $fileContents.= '*' x 10."\n\n\n"; } $textWinRef->insert('end',$fileContents); }

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc Perl::Tk - bind The bind method associates callbacks with X events. If callback is specified, bind will arrange for callback to be evaluated whenever the event(s) given by sequence occur in the window(s) identified by $widget or tag. If callback is an empty string then the current binding for sequence is destroyed, leaving sequence unbound. You can use any number of events such as:  Key presses, releases (and sequences thereof)  Mouse moves  Mouse wheel $widget->bind(" ", sub { }); For more information, refer to:

TM Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc