Programmer Guide/Examples/gui basic example: Difference between revisions

From STX Wiki
Jump to navigationJump to search
mNo edit summary
mNo edit summary
 
Line 13: Line 13:
     2006-11-13  First implemented
     2006-11-13  First implemented
     2007-10-04  Dialog button now toggles function color
     2007-10-04  Dialog button now toggles function color
        2009-06-25  Modernising
    2009-06-25  Modernising
--*/
--*/
[macro gui_basic_example #standalone=1]
[macro gui_basic_example #standalone=1]
Line 19: Line 19:
     // create and configure display
     // create and configure display
     //
     //
     #display := new display * 'Display Title' 2 1 2 /Dialog=Below
     #display := new display * 'Display Title' 1 1 /Dialog=Above
     if '$#display[?]' != 'display' then
     if '$#display[?]' != 'display' then
         em -1 ; display creation failed ($emsg)
         em -1 ; display creation failed ($emsg)
     end
     end
     $#display enabled restore 0 0 600 600
     $#display enabled restore 0 0 600 600
    // create dialog
    #dlg := new menu * $#display
    $#dlg * button 0 0 'OK' * 8 /Defaultbutton
    $#dlg * BUTTON 1 0 '&Cancel' * 8 /w
    $#dlg enabled restore 0 0 200 200 /layout
     //
     //
     // create spu to generate data for graph
     // create spu to generate data for graph
Line 36: Line 30:
     #nValues := 100
     #nValues := 100
     #vector := eval fill($#nValues,0,1)
     #vector := eval fill($#nValues,0,1)
        // create and run spu
    // create and run spu
     #spu := new spu * table2output $#vector 1 0 1 /n
     #spu := new spu * table2output $#vector 1 0 1 /n
     if '$#spu[?]' != 'spu' then
     if '$#spu[?]' != 'spu' then
         em -1 ; spu creation failed ($emsg)  
         em -1 ; spu creation failed ($emsg)  
     end
     end
        //
    //
     // create and configure graph
     // create and configure graph
     //
     //
     #graph := new graph g1 1 $#display 0 0
     #graph := new graph * 1 $#display 0 0
     if '$#graph[?]' != 'graph' then
     if '$#graph[?]' != 'graph' then
         em -1 ; graph creation failed ($emsg)
         em -1 ; graph creation failed ($emsg)
Line 50: Line 44:
     theGraph := $#graph // shell variable used for graph commands in message handler
     theGraph := $#graph // shell variable used for graph commands in message handler
     $#graph axis both both * yellow both both
     $#graph axis both both * yellow both both
    $#graph bgcolor red yellow
     $#graph xscale 0 $#nValues-1 '' 'X'
     $#graph xscale 0 $#nValues-1 '' 'X'
     $#graph yscale 0 $#nValues-1 '' 'Y'
     $#graph yscale 0 $#nValues-1 '' 'Y'
Line 59: Line 52:
     //
     //
     $#spu run 1
     $#spu run 1
    #graph := new graph g2 1 $#display 1 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 bgcolor blue green
    $#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
    $#display height 2 1
     // return if this is not a standalone call
     // return if this is not a standalone call
     // caller should clean up
     // caller should clean up
     if '$#standalone' != 1 exit 1
     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
     // process messages until display is close

Latest revision as of 11:42, 29 May 2015

/*++
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