02.03.2014 Views

Tornado

Tornado

Tornado

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3<br />

Launcher<br />

This sort of safeguard is nearly universal in graphical applications, but some<br />

people find it annoying. If you would prefer to take your chances with an<br />

occasional unintended shutdown, for the sake of having the launcher obey you<br />

unquestioningly, this example may be of interest. It shows how to redefine the Quit<br />

command to shut down the launcher without first displaying a query.<br />

To discover what procedure implements the Quit command, examine the launcher<br />

definitions in ${WIND_BASE}/host/resource/tcl/Launch.tcl. Searching there for the<br />

string “Quit” leads us to the following menuButtonCreate invocation, which<br />

shows that the procedure to redefine is called launchQuit:<br />

3<br />

menuButtonCreate File Quit Q {launchQuit}<br />

Example 3-2<br />

Alternate Quit Definition<br />

The following redefinition of the launchQuit procedure eliminates the safeguard<br />

against leaving the launcher accidentally:<br />

#############################################################################<br />

#<br />

# launchQuit - abandon the launcher immediately<br />

#<br />

# This routine is a replacement for the launchQuit that comes with the<br />

# launcher; it runs when Quit is selected from the File menu in place of<br />

# the standard launchQuit, to avoid calling a confirmation dialog.<br />

#<br />

# SYNOPSIS:<br />

# launchQuit<br />

#<br />

# RETURNS: N/A<br />

#<br />

# ERRORS: N/A<br />

#<br />

proc launchQuit {} {<br />

exit<br />

}<br />

An Open Command for the File Menu<br />

Because editing files is a common development activity, it may be useful to invoke<br />

an editor from the launcher. This example defines a File>Open command to run the<br />

editor specified by the EDITOR environment variable. The example is based on the<br />

file selector built into the noticePost Tcl extension.<br />

The code in this example collects the launcher initialization (adding commands to<br />

the File menu, both for this example and for Example 3-1) in an initialization<br />

procedure. In the example, the launcher executes launchExtInit, which adds<br />

87

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!