TIMED INPUTDIALOG
Author SGP
Message No.

http://groups.yahoo.com/group/power-pro/message/13867

File Name scr_TimedInputDialog.powerpro [version 1.0 available in the files section of the Yahoo group. Updated version 1.1 presented here]
Requirements Event Plugin, MiscPlugin, Map Plugin, Win Plugin, ppBang.exe
Assumptions ' as the quote character
& as the expression character in PowerPro config.
Purpose Provide a timed input dialog.
Notes:

Application: Extend the built-in inputdialog function such that it automatically closes after a user-specified timeout and returns default values.

The built-in inputdialog function can be used to prompt for up to six input values as combo boxes, plain text fields, or check items. It's quite powerful, but it lacks a way to return after a user-specified timeout. Function @TimedInputDialog() in the following script extends inputdialog while retaining a similar call interface.

Interesting techniques:
Start by studying @TimedInputDialog first. It makes heavy use of the event plugin. For each TimedInputDialog it creates two events, e and e1. e is created first to countdown the inputdialog window and handle stop triggers. At this point the inputdialog window doesn't exist yet. Then e1 is created to wait for a new builtin inputdialog window. In order to support concurrent inputdialogs, the inputdialog window caption is set to a unique string. When e1 matches that unique string, it stores the window handle in a global map, sets the caption to a user-specified title and terminates itself, leaving timeout management to event e. Eventually e either self-destroys when the timeout expires, or is destroyed by the script because the user pressed the OK button.

A key idea in this implementation is to store values that are associated with events in a global map named gmTimedInputDialog. This makes it possible to consistenly retrieve return/status values without knowing whether the inputdialog terminated because of a timeout or because the user closed it. The global map is also used to store the inputdialog caption and the window handle. Thus the map is treated as an "array of records". To address a field in the record, a string index is used, for instance "h"+e addresses the "h" field of the e-th record, where e is the unique event handle returned by the event plugin.

Finally, the first part of this script, before @TimedInputDialog, demonstrates how to call @TimedInputDialog. It is interesting in its own right, because it shows how to spawn multiple concurrent TimedInputDialogs by means of events.

For more details you really need to study the code below.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

PURPOSE
Demonstrate TimedInputDialog() function, see @TimedInputDialog in this file

CONFIGURATION FOR THIS SCRIPT
Required Plugins and Programs:
- event v.2003.11.31 included in PP3.8.01 package: see .@TimedInputDialog
- map v.2003.02.16:   see .@TimedInputDialog
- win: v 2003.01.31   see .@TimedInputDialog
- miscplugin: sleep service
- ppbang.exe: (temporary, until event plugin is fixed)

Set ' as the quote character and & as the expression character in PowerPro config.

Change History:
20031127 v1.0  base version
20031201 v1.1  use event plugin version 2003 11 30

Documentation:
All comments in this file.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

local xInput

; do NOT declare variables gx* as local!
global gxMount=1
xInput="gxMount=Mount network volumes??"

global gxSkip=0
xInput="gxSkip=Skip startup programs??,"++xInput

global gxFolder="C:\"
xInput="gxFolder=Explore Folder??C:\|C:\Windows,"++xInput

if( 1 != messagebox("okcancel information", "2 independent dialogs will run at the same time.'ro Upper left dialog times out after 30 s'r   & shows results with built-in messagebox.'ro Lower left dialog times out after 60 s'r   & returns value to  external messagebox.'rPress OK when you are ready to start.'rPRESS CANCEL if your event plugin version < 30-Nov-03","Demo "++scriptname) )
    quit

;; On Win9x I get strange error messages from PP after each instance of
;; .@TimedInputDialog _in this demo_ terminates. These error messages do
;; not occur on Win2k. Moreover, they seem to occur only because of the
;; elaborate way that I chose for demoing .@TimedInputDialog (see the lines
;; marked with #@#@ below), that is by "spawning" the dialogs "in the
;; background" usingthe event plugin + a workaround for a known plugin bug.
;; As far as I've been able to test calling .@TimedInputDialog not from an
;; event, everything works fine and there are no error messages on Win9x.
;messagebox("ok warning", "On Win98 you may get two strange error messages from PowerPro.'rIt is safe to ignore them and continue running this script by'rpressing ESC when the errors are displayed.'rSee &(scriptname).powerpro for a full explanation.", "Demo behaves differntly on Win9x vs Win2k")
;
;; #@#@ Start upper left dialog "in the background"
;; #@#@ Important: event.destroythis MUST be exactly where it is, to work around
;; #@#@ a PP crash, see http://groups.yahoo.com/group/power-pro/message/14378
;event.createms(1,1,"event.destroythis'r.&(scriptname)@UpperLeftDialog")
;; #@#@ Start lower left dialog "in the background"
;event.createms(1,1,"event.destroythis'r.&(scriptname)@LowerLeftDialog('"&(xInput)'")")

; Start upper left dialog "in the background"
event.createms(1,1,".&(scriptname)@UpperLeftDialog")
; Start lower left dialog "in the background"
event.createms(1,1,".&(scriptname)@LowerLeftDialog('"&(xInput)'")")

quit

@UpperLeftDialog
.@TimedInputDialog(30,"","","10,100")
quit

@LowerLeftDialog
local button=.@TimedInputDialog(60, "MyDialog", arg(1),"10,330")
messagebox("ok information","MyDialog returned &(button). See full documentation'rin &(scriptname).powerpro.", "MyDialog")
quit