Software / Reginald / Examples / Loop1.rex

Search 搜索
Home Home

/* An example of opening several windows simultaneously, and allowing the
 * user to interact with them all at once. We create a Main Window, and
 * numerous Child Windows. Each window has only 1 Group in it. That's not to
 * say that you can't have more Groups in a window, but just that it simplifies
 * this example. Then we do a message loop, letting the user choose which window
 * to interact with. Some of the windows have a Group which causes RXMSG() to
 * return (ie, REPORT Flag set). Other windows have the RESULT flag set so that the
 * user can end by pressing ESC or ENTER. Of course, clicking upon a CLOSE BOX
 * always causes RXMSG() to return. We check the RXWIND variable and do some
 * appropriate processing for that window -- namely, we just print out the
 * returned value for that window's groups. We don't use the INTERPRET instruction
 * here, but LOOP2.rex shows you how to utilize that to make a program that is
 * easier to read/edit.
 * We also open all windows as CHILD windows.


/* Trap HALT and SYNTAX in any scripts we call which don't
 * trap HALT or SYNTAX themselves.

/* Trap SYNTAX/ERROR/HAT, and ask for ERROR raising */

/* ================ Create "Main Window" window =============== */
/* First Group is ENTRY */
rxtype.1 = 'ENTRY'

/* Use of a control in this group causes RXMSG to return */
rxflags.1 = 'REPORT'

/* Labels for each entry, and Groupbox. Note: 3rd entry has no label */
rxlabel.1 = 'Label|Second||Fourth|All'

/* Variable name where the text "typed into" the entries is stored */
rxval.1 = 'TEXT'

/* INFO not needed */

/* ControlsPerLine, X Position, Y Position, Width */
rxpos.1 = '2 10 20 45'

/* The text for the 4 entries */
text.1 = 'Hello'
text.2 = 'Hi'
text.3 = ''         /* A blank entry initially */
text.4 = 'More text'

/* Default size and position */
rx = ''

/* Specify NOCLOSE (since we'll do the closing ourselves, and also
 * RESULT so that RXMSG returns upon ESC or ENTER
CALL RXCREATE('Rx', 1, 'Main Window', 'SIZE|NOCLOSE')

/* ================ Create "Checkmarks"  window =============== */
/* First Group is CHECK */
rx2type.1 = 'CHECK'

/* Use of a control in this group causes RXMSG to return */
rx2flags.1 = 'REPORT'

/* Labels for each button, and Groupbox */
rx2label.1 = 'One|Two|Three|Four|Choices'

/* INFO not needed */

/* Default choice for Checkmarks is none */
rx2val.1 = ''

/* ControlsPerLine, X Position, Y Position, Width=0 */
rx2pos.1 = '2 7 20'

rx2 = ''

/* ================== Create "Spin Me" window ================= */
/* First Group is SPIN */
rx3type.1 = 'SPIN'

/* Use of a control in this group causes RXMSG to return */
rx3flags.1 = 'REPORT'

/* Max, Min, Label for each spin, and groupbox */
rx3label.1 = 'Range 1:|Range 2:|Try us'

/* Values for each spin */
rx3val.1 = '64 19'

/* Min/Max for each spin */
rx3info.1 = '0 255 10 20'

/* ControlsPerLine, X Position, Y Position, Width */
rx3pos.1 = '1 10 20 70'

rx3 = ''

/* ================= Create "Understand?" window ================ */
/* First Group is PUSH */
rx4type.1 = 'PUSH'

/* A RESULT group of buttons. Also BOOL, so
 * return RXSUBID = 1 for even-numbered buttons, or 0 for
 * odd-numbered buttons.
rx4flags.1 = 'BOOL|RESULT'

/* Give me "Yes" and "No", no groupbox */
rx4label.1 = 'No|Yes|'

/* No default value for button */
rx4val.1 = ''

/* ControlsPerLine, X Position, Y Position */
rx4pos.1 = '-1 3 3'

rx4 = ''

