SOB – b – Event handler and menu

Let us expand the simple “Hello World” window , to have a menu and a shut-down event handler.

' create a hello world type application, in a standard window structure
newscript ' has an internal call to SOB("new")
' -----------------------------------------------------
' create a new window without a parent (hence the first parameter is 0 = no parent )
' A window is a container, which positions its children one under the other in a
' simple column. A window container does not impose any dimensioning rules on its children SOBs-
'
dim myWindow = sob (0, "add","window","Hello World")' Define a callback to handle a click on the TOP Right "X"
' Callbacks are discussed in detail in the CALLBACK help option
function ClickMyWindow ( sobid )
' delete the SOB myWindow , automatically deletes all of its child SOBs
sob ( myWindow, "delete")
End function
'
' Associate the callback with myWindow
sob ( myWindow , "ON"   , "CLICK"   , "ClickMyWindow" )
'    ( target , action , qualifier , parameter )

' add a menu bar to  myWindow
dim myMenuBar = sob (myWindow ,  "add" ,  "menu"   , "bar" )
'                   ( target  , action , qualifier , qualifier )

' add a horizonal menu to the menu bar myMenuBar
dim myMenuFile = sob (myMenuBar , "add" , "menu"     , "Horizontal" , "File" )
'                    (target    , action , qualifier , qualifier   , parameter )

' add a menu item to the FILE menu
Dim myFileExit = sob ( myMenuFile , "add" , "menu"    , "Vertical" , "Exit" )
'                    ( target    , action , qualifier , qualifier  , parameter )

' Associate a click / press on the File.Exit menu option with a callback handler
sob ( myFileExit , "ON"   , "CLICK"   , "ClickMyWindow")
'   ( target     , action , qualifier , parameter )

The result of this script is shown in the following screenshot.

Clicking on the menu File / Exit , or on the  x in the top right corner will cause the SOB GUI to shut-down, but the executable will remain running.

To cause the executable to shut-down when the SOB GUI is shut-down, change the callback function ClickMyWindow  to have the quit command:

function ClickMyWindow ( sobid )
' delete the SOB myWindow , automatically deletes all of its child SOBs
sob ( myWindow, "delete")
quit
End function

To hide the executable GUI whilst the SOB GUI is visible, add the following line at the end of the script.

sob( SOBSQLite, "SET", "SHOW", 0 )

 But be warned, you will not be able to see the executable GUI, and you will have to use the Windows TaskManager to stop the executable process! Unless you implement some callback that sets

sob ( SOBSQLITE , "set" "SHOW", 1)

The following lines will add 2 buttons, and a label to the GUI. Since they are added to a “Window”, they define their own sizes and are positioned in a column. For now we do not care about these SOBs’ identities.

sob (myWindow, "add", "button","Push" , "Push button")
sob (myWindow, "add", "button","Radio" , "Radio button")
sob (myWindow, "add","label","Label")

And now finally,  one line to cause the Window SOB to shrink to its minimum size.

SOB ( myWindow, "SET" , "SHRINK" )


Run it and the resulting GUI is:

Just as a recap, without comments, the code we needed to create this GUI is:

newscript
dim myWindow = sob (0, "add","window","Hello World")
function ClickMyWindow ( sobid )
sob ( myWindow, "delete")
quit
End function
sob ( myWindow , "ON" , "CLICK" , "ClickMyWindow" )
dim myMenuBar = sob (myWindow , "add" , "menu" , "bar" )
dim myMenuFile = sob (myMenuBar , "add" , "menu" , "Horizontal" , "File" )
dim myFileExit = sob ( myMenuFile , "add" , "menu" , "Vertical" , "Exit" )
sob ( myFileExit , "ON" , "CLICK" , "ClickMyWindow")

sob ( myWindow, "add", "button","Push" , "Push button")
sob ( myWindow, "add", "button","Radio" , "Radio button")
sob ( myWindow, "add","label","Label")

sob ( myWindow, "SET" , "SHRINK" )
sob ( SOBSQLite, "SET", "SHOW", 0 )