Lock screen challenge
Geoff Canyon
gcanyon at gmail.com
Tue Nov 22 16:29:30 EST 2022
One small point on this: it doesn't matter since we're dealing with HC
files here, but in LC there can be backgrounds that don't appear on any
card. So it would be necessary to add:
repeat with j = 1 to the number of backgrounds in stack i
repeat with k= 1 to the number of controls of background j of stack i
Note that this *doesn't* guarantee a single loop through all the controls.
The code would need to handle controls in groups that appear on multiple
cards. In Navigator I needed something like this. I created this, some of
which I wrote years ago, and no warranty is expressed or implied:
function allIDsOfStack stackID
local tReturnIDList
put empty into tReturnIDList
repeat for each line bgID in backgroundIDsOf(stackID)
put allControlIDsOf(bgID) after tReturnIDList
end repeat
repeat for each line cdID in cardIDsOf(stackID)
put nonGroupChildControlIDsOf(cdID) after tReturnIDList
end repeat
return (the long id of stackID) & cr & tReturnIDList
end allIDsOfStack
function allControlIDsOf pContainerID
local cIDend, cIDendString, controlIDList, controlList
if not exists(pContainerID) then return empty
put the long id of pContainerID into pContainerID
--breakpoint
switch word 1 of the name of pContainerID
case "stack"
return allIDsOfMainstack(pContainerID)
case "card"
put the controlIDs of pContainerID into controlList
if controlList is empty then return pContainerID & cr
repeat for each line cID in controlList
put (the long id of control id cID of pContainerID) & cr after
controlIDList
end repeat
return pContainerID & cr & controlIDList
case "group"
if word -6 of pContainerID is "card" then put -7 into cIDend else
put -10 into cIDend
put (word cIDend + 5 to -1 of pContainerID) & cr into cIDendString
put the controlIDs of pContainerID into controlList
if controlList is empty then return pContainerID & cr
repeat for each line cID in controlList
put "control" && (word 2 to cIDend of the long id of control id
cID of pContainerID) && cIDendString after controlIDList
end repeat
return pContainerID & cr & controlIDList
default
--return "control" && word 2 to -1 of pContainerID
return pContainerID
end switch
end allControlIDsOf
function allUniqueIDsOf pControlList,includeBehaviors
local tReturn, tWorking, X
-- returns all the controls within
put format("group,1\ncard,2\nstack,3") into X
split X using cr and comma
put canonicalIDsOf(pControlList) into pControlList
sort lines of pControlList descending by X[word 1 of each]
--answer pControlList
repeat for each line cID in pControlList
--put the long id of cID into cID
if tReturn[cID] is not empty then next repeat
--put true into tReturn[cID]
if includeBehaviors then
put canonicalIDsOf(allControlIDsOf(cID),false) into tWorking
put addBehaviorChains(tWorking) into tBehaviors
if tBehaviors is not empty then put cr & tBehaviors after tWorking
split tWorking by cr as set
else
put canonicalIDsOf(allControlIDsOf(cID),true) into tWorking
end if
--answer tWorking
--split tWorking by cr as set
union tReturn with tWorking
end repeat
--answer the number of lines of the keys of tReturn
return the keys of tReturn
end allUniqueIDsOf
function nonGroupChildControlIDsOf pContainerID
local controlIDList, tReturnIDList
put empty into tReturnIDList
put the long id of pContainerID into pContainerID
put the childControlIDs of pContainerID into controlIDList
if controlIDList is empty then return pContainerID & cr
put "control id " before controlIDList
replace cr with " of" && pContainerID & cr & "control id " in
controlIDList
repeat for each line controlID in (controlIDList && "of" && pContainerID)
if word 1 of the name of controlID is not "group" then put controlID
& cr after tReturnIDList
end repeat
return pContainerID & cr & tReturnIDList
end nonGroupChildControlIDsOf
function canonicalIDsOf cIDList, returnArray
local cID, cIDend, R
repeat for each line cIDx in cIDList
put the long id of cIDx into cID
if word 5 of cID is "group" then
if word -6 of cID is "card" then put -7 into cIDend else put -10
into cIDend
put 1 into R[word 1 to cIDend of cID && word cIDend + 5 to -1 of
cID]
else
put 1 into R[cID]
end if
end repeat
if returnArray is true then return R else return (the keys of R) & cr
end canonicalIDsOf
function backgroundIDsOf stackID
local backgroundIDList, bgID
put empty into backgroundIDList
repeat with i = 1 to 999999999
if not (there is a background i of stackID) then return
backgroundIDList
put (the long id of background i of stackID) into bgID
if word 5 of bgID is not "group" then put bgID & cr after
backgroundIDList
end repeat
end backgroundIDsOf
function backgroundsOf stackID,bFilter,returnType,typeModifier
if returnType = "short name" and bFilter = "backgroundNames" then return
the backgroundNames of stackID
put empty into R
repeat with i = 1 to 999999999
if not (there is a background i of stackID) then return char 1 to -2
of R
if not (bFilter = "all" \
or bFilter = "backgroundNames" and the backgroundBehavior of
background i of stackID \
or bFilter = "base" and word 5 of the long id of background i
of stackID is not "group") then next repeat
switch
case word 1 of returnType = "name"
switch typeModifier
case empty; put "background" && Q(the short name of
background i of stackID) after R; break
case "short"; put (the short name of background i of
stackID) after R; break
case "long"; put "background" && (word 2 to -1 of the long
name of background i of stackID) after R; break
end switch
if returnType = "name" then break
put tab after R
case word 1 of returnType = "id"
switch typeModifier
case empty; put (the id of background i of stackID) after R;
break
case "short"; put (the short id of background i of stackID)
after R; break
case "long"; put (the long id of background i of stackID)
after R; break
end switch
end switch
put cr after R
end repeat
end backgroundsOf
function cardsOf stackID
repeat with i = 1 to 999999
if not (there is a card i of stackID) then return char 1 to -2 of R
put (the short name of card i of stackID) & tab & (the short id of
card i of stackID) & cr after R
end repeat
end cardsOf
function backgroundIDsOf stackID
local backgroundIDList, bgID
try
repeat with i = 1 to 999999999
put (the long id of background i of stackID) into bgID
if word 5 of bgID is not "group" then put bgID & cr after
backgroundIDList
end repeat
catch someErr
end try
return backgroundIDList
end backgroundIDsOf
function cardIDsOf stackID
local cardIDList
put "card id" && the cardIDs of stackID into cardIDList
replace cr with " of" && the name of stackID & cr & "card id " in
cardIDList
return cardIDList && "of" && the name of stackID & cr
end cardIDsOf
On Mon, Nov 21, 2022 at 1:44 PM Paul Dupuis via use-livecode <
use-livecode at lists.runrev.com> wrote:
> I was also going to suggest just brute forcing it. Something like: (code
> not complete or syntax checked)
>
> repeat with i=1 to the number of stacks
> repeat with j = 1 to the number of cards in stack i
> repeat with k= 1 to the number of controls of card j of stack i
> put the script of control k of card j of stack i into tScript
> -- look through the lines of tScript for "lock screen", note the
> line number A, then search from there onward for "unlock screen" and
> note the line number B
> -- if line B begins with (after trimming spaces) "unlock screen
> with" then
> -- replace line B with "unlock screen with visual effect"
> -- and replace line A with "lock screen for visual effect"
> end repeat
> end repeat
> end repeat
>
>
> On 11/21/2022 4:30 PM, Craig Newman via use-livecode wrote:
> > Jacque.
> >
> > Why aren’t you on the forum?
> >
> > Cant you just loop through each line in your handlers, and find the ones
> that contain “lock screen”, both with and without the visual effect thing.
> Search downstream until you find the “unlock” line, That gives you the
> start and finish lines for each handler. Then you can just replace the
> start and finish lines with the new ones.
> >
> > Am I missing this?
> >
> > Craig
> >
> >> On Nov 21, 2022, at 4:24 PM, J. Landman Gay via use-livecode <
> use-livecode at lists.runrev.com> wrote:
> >>
> >> I'm updating a very old set of stacks that use old HC syntax for "lock
> screen". A search with LC's Find utility says there are 723 instances that
> may need to be changed. Right now they look like this:
> >>
> >> lock screen
> >> -- do any number of things
> >> unlock screen with <effect>
> >>
> >> These all need to be changed to:
> >>
> >> lock screen for visual effect
> >> -- do any number of things
> >> unlock screen with visual effect <effect>
> >>
> >> The challenge is that not all "lock screen" commands use a visual
> effect, some are simple lock/unlock pairs. I need to automate this. The
> visual effects are not all the same. Some handlers have multiple instances
> of locking the screen with or without a visual effect.
> >>
> >> I'd use a regex if I could, but back references aren't supported (or
> are they now?) I really don't want to do this manually.
> >>
> >> --
> >> Jacqueline Landman Gay | jacque at hyperactivesw.com
> >> HyperActive Software | http://www.hyperactivesw.com
> >>
> >> _______________________________________________
> >> use-livecode mailing list
> >> use-livecode at lists.runrev.com
> >> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> >
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
More information about the use-livecode
mailing list