home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rexxtk12.zip / demo / spectcl / spectest.rexx < prev   
OS/2 REXX Batch file  |  2000-04-23  |  5KB  |  174 lines

  1. /**/
  2. Call Rxfuncadd 'TkLoadFuncs','rexxtk','TkLoadFuncs'
  3.  
  4. If TkLoadFuncs() \= 0 Then exit
  5.  
  6. Trace o
  7.  
  8. call SetupMainWindow
  9.  
  10. /* do our "normal" Rexx/Tk main loop */
  11.  
  12. do forever
  13.    interpret 'call' TkWait()
  14. end
  15.  
  16. exit:
  17. exit
  18.  
  19. /* call the UI code for the main window that was created by
  20.    SpecTcl */
  21. SetupMainWindow:
  22.  
  23.    /* first set a title for our app's main window */
  24.    call TkWm 'title', '.', 'SpecTcl Test App'
  25.  
  26.    /* Now add the menus that we want for the main window.
  27.       SpecTcl doesn't create menus is why we have to do that
  28.       with code.  (Oh, well) */
  29.    
  30.    /* make a menu that will be our menubar */
  31.    menubar = TkMenu('.m1')
  32.  
  33.    /* add a File menu to the menubar.  the file
  34.       menu will 'cascade' off of the menu bar */
  35.    /* create another menu widget to be our file menu
  36.       and tell the menubar menu about it... the "tearoff"
  37.       option, well, just remove it and see what happens.*/
  38.    menu = TkMenu('.m1.m1','-tearoff', 0)
  39.    label = 'File'
  40.    call TkAdd menubar, 'cascade', 'label', 'menu', 
  41.  
  42.    /* now add items to the File menu */
  43.    call TkAdd menu, 'command', '-label', 'Test...', '-command', 'AnotherWin'
  44.  
  45.    /* adding another item... */
  46.    label = 'Quit'
  47.    command = 'exit'
  48.    call TkAdd '.m1.m1', 'command', 'label', 'command'
  49.  
  50.    /* attach the menubar to the main window */
  51.    call TkConfig '.', '-menu', menubar
  52.  
  53.    /* NOW we get to use the UI code generated by SpecTcl...
  54.       Call TCL to load in the UI code with the "source" command. */
  55.    rc = TkTcl('source', 'mdlog.ui.tcl')
  56.  
  57.    /* AND now initialize the window.
  58.       The 1st arg is the name of the window that was created in
  59.       SpecTcl, which is just the name of the file plus an
  60.       underscore and "ui"... The 2nd arg is the TK pathname
  61.       of the window and Since this will be
  62.       our "root" or main window, we are passing the root
  63.       window name, "." 
  64.    */
  65.    rc = TkTcl('mdlog_ui','.')
  66.  
  67.    /* Finally, we'll go ahead and load the other windows
  68.       UI files for the program, but just not initialize
  69.       (and thus display) them right yet */
  70.    rc = TkTcl('source', 'dlog2.ui.tcl')
  71.    
  72.    return
  73.  
  74. /* Display the other window that we 'sourced' in the SetupMainWindow
  75.    routine above */
  76. AnotherWin:
  77.  
  78.    /* make a new toplevel window to load our UI
  79.       design into */
  80.    call TkToplevel '.another'
  81.  
  82.    /* grab it straight off */
  83.    call TkGrab '.another'
  84.  
  85.    /* make the window so it isn't resizable.
  86.       This is what most temporary dialogs are */
  87.    call TkWm 'resizable', '.another', 0, 0
  88.  
  89.    /* create and display the window using the new toplevel */
  90.    call TkTcl 'dlog2_ui', '.another'
  91.   
  92.    return
  93.  
  94. /* A routine to handle when the user presses Okay
  95.    in the dlog2 dialog window */
  96. D2Okay:
  97.  
  98.    /* The name and phone text are in textvariables defined
  99.       in the properties of the text field using SpecTcl.
  100.       These are TK Variables, so we just use TkVar to get
  101.       their value.  Remember that TK variables are case
  102.       specific...  Upper/lower case matters.*/
  103.    name = TkVar('name')
  104.    phone = TkVar('phone')
  105.  
  106.    /* Now let's set the prompt in the main window with that info.
  107.       Note that the name of the objects in SpecTcl are the name
  108.       of the window PLUS the name of the object concated on.  So,
  109.       since we named the label at the bottom of the main window,
  110.       "prompt" that would make it ".prompt" since it is in the main
  111.       window, which is called "." (since it's the root window).*/
  112.    text = 'Your name is' name 'and your phone is' phone '.'
  113.    call TkConfig '.prompt', 'text'
  114.  
  115.    /* Of course,  we should close the little window by just
  116.       destroying it. */
  117.    call TkDestroy '.another'
  118.       
  119.    return
  120.  
  121.  
  122. Up: /* the up button was pressed... fetch the radio button value */
  123.    
  124.    /* The radio buttons are an example of a control that is
  125.       not currently buildable in "native" Rexx/Tk, but since
  126.       it has a "variable" it can be set and queried.
  127.  
  128.       NOTE: The "variable" in radio buttons is what makes them
  129.       mutually exclusive.  Any button that shares the same variable
  130.       will be automatically grouped as a radio button should.  The
  131.       frame around the buttons in the included UI file is just an example
  132.       of using a frame to group elements and is not needed to group
  133.       the radio buttons together. */
  134.  
  135.    radio = TkVar('radio')
  136.  
  137.    text = 'Radio button "'radio'" was pressed.'
  138.    call TkConfig '.prompt', 'text'
  139.  
  140.    /* now clear the radio button variable to clear
  141.       the selection */
  142.    call TkVar 'radio', ''
  143.  
  144.    return
  145.  
  146. Down: /* fetch the slider value */
  147.  
  148.    /* we assigned a textvariable to the scale,
  149.       so we can just fetch that value */
  150.    scale = TkVar('scale')
  151.  
  152.    text = 'Slide at' scale'. Moving back 10.'
  153.    call TkConfig '.prompt', 'text'
  154.  
  155.    if scale >= 10 then scale = scale - 10
  156.  
  157.    call TkVar 'scale', scale
  158.  
  159.    return
  160.  
  161. D2Cancel: /* just kill the window */
  162.  
  163.    call TkDestroy '.another'
  164.    return
  165.  
  166.  
  167.  
  168.  
  169. /****** NOT FINISHED *********/
  170. Around:
  171.    
  172.  
  173.    Return
  174.