From 5481c73b202a122e8dd34c45fa4af03f614330eb Mon Sep 17 00:00:00 2001 From: mfranz Date: Fri, 9 Nov 2007 13:00:05 +0000 Subject: [PATCH] - fix bug that made gui.popupTip() ignore the optional delay argument - use more "var" keywords and named args - popupTip(): add optional third hash argument that is merged with the dialog properies hash. This can be used to select different font or dialog colors, etc. --- Nasal/gui.nas | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Nasal/gui.nas b/Nasal/gui.nas index b89f64a9a..a092856fe 100644 --- a/Nasal/gui.nas +++ b/Nasal/gui.nas @@ -1,38 +1,40 @@ ## # Pop up a "tip" dialog for a moment, then remove it. The delay in # seconds can be specified as the second argument. The default is 1 -# second. Note that the tip dialog is a shared resource. If -# someone else comes along and wants to pop a tip up before your delay -# is finished, you lose. :) +# second. The third argument can be a hash with override values. +# Note that the tip dialog is a shared resource. If someone else +# comes along and wants to pop a tip up before your delay is finished, +# you lose. :) # -popupTip = func { - delay = if(size(arg) > 1) {arg[1]} else {DELAY}; - tmpl = { name : "PopTip", modal : 0, layout : "hbox", - y: screenHProp.getValue() - 140, - text : { label : arg[0], padding : 6 } }; +var popupTip = func(label, delay = nil, override = nil) { + var tmpl = props.Node.new({ + name : "PopTip", modal : 0, layout : "hbox", + y: screenHProp.getValue() - 140, + text : { label : label, padding : 6 } + }); + if (override != nil) tmpl.setValues(override); popdown(); - fgcommand("dialog-new", props.Node.new(tmpl)); + fgcommand("dialog-new", tmpl); fgcommand("dialog-show", tipArg); - currTimer = currTimer + 1; - thisTimer = currTimer; + currTimer += 1; + var thisTimer = currTimer; # Final argument is a flag to use "real" time, not simulated time - settimer(func { if(currTimer == thisTimer) { popdown() } }, DELAY, 1); + settimer(func { if(currTimer == thisTimer) { popdown() } }, delay or DELAY, 1); } -showDialog = func { - fgcommand("dialog-show", - props.Node.new({ "dialog-name" : arg[0]})); +var showDialog = func(name) { + fgcommand("dialog-show", props.Node.new({ "dialog-name" : name })); } ## # Enable/disable named menu entry # -menuEnable = func(searchname, state) { - foreach (menu; props.globals.getNode("/sim/menubar/default").getChildren("menu")) { - foreach (name; menu.getChildren("name")) { +var menuEnable = func(searchname, state) { + foreach (var menu; props.globals.getNode("/sim/menubar/default").getChildren("menu")) { + foreach (var name; menu.getChildren("name")) { if (name.getValue() == searchname) { menu.getNode("enabled").setBoolValue(state); }