Some problems with background behaviour

Peter Brigham MD pmbrig at gmail.com
Thu Apr 8 15:49:41 EDT 2010


Be aware that using the menuhistory in the handlers I originally  
suggested depends on the contents of the button remaining unchanging,  
since the menuhistory returns the number of the line selected. If you  
are working with a pulldown menu that will be changing its contents  
then you'll have to store and retrieve not the menuhistory for each  
card but the content of the selection:

on menuPick pItemName
    put the short id of of this card into cID
    put the menuhistory of me into lineNbr
    set the bValue[cID] of me to pItemName -- text of choice
    set the label of me to pItemName
end menuPick

on preopencard
    put the short id of this card into cID
    put the number of this card into fld "pg"
    put the bValue[cID] of btn "p" into bVal
    -- bVal is the text of the user selection for this card
    if bVal = empty then
       set the label of btn "p" to "choose..."
       -- or whatever, for cards where the user has
       -- not chosen a value yet
    else
       put the text of btn "p" into bContents
       set the wholematches to true
       put lineoffset(bVal,bContents) into lineNbr
       if lineNbr = 0 then
          -- not found, menu was changed
          set the label of btn "p" to "choose..."
          -- or whatever, for cards where the user has
          -- not chosen a value yet
       else
          lock messages
          -- do this if you want to avoid triggering a menupick
          -- if picking an item results in some further action
          set the menuhistory of btn "p" to lineNbr
          set the label of btn "p" to bVal
          unlock messages
       end if
       set the menuChoice of btn "p" to bVal
    end if
end preopencard

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig

On Apr 8, 2010, at 11:38 AM, Peter Brigham MD wrote:

> On Apr 8, 2010, at 4:12 AM, planix wrote:
>
>> ... Unfortunately, I think the problem I have is actually that one  
>> of my
>> "fields" is a dropdown list- so a button. It seems that these do  
>> propogate
>> across all backgrounds. So, I will work on remembering the state of  
>> the
>> dropdown buttons for each card, setting them back to a default  
>> condition
>> when the card is closed, and then re-instating the state from a card
>> specific custom property in a pre-open statement. This will be a  
>> lot easier
>> using the modular approach to groups as backgrounds.
>>
>> Though if someone has some example code of this sort of management  
>> of button
>> status I would be grateful for a link.
>
> Try this. Put the preopencard handler in the stack script, and the  
> menupick handler in your pulldown button.
>
> on menuPick pItemName
>   put the short id of of this card into cID
>   put the menuhistory of me into lineNbr
>   set the bValue[cID] of me to lineNbr
>   set the label of me to pItemName
> end menuPick
>
> on preopencard
>   put the short id of this card into cID
>   put the bValue[cID] of btn "pullDown" into bVal
>   if bVal = empty then
>      set the label of btn "pullDown" to "choose..."
>      -- or whatever, for cards where the user has
>      -- not chosen a value yet
>   else
>      set the menuhistory of btn "pullDown" to bVal
>   end if
> end preopencard
>
> I wish that it were an option in Rev to set the sharedtext (or some  
> equivalent) of a pulldown/popup menu to false, so this could be done  
> authmatically. Until then, the above works fine.
>
> -- Peter
>
> Peter M. Brigham
> pmbrig at gmail.com
> http://home.comcast.net/~pmbrig
>
>
>




More information about the use-livecode mailing list