\documentclass[]{article}
\usepackage{amsmath,graphicx,supertabular,hyperref,tabularx,ifthen}
\title{TIP \#321: Add a [tk busy] Command}
\date{June 26, 2008}
\author{Jos Decoster}
\urlstyle{sf}
\setlength{\parskip}{1ex}
\setlength{\parindent}{0pt}
\def\tipversion$#1${\texttt{\$#1\$}}
\def\tiplangle#1{\ensuremath{<}}
\def\tiprangle#1{\ensuremath{>}}
\def\tipbar#1{\ensuremath{|}}
\def\tipmail#1#2{\(\langle\){\small\expandafter\url{#1@#2}}\(\rangle\)}
\ifx\pdfoutput\undefined
\newcommand{\tipimage}[2]{\typeout{Make sure you download #1.eps}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.eps}}{\includegraphics[width=0.8\textwidth]{#1.eps}}}
\newcommand{\tipxref}[1]{}
\newcommand{\tipxrefend}{}
\else
\newcommand{\tipimage}[2]{\typeout{Make sure you create #1.pdf}\ifthenelse{\lengthtest{0.8\textwidth>#2}\and\lengthtest{0pt<#2}}{\includegraphics{#1.pdf}}{\includegraphics[width=0.8\textwidth]{#1.pdf}}}
\pdfcatalog{/PageMode /UseOutlines}
\newcommand{\tipxref}[1]{\pdfannotlink attr {/C [0.5 0.5 1.0] /Border [0 0 1]} goto name {#1}}
\newcommand{\tipxrefend}{\pdfendlink}
\fi
\newenvironment{tipabstract}{\begin{abstract}}{\end{abstract}}
\begin{document}\maketitle
\begin{center}\begin{tabularx}{\linewidth}{|r@{: }X|}\hline
\textbf{TIP \#321}&\textbf{Add a [tk busy] Command}\\\hline
Author&

Jos Decoster \tipmail{jos.decoster}{gmail.com}
\\
Created&Thursday, \(\text{26}^{\text{th}}\) June 2008\\
Type&Project\\
Tcl Version&\(8.6\)\\
State&Final\\
Vote&Done\\
Version&\tipversion$Revision: 1.6 $\\
Keywords&Tk, BLT, busy\\
Post History&\\
\hline\end{tabularx}\end{center}
\thispagestyle{empty}\pagestyle{empty}
\begin{tipabstract}

The \textbf{blt::busy} commands can be used to make Tk widget busy, with all user interaction blocked and the cursor can be changed to e.g. a clock. This TIP proposes to add this useful feature to Tk.
\end{tipabstract}
\tableofcontents\setcounter{page}{0}\clearpage\pagestyle{plain}

\section{Rationale}

BLT has a lot of very useful commands: \textbf{bgexec}, \textbf{busy}, \textbf{vector}, \textbf{graph} widget, \textbf{barchart} widget, ... But getting BLT to work with the latest releases of Tcl and Tk becomes more and more difficult. Some of the problems I experienced are:
\begin{itemize}
\item{}
internal Tk structures are mirrored
\item{}
interaction with xft fails, so Tk has to be build without xft support
\item{}
the build process is different from the one used in Tcl and Tk
\end{itemize}

Discussions on CLT and \#tcl indicated that extracting functionality from BLT and add it to Tcl and Tk might be a good way to make the blt commands available for every Tcl programmer.

This TIP proposes a way to add the blt::busy command to Tk, based on the code as found in BLT2.4z and the code as found in busy.kit. While adding the code to Tk, it was rewritten to use the Tcl\_Obj interface and the new option interface. The interface has also been simplified. The \textbf{blt::release} command was not withheld. Because often the same window is made busy again and again, using \textbf{release} in stead of \textbf{forget} might be faster. But when making an application busy, it's because it'll have to wait for another operation and/or process to finish which will typically take a much longer time than the time needed to (re)create the transparent window. The \textbf{names} and \textbf{isbusy} commands were replaced by the new \textbf{current} command. The confusing difference between a window which is busy, a window which was busy but still has the associated transparent window allocated and a window which was busy but no longer has its associated transparent window allocated was removed.

The name of this new Tk command as currently implemented is \textbf{tk busy}, part of the \textbf{tk} command ensemble. Adding it as an option to the \textbf{grab} command might cause confusion as the \textbf{tk busy} command has the opposite functionality of the \textbf{grab} command. It blocks all user interaction rather than redirecting it to one widget.

\section{Specification}

The \textbf{tk busy} command is an ensemble with a special feature that any unrecognized subcommand that starts with a period is treated as an invokation of the \textbf{hold} subcommand upon the widget with that name.

\subsection{Hold Subcommand}

\begin{quote}
\textbf{tk busy} \textit{window} ?\textit{option value}?
\end{quote}

\begin{quote}
\textbf{tk busy hold} \textit{window} ?\textit{option value}?
\end{quote}

Makes the window (and its descendants in the Tk window hierarchy) appear busy by ignoring all events sent to the window and its descendants. \textit{Window} must be a valid path name of a Tk widget. A transparent window is put in front of the specified window. This transparent window is mapped the next time idle tasks are processed, and the specified window and its descendants will be blocked from user interactions. Normally update should be called immediately afterward to insure that the hold operation is in effect before the application starts its processing. The following configuration options are valid:

\begin{quote}
\textbf{-cursor} \textit{cursorName} 
\end{quote}

Specifies the cursor to be displayed when the widget is made busy. CursorName can be in any form accepted by Tk\_GetCursor. The default cursor is watch.

\subsection{Forget Subcommand}

\begin{quote}
\textbf{tk busy forget} \textit{window}
\end{quote}

Releases resources allocated by the \textbf{tk busy} command for \textit{window}, including the transparent window. User events will again be received by the specified window. Resources are also released when the specified window is destroyed. \textit{Window} must be the name of a widget previously specified in a \textbf{hold} operation, otherwise an error is reported.

\subsection{Current Subcommand}

\begin{quote}
\textbf{tk busy current} ?\textit{pattern}?
\end{quote}

Returns the pathnames of all windows that are currently made busy. If a \textit{pattern} is given, only the path names of busy windows matching \textit{pattern} are returned.

\subsection{Status Subcommand}

\begin{quote}
\textbf{tk busy status} \textit{window}
\end{quote}

Returns the busy status of a \textit{window}. If \textit{window} presently can not receive user interactions, 1 is returned, otherwise 0.

\subsection{Configure Subcommand}

\begin{quote}
\textbf{tk busy configure} \textit{window} ?\textit{option}? ?\textit{value ...}?
\end{quote}

Queries or modifies the \textbf{tk busy} command configuration options for \textit{window}. \textit{Window} must be the path name of a widget previously made busy by the \textbf{hold} operation. If no options are specified, a list describing all of the available options for window (see \textbf{Tk\_ConfigureInfo} for information on the format of this list) is returned. If \textit{option} is specified with no \textit{value}, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more \textit{option-value} pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns the empty string. Options may have any of the values accepted by the hold operation.

Please note that the option database is referenced through window. For example, if the widget .frame is to be made busy, the busy cursor can be specified for it by either option command:
\begingroup\small\begin{verbatim}
        option add *frame.busyCursor gumby
        option add *Frame.BusyCursor gumby
\end{verbatim}
\endgroup

\subsection{Cget Subcommand}

\begin{quote}
\textbf{tk busy cget} \textit{window option}
\end{quote}

Queries the \textbf{tk busy} command configuration options for \textit{window}. \textit{Window} must be the path name of a widget previously made busy by the \textbf{hold} operation. The command returns the present value of the specified \textit{option}. \textit{Option} may have any of the values accepted by the \textbf{hold} operation.

\section{Reference Implementation}

See SourceForge patch \#1997907 [\url{https://sourceforge.net/support/tracker.php?aid=1997907}]. There is no support for Mac + Aqua in this patch. It compiles on Mac + Aqua and the command will not return errors but will not resort in a \textit{busy} effect. Mac + X11 does work.

\section{Compatibility}

Because the command as proposed above has the same interface and behavior as the \textbf{blt::busy} command, replacing \textbf{blt::busy} with \textbf{tk busy} is all that's needed to switch to the Tk version of the busy command.

The \textbf{tk busy} command is not one-by-one compatible with the \textbf{blt::busy} command, but typical use (\textbf{hold} and \textbf{forget}) will not suffer a lot. Aliases or an ensemble could be used to make transition easier.

\section{Alternatives}

The busy command is available as starkit from \url{http://tcl.tk/starkits/busy.kit}

An alternative would have been to keep the interface from BLT. This would have made transition easier, but would have kept the confusing difference between \textit{forgotten} and \textit{released} busy windows.

\section{Copyright}

This document has been placed in the public domain.

\section{Colophon}

\textit{TIP AutoGenerator --- written by Donal K. Fellows}
\end{document}
