Howto:Implementing a simple GCA system: Difference between revisions

Jump to navigation Jump to search
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,200);
var title = 'GCA Dialog ';
var title = 'GCA Dialog ';


Line 246: Line 245:
window.del = func()
window.del = func()
{
{
  print("Cleaning up window:",title,"\n");
print("Cleaning up window:",title,"\n");
# explanation for the call() technique at: http://wiki.flightgear.org/Object_oriented_programming_in_Nasal#Making_safer_base-class_calls
call(canvas.Window.del, [], me);
  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: nil, convert:nil},
{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: nil, convert:nil},
{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: nil, convert:nil},
{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: nil, convert:nil},
{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: nil, convert:nil},
{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>


Navigation menu