/* ============= Message loop on the windows ============ */

   /* Because we have more than 1 window open and do not specify a WindowID
    * to RXMSG(), the user can interact with any of the open windows. Therefore,
    * we can't be sure which window will cause RXMSG() to return. We'll need to
    * check the RXWIND variable for that. RXMSG() will also set RXID and RXSUBID.
    * REXX Dialog may also set the dimensions variable if the window is resized.
    * Also, because all of our windows are NOCLOSE here, REXX Dialog will set the
    * VAL variable for only the one control that caused RXMSG() to return (if
    * indeed a control was manipulated).
    * NOTE: Here, all of our windows are NOCLOSE. RXMSG() will return if the user
    * clicks the CLOSE BOX of a window. But the window won't be automatically
    * closed. We'll do the closing ourselves with an explicit call to RXMSG() using
    * an 'END' operation. There's one gothca here. If we eventually close all of
    * the windows (including the Main Window), and make another call to RXMSG(),
    * then RXMSG() will report an ERROR (ie, "No open REXX Windows." error message).
    * So make sure that you have at least one window open before you ever call RXMSG()
    * (with the exception of simply calling RXMSG(,'END')). In fact, our way out
    * of here is to EXIT after we detect that the user has clicked on our first
    * Window's CLOSE BOX.

   /* Wait on the window(s). We go to sleep while user manipulates windows,
    * until such time as the user presses ESC or ENTER, or tries to close a window
    * using its CLOSE BOX, or uses a RESULT Group or a Control within some Group
    * that has its REPORT Flag set, or an abort signal. Other things that could
    * cause RXMSG() to return are a window timeout, or if the user pressed a key
    * in a window with its KEYS Flag set, or user resizes a window with its NEWSIZE
    * flag set... but we haven't utilized those features here.
   CALL RXMSG()  /* NOTE: No windowID arg means non-modal state. No operation
		   arg means an operation of PROCESS */

   /* RXWIND now specifies which window woke us up. (The window is still
    * there because we specified NOCLOSE and didn't do an operation that
    * causes a window closure). The RXID, RXSUBID, and RXWIND variables
    * (and perhaps the dimensions variable for that window) have been setup
    * according to what caused RXMSG() to return.

   /* Did user press ESC or click on the CLOSE BOX? */
   IF rxid == '' THEN DO
      CALL RXSAY('"'||rxwind||'" closed.')

   /* Note that we haven't set the KEYS flag of any window, nor
    * specified any accelerator items, so we don't need to check for
    * any other non-numeric values of RXID.

   /* If user didn't abort, then display the value strings for this window.
    * IMPORTANT: If he didn't abort, then he either pushed some SUCCESS (ie,
    * OK, RETRY, ENTER, etc) or FAILURE (ie, CANCEL, IGNORE, NO, etc)
    * button in a RESULT Group, or he used some Group whose 'REPORT' Flag
    * we set, or he pressed the ENTER key while the window itself had the
    * focus, or a timeout occured if we setup a timer for this window, or
    * some key was pressed if the window had its KEYS Flag set.
    * If we had a RESULT Group with a FAILURE type button in the window,
    * and that caused RXMSG to return, normally we'd check the value(s) of that
    * Group, and if an odd number, abort any operation. (For BOOL, we'd
    * abort on 0)

       /* Did user press the ENTER key while the window had the focus? */
       IF rxid == 0 & rxsubid == 'ENTER' THEN DO
          CALL RXSAY('Pressed ENTER on "'||rxwind||'".')

       /* Display the Group #, Control # of the control that caused RXMSG() to return */
       ELSE CALL RXSAY('Group #'||rxid||', Control #'||rxsubid||' ended "'||rxwind||'" window.')


           /* =============== Spin Me Window ================ */
	   WHEN rxwind = "RX3" THEN DO
               /* Display spin values for this group, one spin at a time */
	       DO i = 1 TO 2
                   CALL RXQUERY(rxwind, , 'KNOB', 1, i)
                   CALL RXSAY('Spin Me Group 1, Knob #'||i||' = '||knob)

	   /* =============== Checkmarks Window =============== */
	   WHEN rxwind = "RX2" THEN DO
              /* NOTE: For a NOCLOSE window, a Checkmark Group's value
               * is 1 for 'On' or 0 for 'Off'.
               IF rxid > 0 THEN DO
 	          IF rx2val.1 == '1' THEN CALL RXSAY('Checkmark is On')
	          ELSE CALL RXSAY('Checkmark is Off')

	   /* ============== Understand? Window ============== */
	   WHEN rxwind = "RX4" THEN DO

              /* See IMPORTANT above. We know that Group 1 in this window is a
               * RESULT button. Normally, we'd check that group's value, and if
               * it's an odd number, abort any operation that this window was
               * supposed to provide us input for. Since we asked for YES and NO
               * buttons, and also specified BOOL result, RXSUBID will
               * be 1 for YES and 0 for NO
	       i = 'NO'
	       IF rxsubid THEN i = 'YES'
	       CALL RXSAY('Understand? Group 1, result is '||i)

	   /* ================ Main Window ================= */
	   WHEN rxwind = 'RX' THEN DO

              /* Display the text for the selected entry */
              IF rxid > 0 THEN DO
                 CALL RXSAY('Entered text is "'||text.rxsubid||'"')

      END /* SELECT */

   END /* ELSE DO */

   /* Close this window (ie, END operation). NOTE: You might not want to do this
    * without checking RXWIND. After all, we could be closing our Main Window
    * right now. You might want to continue leaving that window open, or maybe
    * only close it if the user pressed ESC or clicked the CLOSE BOX or selected
    * a CANCEL/NO/IGNORE/OFF button in a RESULT Group.
   CALL RXMSG(rxwind, 'END')

   /* If it's our 'Main Window', close everything down */
   IF rxwind = 'RX' THEN SIGNAL HALT

/* Do another message loop */

/* ==================== Error Handling ====================== */
    CALL RXSAY(CONDITION('D') || '0D0A0D0A'x || SOURCELINE(sigl),,'Error '||condition('E')||' at line '||sigl)

    /* NOTE: CONDITION('D') fetches error message. CONDITION('E') fetches the
     * error number. SIGL is the line number where the error occurred.
     * Rexx Dialog has already displayed a message since we specified DISPLAY
     * option.
© Thu 2017-6-22  Guidance Laboratory Inc. Hits:0 Last modified:2013-06-18 23:35:08