1\documentclass[12pt]{article} 2\usepackage{graphicx} 3\def\key#1{{\bf #1}} 4 5\begin{document} 6\title{How the GUIB works} 7\author{Anton Kokalj} 8\maketitle 9\begin{abstract} 10 This document describes briefly the GUIB: (i) how it works, and (ii) 11 how to make a GUI application by using the GUIB engine. It is highly 12 recommended that the document from the GUIB web page entitled {\em 13 Description} is read first. 14 \\[1em] 15% {\bf BEWARE:} this document is in under preparation ... 16\end{abstract} 17 18\tableofcontents 19 20\section{The easiest way} 21 22The easiest way to create a simple GUI application, is to use the {\tt 23 guib} script that comes with GUIB package. Let say that your module 24definition-file is named {\tt myGUI.def}, then a simple GUI will be 25constructed by the following execution: 26\begin{verbatim} 27guib myGUI.def 28\end{verbatim} 29 30To explain how the {\tt guib} script works, the following diagram is 31provided: 32 33\includegraphics[width=1.0\textwidth]{diagrams/Guib.png} 34 35This diagram shows that the module definition-file is source from the 36\key{loadModule} procedure. Technically, the module definition-file is 37a Tcl script, which uses the GUIB library. The whole script is 38embedded inside the \key{module} keyword, which is a wrapper for the 39\key{moduleObj} class. This means that by a call to \key{module} an 40object of \key{moduleObj} type is constructed. This is a complex 41object, and it holds the whole GUI definition. 42 43To illustrate---from programming point of view---how the definition of 44the GUI is stored in the \key{moduleObj} type object, let us consider 45the following example: 46 47{\small 48\begin{verbatim} 49module \#auto -title "Testing" -script { 50 page p1 -name "Page No.1" { 51 line l1st -name "1st line" { 52 var title -label "Title:" 53 var code -label "Code:" 54 } 55 line l2nd -name "2nd line" { 56 var description -label "Description:" 57 } 58 } 59 line llast -name "last line" { 60 var conclusion -label "Conclusion:" 61 } 62} 63\end{verbatim} 64} 65 66Here the following GUIB keywords are used: \key{module}, \key{page}, 67\key{line}, \key{var}. The GUIB keywords can be divided into two 68groups: objects and items. The keywords such as \key{page} and 69\key{line} are object-keywords as they construct new object of a given 70type, while the \key{var} keyword is an example of the item-keyword, 71i.e., item keywords do not create new objects, but their content is 72stored in corresponding object-keyword. Which GUIB keyword is object- 73or item-like can be guessed from the syntax. Consider the following: 74{\small 75\begin{verbatim} 76line l1st -name "1st line" { 77 var title -label "Title:" 78 var code -label "Code:" 79} 80\end{verbatim} 81} Obviously, the \key{line} keyword is an object-keyword, and in this 82examples it holds two \key{var} item-type keywords. 83 84The base-class of keyword objects is \key{keywordObj} class. This 85class possesses a mechanism for storing the information of the module 86definition file in hierarchical fashion. Let say that we want to 87retrieve all information of the module definition file that was 88already stored in \key{moduleObj} type object. This will be done 89recursively and will look like this: 90 91{\small 92\begin{verbatim} 93proc retrieve_and_DoWhatever {obj} { 94 95 set NItem [$obj getID] 96 for {set id 0} {$id <= $NItem} {incr id} { 97 98 # check if $id keyword is object-type !!! 99 set childObj [$obj getChild $id] 100 101 if { $childObj != "" } { 102 # 103 # keyword is OBJECT-type, manage it recursively 104 # 105 ... 106 retrieve_and_DoWhatever $childObj 107 ... 108 } else { 109 # 110 # keyword is ITEM-type 111 # 112 ... 113 } 114 } 115} 116\end{verbatim} 117} 118To illustrate more schematically, how the information about the 119module-definition file is stored, the following diagram shows 120this graphically for the above \key{module \#auto -title "Testing" 121 -script \{...\}} example. 122 123\includegraphics[width=0.5\textwidth]{diagrams/parsing.png} 124 125 126\section{A more elaborate way} 127 128The GUI constructed by the {\tt guib} script can only hold one module 129definition file. Moreover no configuration is possible. If we want to 130create a configurable GUI that will be able to create/manipulate 131several different input files, than a \key{GUI} class provided by the 132GUIB package can be used. Below scheme shows the idea in diagrammatic 133fashion: 134 135\includegraphics[width=1.0\textwidth]{diagrams/myGUI.png} 136 137Now let us do a sample GUI application that will use the \key{GUI} 138class to construct a configurable GUI, which will be able to 139create/manipulate several input files. Let's say that the module 140definition files for these inputs are stored in files {\tt 141 myInput-1.def}, and {\tt myInput-2.def}. Let's say we also have help 142files with description of both input formats stored in files {\tt 143 myInput-1.html}, and {\tt myInput-2.html}. Now we have to create a 144GUI script, for example: 145 146{\footnotesize 147\begin{verbatim} 148#!/bin/sh 149# next line restarts wish \ 150exec wish 151 152# ------------------------------------------------------------------------ 153# INITIALIZATION 154# ------------------------------------------------------------------------ 155 156# check if GUIB environmental variable is defined 157 158if { [info exists env(GUIB)] } { 159 # instruct the Tcl where to search for GUIB package 160 lappend auto_path [file join $env(GUIB)] 161} else { 162 # we assume that GUIB package is on some "standard" path and Tcl 163 # will find it. 164} 165 166# load a Guib package 167package require Guib 0.1.1 168 169# withdraw the "." toplevel window, and bind the <Destroy> event 170# to ::guib::exitApp 171wm withdraw . 172bind . <Destroy> ::guib::exitApp 173 174 175# ------------------------------------------------------------------------ 176# GUI construction 177# ------------------------------------------------------------------------ 178 179# construct the GUI object 180set gui [::guib::GUI \#auto -title "My 1st GUI" -appname MyGUI] 181 182# Add modules. The syntax is: 183# ------------ 184# $gui addModule module $moduleID $moduleLabel $moduleFile 185# 186$gui addModule module inp1 "My Input-1" myInput-1.def 187$gui addModule module inp2 "My Input-2" myInput-2.def 188 189# Add help. The syntax is: 190# --------- 191# $gui addHelp help $helpID $helpLabel $helpFile 192# 193$gui addHelp help help1 "Help for Input-1" myInput-1.html 194$gui addHelp help help2 "Help for Input-2" myInput-2.html 195 196 197# 198# some extra configuration of the GUI 199# 200$gui extra { 201 # 202 # add a logo to toolbar panel 203 # 204 image create photo myLogo -format gif -file myLogo.gif 205 206 set tb [component toolbar] 207 set logo [$tb add label logo -image myLogo] 208 pack configure $logo -side right 209} 210\end{verbatim} 211} 212 213When GUI defined in above file will be launched, an application 214toplevel window with menubar and toolbar will appear. But none of the 215GUI will be rendered. This can be done by selecting either \key{File 216 $\rightarrow$ New Input ...} or \key{File $\rightarrow$ Open Input 217 ...} menu. The following diagram shows a programming scheme for 218\key{New Input ...} method: 219 220\includegraphics[width=1.0\textwidth]{diagrams/GUI-new.png} 221 222The scheme for the \key{Open Input ...} is very similar. In fact the 223``open'' method first call the ``new'' method, which constructs an 224appropriate GUI, and then an existing file is loaded in that GUI. The 225scheme is shown here: 226 227\includegraphics[width=.5\textwidth]{diagrams/GUI-open.png} 228 229\section{An example of real GUI application: PWgui} 230 231PWgui is a GUI for PWscf set of numerical programs for electronic 232structure calculations. It is a real GUI application that uses the 233GUIB engine. It is only a slightly more complicated than above GUI 234example. Here is a diagram showing the structure of the PWgui 235application: 236 237\includegraphics[width=1.0\textwidth]{diagrams/PWgui.png} 238 239\section{File and directory structure of GUIB} 240 241\begin{description} 242\item[Directory structure:]~\\ 243 \begin{tabular}[t]{ll} 244 $\bullet$~\tt lib/ & auxiliary Tcl/Tk routines, i.e., tclUtils.tcl, tkUtils.tcl\\ 245 $\bullet$~\tt doc/ & programming documentation generated from source-code\\ 246 $\bullet$~\tt examples/ & a few examples (definition files: *.tcl; input files: *.inp)\\ 247 $\bullet$~\tt external/ & external \key{cmdline} library\\ 248 $\bullet$~\tt images/ & \\ 249 $\bullet$~\tt src/ & GUIB source code directory\\ 250 \end{tabular} 251\item[Description of some src/ files:]~\\ 252 \begin{tabular}[t]{ll} 253 $\bullet$~\tt moduleObj.itcl & implementation of \key{moduleObj} class\\ 254 $\bullet$~\tt keywordObj.itcl & implementation of \key{keywordObj} class\\ 255 $\bullet$~\tt guibKeywords.itcl & implementation of all GUIB keywords\\ 256 $\bullet$~\tt build.itcl & build Tk-based GUI defined by module definition file.\\ 257 $\bullet$~\tt open.itcl & open an input file\\ 258 $\bullet$~\tt save.itcl & save edited input file\\[1em] 259 $\bullet$~\tt guib-keywords-def.tcl & definition of options of GUIB-keywords\\[1em] 260 $\bullet$~\tt gui.itcl & application GUI: procs for "simple-GUI" and\\ 261 & implementation of more elaborate \key{GUI} class\\[1em] 262 \end{tabular} 263\end{description} 264\end{document} 265 266%%% Local Variables: 267%%% mode: latex 268%%% TeX-master: t 269%%% End: 270