20,741
edits
Line 232: | Line 232: | ||
Once the underlying script is working well enough, we can look into providing a GUI on top of the script using the Canvas GUI library: | Once the underlying script is working well enough, we can look into providing a GUI on top of the script using the Canvas GUI library: | ||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> | ||
var (width,height) = (320,250); | |||
var (width,height) = (320, | |||
var title = 'GCA Dialog '; | var title = 'GCA Dialog '; | ||
Line 246: | Line 245: | ||
window.del = func() | window.del = func() | ||
{ | { | ||
print("Cleaning up window:",title,"\n"); | |||
call(canvas.Window.del, [], me); | |||
}; | }; | ||
Line 275: | Line 273: | ||
if (focus) | if (focus) | ||
input.setFocus(); | input.setFocus(); | ||
} # setupLabeledInput() | |||
var validateAircraftRoot = func(input) { | |||
} | |||
var validateAirport = func(input) { | |||
} | |||
var validateRunway = func(input) { | |||
} | |||
var validateGlidepath = func(input) { | |||
} | } | ||
var validateTouchdownOffset = func(input) { | |||
} | |||
var inputs = [ | var inputs = [ | ||
{text: 'Aircraft root property:', default_value:'/position', focus:1, callback:nil, tooltip:nil, validate: | {text: 'Aircraft root property:', default_value:'/position', focus:1, callback:nil, tooltip:nil, validate: func return 0, convert:nil}, | ||
{text: 'Airport:', default_value:'KSFO', focus:0, callback:nil, tooltip:nil, validate: | {text: 'Airport:', default_value:'KSFO', focus:0, callback:nil, tooltip:nil, validate: func return 0, convert:nil}, | ||
{text: 'Runway:', default_value:'28R', focus:0, callback:nil, tooltip:nil, validate: | {text: 'Runway:', default_value:'28R', focus:0, callback:nil, tooltip:nil, validate: func return 0, convert:nil}, | ||
{text: 'Glidepath:', default_value:'3.00', focus:0, callback:nil, tooltip:nil, validate: | {text: 'Glidepath:', default_value:'3.00', focus:0, callback:nil, tooltip:nil, validate: func return 0, convert:nil}, | ||
{text: 'Touchdown Offset (m):', default_value:'0.00', focus:0, callback:nil, tooltip:nil, validate: | {text: 'Touchdown Offset (m):', default_value:'0.00', focus:0, callback:nil, tooltip:nil, validate: func return 0, convert:nil}, | ||
]; | ]; | ||
Line 290: | Line 304: | ||
} | } | ||
var validateFields = func() { | |||
foreach(var f; inputs) { | |||
var result = f.validate(); | |||
if (result == 1) { | |||
canvas.MessageBox.critical( | |||
"Validation error", | |||
"Error validating "~f.text, | |||
cb = nil, | |||
buttons = canvas.MessageBox.Ok | |||
); | |||
} # error handling | |||
} # foreach | |||
} # validateFields() | |||
# click button | # click button | ||
Line 299: | Line 329: | ||
# add code here to react on click on button. | # add code here to react on click on button. | ||
# TODO: toggle all fields read-only | # TODO: toggle all fields read-only | ||
print("Button clicked !"); | validateFields(); | ||
# print("Button clicked !"); | |||
}); | }); | ||
myLayout.addItem(button); | myLayout.addItem(button); | ||
</syntaxhighlight> | </syntaxhighlight> | ||