SCAlert

part of wslib



An alert window class


Note: not yet SwingOSC compatible


SCAlert( "Are you alerted now?", [ "No", "Yes" ] );



creation:


SCAlert( string, buttons, actions, color, background, iconName, border )


string : a string containing the message to be displayed. You can use $\n characters in it as well

buttons : an Array containing the names of the buttons. It can also contain SCButton states.

buttons defaults to [ "cancel", "ok" ]

actions : an Array containing a function for each button

color : the color of the border stripe around the window and the icon. Defaults to Color.red.alpha_(0.75)

background : the background color of the window. Defaults to white

iconName : the name of the icon to be displayed from DrawIcon. Defaults to 'warning'

border : Should the window have a border? Defaults to true


SCAlert also listens to key strokes. If you type a letter it will find the button of which the name starts with that letter and hit it (just like in most alert windows).


(

SCAlert( "What do you want to hear now?\n

type 'n' for nothing, 's' for a sine wave

and 'p' for a pulse", 

[ "nothing", ["sine wave", Color.red(0.2)], "pulse" ],  // buttons

[ nil, 

{ { Env.sine(0.25, 0.25).kr(2) * SinOsc.ar(440) }.play;  },

{ { Env.sine(0.25, 0.25).kr(2) * Pulse.ar(440) }.play;  } ], // actions

Color.blue(0.2),

iconName: 'sign_$?' );

);



class vars:


modal

if true (default) runs all SCAlerts in modal mode (see SCModalWindow)


elements of the SCAlert:


buttons

An Array of button states for each button


buttonViews

An Array containing all SCButton objects


window

The SCWindow itself


string / string_

actions / actions_

color / color_

background / background_

iconName / iconName_

actions, Colors and iconName can all be changed after creation


onCloseIndex / onCloseIndex_

the index of the button action which is eveluated when the SCAlert window is closed using it's close box.

Defaults to -1, which means that none of the actions is used.


(

a = SCAlert( "hello!" );

a.color = Color.green(0.2);

b = Task({

var i = 0;

loop { 

{ a.iconName = ("wait_" ++ (i = i+(1/16))).asSymbol; }.defer;

  0.1.wait;

  };

}).start;

a.actions = [ { b.stop }, { b.stop } ];

a.onCloseIndex = 0;

)



buttonClosesWindow / buttonClosesWindow_

defaults to true, if false the window is not closed when one of the butons is hit.


buttonLabel ( index ) / buttonLabel_ ( index, newLabel )

changes the name of the button at index


focus ( index )

sets the focus to the button at index


enable ( index ) / disable ( index )

enables or disables the button at index



(

a = SCAlert( "try out these buttons", ["cancel", "disable me", "change text"] );

a.buttonClosesWindow_( false );

a.actions_( [ 

{ a.window.close }, // cancel closes the window

{ a.disable( 1 ); }, 

{ a.string_( "text changed" ); // first hit changes text

a.buttonLabel_( 2, "ok" );

a.actions[2] = { a.window.close; } // next hit closes window

} ] );

)



hit

hits the currently focused button