Programmer Guide/Examples/gui basic example

From STX Wiki
Jump to navigationJump to search
/*++
Macro:  gui_basic_example
Descriptions:
    Creates a basic graphical user interface,
Parameters:
    #standalone Set to 1 if the script is running on it's own
    (i.e. not called by another script). This is the default.
    Otherwise set to 0.
Author:
    Jonnie White
History:
    2006-11-13  First implemented
    2007-10-04  Dialog button now toggles function color
    2009-06-25  Modernising
--*/
[macro gui_basic_example #standalone=1]
    //
    // create and configure display
    //
    #display := new display * 'Display Title' 1 1 /Dialog=Above
    if '$#display[?]' != 'display' then
        em -1 ; display creation failed ($emsg)
    end
    $#display enabled restore 0 0 600 600
    //
    // create spu to generate data for graph
    //
    // generate some data
    #nValues := 100
    #vector := eval fill($#nValues,0,1)
    // create and run spu
    #spu := new spu * table2output $#vector 1 0 1 /n
    if '$#spu[?]' != 'spu' then
        em -1 ; spu creation failed ($emsg) 
    end
    //
    // create and configure graph
    //
    #graph := new graph * 1 $#display 0 0
    if '$#graph[?]' != 'graph' then
        em -1 ; graph creation failed ($emsg)
    end
    theGraph := $#graph // shell variable used for graph commands in message handler
    $#graph axis both both * yellow both both
    $#graph xscale 0 $#nValues-1 '' 'X'
    $#graph yscale 0 $#nValues-1 '' 'Y'
    $#graph y 0 $#spu.x0 xyplot 1 green lines solid 2
    $#graph x $#spu.x0 /a // set x data and apply all graph settings
    //
    // run spu (sending data to graph
    //
    $#spu run 1
    // return if this is not a standalone call
    // caller should clean up
    if '$#standalone' != 1 exit 1
    //
    // create and configure the dialog
    //
    #dialog := new menu * $#display
    if '$#dialog[?]' != 'menu' then
        em -1 ; dialog creation failed ($emsg)
    end
    $#dialog $#dialog[!controls] button 0 0 'Toggle function color'
    $#dialog enabled restored
    //
    // process messages until display is close
    // by the user
    //        
    setmsghandler display $#display gui_basic_example_mh
    //
    // process dialog messages too
    //
    setmsghandler menu $#dialog gui_basic_example_mh
    AppMode := 1
    do while '$AppMode' != '0'
        GetMessage
    end
    setmsghandler display $#display
    //
    // clean up
    //
    delete $#graph $#display $#dialog $#spu
exit

[MACRO gui_basic_example_mh #objtype #objname #msgid #msgpar]
    if '$#objtype' == display || '$#objtype' == shell then
        if '$#msgid' == Close || '$#msgId' == Exit then
            AppMode := 0    
        end
    else if '$#objtype' == 'menu' then
        if '$#msgid' == 'command' && '$#msgpar' == '0' then
            // toggle function color
            fcolor := COND '$fcolor' == 'green' || '$fcolor' == '' ? 'blue' : 'green'
            $theGraph y 0 * * * $fcolor * * * /Apply
        end
    end
exit 1

Navigation menu

Personal tools