Mendelsohn, Michael <[EMAIL PROTECTED]> wrote:
> Now, a MUI question:
>
> In a callback handler, I have a drop down menu that if certain items are
> selected, they should enable a button in the MUI. Is this possible? From
> within the callback, can you alter the initialized MUI?
Hi Michael,
Here's a "simple" MUI script that does just that. You need to use the
itemUpdate() method.
Cheers,
James
----------------------------------------------------------------------------
global gMui -- [#selection: <user's choice>,
-- #instance: xtra("mui").new(),
-- #menu: <data list for menu without prompt>,
-- #button: <data list for enabled button>]
-- PUBLIC METHODS --
on MuiDialog() -------------------------------------------------------
-- ACTION: Builds a dialogue with a popup menu, a Cancel button and
-- an OK button. An item in the popup menu other than the
-- default must be selected before the OK button will be
-- enabled.
-- OUTPUT: The string item selected by the user, or VOID if the user
-- cancelled the dialog.
--------------------------------------------------------------------
gMui = [#selection: VOID] -- default result is VOID
tInstance = xtra("mui").new()
gMui[#instance] = tInstance
muiPropList = tInstance.GetWindowPropList() -- 200 x 210
muiPropList[#mode] = #pixel
muiPropList[#height] = 70
muiPropList[#callback] = #MuiCallBack
-- Create template for window items
muiItemList = []
defaultItem = tInstance.GetItemPropList()
-- 1. Window begin
muiItem = duplicate(defaultItem)
muiItem[#type] = #windowBegin
muiItemList.append(muiItem)
-- 2. popUpList
muiItem = duplicate(defaultItem)
muiItem[#type] = #popUpList
muiItem[#attributes] = [#valueList: ["Select...","Item 1","Item 2"]]
muiItem[#value] = "Select..."
muiItem[#popUpStyle] = #normal
muiItem[#locH] = 10
muiItem[#locV] = 10
muiItem[#width] = 180
muiItem[#height] = 22
muiItemList.append(muiItem)
-- Keep a copy of this without the "Select..." item
tMenu = muiItem.duplicate()
tMenu.attributes.valueList = ["Item 1", "Item 2"]
gMui[#menu] = tMenu
-- 3. cancel PushButton
muiItem = duplicate(defaultItem)
muiItem[#type] = #cancelPushButton
muiItem[#title] = "Cancel"
muiItem[#locH] = 10
muiItem[#locV] = 40
muiItem[#width] = 85
muiItem[#height] = 20
muiItemList.append(muiItem)
-- 4. default PushButton
muiItem = duplicate(defaultItem)
muiItem[#type] = #defaultPushButton
muiItem[#title] = "OK"
muiItem[#locH] = 105
muiItem[#locV] = 40
muiItem[#width] = 85
muiItem[#height] = 20
-- Keep a copy of this with the button enabled...
gMui[#button] = muiItem.duplicate()
-- ... then disable the button
muiItem[#enabled] = FALSE
muiItemList.append(muiItem)
-- 5. window end
muiItem = duplicate(defaultItem)
muiItem[#type] = #windowEnd
muiItemList.append(muiItem)
-- The dialog is ready to run
tInstance.initialize([\
#windowPropList: muiPropList, \
#windowItemList: muiItemList \
])
tInstance.run()
-- Copy global to a local variable so the globals can be destroyed
tData = gMui
gMui = VOID
return tData
end MuiRunDialog
on MuiCallBack(anEvent, anItemNumber, anItemPropList) ----------------
-- Called by the Mui Xtra instance whenever a change is made to the
-- dialog.
--------------------------------------------------------------------
case anEvent of
#itemChanged:
-- The user has made a selection from the popup menu
tValue = anItemPropList.value
if tValue <> "Select..." then
-- Remove the default "Select..." choice
tMenu = gMui.menu
tMenu.value = tValue
gMui.instance.itemUpdate(2, tMenu)
-- Enable the default button
gMui.instance.itemUpdate(4, gMui.button)
-- Remember this selection
gMui.selection = tValue
end if
#itemClicked:
-- The user clicked on one of the buttons
gMui.instance.stop(0)
-- Adopt the chosen value if the OK button was clicke
case (anItemPropList[#type]) of
#defaultPushButton: gMui = gMui.selection
#cancelPushButton: gMui = VOID
end case
end case
end MuiCallBack
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL
PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping
with programming Lingo. Thanks!]