How can I change a button's number?

Questions regarding the Developer Edition's SuperEdit? This is the place!

How can I change a button's number?

Postby drpitcairn » Sat Dec 25, 2010 6:57 pm

Is there a way to change the number of a button (not the ID) so the ranking/sorting of numbers can be controlled? I have tried to do it by manually changing the number but just locks up SC. I am thinking it is done in SuperEdit but when in there can't seem to figure it out.
Any suggestions welcome.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: How can I change a button's number?

Postby peter_jenkins » Sun Dec 26, 2010 12:57 am

The number assigned to objects is determined by their arrangement from back to front.
E.g., card button at the back is number 1, next towards the front is number 2, etc.
So if you control the back-to-front position then you control the numbering.

In SuperEdit, select a button and then in the "Arrange" menu, select "Shuffle Back" to decrease the button's number, or "Shuffle Forward" to increase its number.

Peter Jenkins
peter_jenkins
 
Posts: 3
Joined: Mon Dec 28, 2009 7:18 pm

Re: How can I change a button's number?

Postby Didier Gross » Sun Dec 26, 2010 12:58 am

Richard,

The SLG contains invaluable informations.
SLG-Button, fields and graphics-Common properties wrote:One of the common properties of all the objects that reside on cards is their number. The number
reflects its bottom to top order among other objects of its type. Card field 1 is the card field at the
“bottom” layer of the card, and card field 1 may be above or below card button 1.


To control objects numbers, you will have to play with their stack order.

What are you trying to achieve? Controlling buttons numbers is probably not a goal, but a solution. Maybe there is another one.
Didier Gross
 
Posts: 47
Joined: Thu Sep 16, 2010 11:32 pm
Location: City of god Lug

Re: How can I change a button's number?

Postby JoshRu » Sun Dec 26, 2010 4:32 am

You can also change the order of the object in the RTE. Choose the pointer tool from the Tool menu, select the object, then use the 'Send To Back', 'Bring To Front', 'Shuffle Back', 'Shuffle Forward' menuitems in the Objects menu to see how your object changes its viewability in your window. If you have other objects underneath that object, you may see how their prominence changes accordingly. -- Josh
User avatar
JoshRu
 
Posts: 147
Joined: Sat Jul 19, 2008 7:04 pm

Re: How can I change a button's number?

Postby drpitcairn » Wed Dec 29, 2010 4:51 pm

Thanks for that clarification. Just for information, I have a vertical row of about 20 buttons that I want to toggle visibility on. Easiest to use a repeat loop for the numbers if they are all in sequence.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: How can I change a button's number?

Postby Dan_Kelleher » Thu Dec 30, 2010 10:53 am

Because of the relative instability of 'number' as an object descriptor (reference) due to the (likely?) possibility of changes in objects (deleted, added and subtracted) in the future, I'd suggest using the 'name' of the object (example, "1","2", etc or more informatively, "SomeThing Button 1", SomeThing Button 2",etc).
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: How can I change a button's number?

Postby Dan_Kelleher » Thu Dec 30, 2010 11:07 am

If you use the "more informative naming system", iteration using either a "looping" syntax or the much more powerful (pointer-moving-progressively-ONCE-across-the-items-of-a-set) "for-next" syntax, will involve a bit more learning, but the effort will be rewarding.
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: How can I change a button's number?

Postby Lisa » Thu Dec 30, 2010 12:03 pm

One more tip on re-ordering objects: The RTE has an Object Browser that lists objects, on either the card or background layer, in number order. When you select an object or objects, they'll also be highlighted in the list (and vice versa). When you choose "Send to Back", "Shuffle Forward", etc. from the Objects menu, you'll see the list re-order itself to reflect the results of the action. Also note that the re-ordering commands in the Objects menu have equivalents in SuperTalk. So if you have a selected object whose position in the stack order needs to be, say, shuffled back some large or unknown number of times, don't risk RSI by repeatedly using the menu -- type "shuffleBack" in the message box and keep hitting return, while watching the object's entry in the Object Browser list move until it gets to the desired position.

But I would very much agree with Dan that rationally naming your objects and identifying them by name in permanent scripts is best. If your buttons were named "Something Button 1" to "Something Button 20", you could script mass changes like this:

Code: Select all
repeat with x = 1 to 20
  set the someProperty of cd btn ("Something Button" && x) of this cd to someValue
end repeat
iMac 24" 3.06 GHz Intel Core 2 Duo, 4 GB RAM, Mac OS X 10.6.8, SC 4.7.3
User avatar
Lisa
 
Posts: 303
Joined: Sun Jul 06, 2008 12:33 pm
Location: San Diego, CA

Re: How can I change a button's number?

Postby Didier Gross » Thu Dec 30, 2010 2:06 pm

Richard,

I agree with Lisa and Dan.

If you cannot name your buttons as Lisa suggested, because you have to display their specific name, you can add them a user property (named uButtonNumber for example), and set it to the button #.

In your loop, scan the buttons for 1 to the number of buttons of the card, check if there is a uButtonNumber property, then get it and do your stuff.

HTH
Didier Gross
 
Posts: 47
Joined: Thu Sep 16, 2010 11:32 pm
Location: City of god Lug

Re: How can I change a button's number?

Postby drpitcairn » Sun Jan 02, 2011 2:37 pm

If you use the "more informative naming system", iteration using either a "looping" syntax or the much more powerful (pointer-moving-progressively-ONCE-across-the-items-of-a-set) "for-next" syntax, will involve a bit more learning, but the effort will be rewarding.

Sorry, this is beyond me. What does "pointer-moving-progressively-once, etc" mean? Are you referring to something outside of the usual language?
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: How can I change a button's number?

Postby drpitcairn » Sun Jan 02, 2011 2:42 pm

buttons.png
List of buttons showing names
buttons.png (56.52 KiB) Viewed 8701 times
If you cannot name your buttons as Lisa suggested, because you have to display their specific name, you can add them a user property (named uButtonNumber for example), and set it to the button #.

In your loop, scan the buttons for 1 to the number of buttons of the card, check if there is a uButtonNumber property, then get it and do your stuff.

I do indeed need to have the button names showing. I will show a picture of what I have so you can see what I mean.
Do I understand correctly that I would create a userprop for each button? The script scans the button names, sees if there is a corresponding userprop of the same name? If so, does something with it?
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: How can I change a button's number?

Postby Dan_Kelleher » Mon Jan 03, 2011 10:48 am

Hi Richard,
First off, when I wrote "For Next" syntax, that was sloppy; I should have said "Repeat For Each" syntax. See the entry for "each" in the Script Lanfuage Guide (SLG) Help Project.

One easy way to avoid using a button's number and to use, instead, the names of your buttons just as you originally made them and also you can use the "Repeat For Each" syntax.

I've uploaded a demo project in the "File Areas" section of the Forum (go to "Board Index").
The project is in the "Sample & Demo Projects" section where in order to upload it I clicked on the "New Topic" button and the new topic is named, "Repeat for Each Syntax".

The "Repeat For Each" syntax utilizes TEXT and is of the following form:
repeat for each «chunkType» «chunkVar» in «container»
do something here
end repeat

Here I've used
the «chunkType» is "word" (space-Delimited values)
the «chunkVar» is a local variable, "tWord"
the «container» is a global variable, gMyText, containing your button names as space-delimited values

Project Script:
on openProject
global gMyText
put "Mind Vertigo Head Eye Ear Nose Face Mouth Teeth Gums" into gMyText
end openProject

To trigger the script, I made a test button, "Find an element of a set using 'Repeat For Each' syntax"
To input a button name to find, I created a field, "The Word To Find"
Button Script:
on mouseUp
trace
global gMyText
put cd field "The Word To Find" into tWordToFind-
repeat for each word tWord in gMyText
if tWord is tWordToFind then
if the visible of cd btn tWord then
set the visible of cd btn tWord to false
else set the visible of cd btn tWord to true
end if
end repeat
end mouseUp

The 'Repeat For Each' syntax is not essential here but learning to use it may be of use in the future if you ever want to, for example, find multiple occurrences of a word or lines in a very large amount text like an entire medical dictionary (or two!) and then do multiple things like highlight each word by colorizing the text characters of found words or lines and extracting the words or lines to display in a results field.
You can nest 'Repeat For Each' constructs; for example "march through" the text until you find the first line that contains your search term then "stop" there and march through the words or characters
and do stuff and then move on to the next occurrence.
For large texts this is the only efficient syntax to use.
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: How can I change a button's number?

Postby Dan_Kelleher » Mon Jan 03, 2011 11:23 am

not so long agq (as Keith Martin used to say),
In the message above I wrote:
"...and then move on to the next occurrence..."

That is, without starting at the top (of the very large amount of text) again.

This is what I was referring to in an earlier message when I wrote,
..."pointer-moving-progressively-ONCE-across-the-items-of-a-set..."
-Dan
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: Repeat For Each Syntax

Postby codegreen » Mon Jan 03, 2011 11:35 am

You might also want to consider these alternatives:

Code: Select all
on mouseUp
  global gMyText
  get cd field "The Word To Find"
  repeat for each word tWord of gMyText
    if tWord ≠ it then next repeat
    set the vis of cd btn it to not the vis of cd btn it
    exit repeat
  end repeat
end mouseUp

on mouseUp
  global gMyText
  get cd field "The Word To Find"
  if chunkOffset(it, gMyText, 0, " ", false, false, true) ≠ 0
  then set the vis of cd btn it to not the vis of cd btn it
end mouseUp

HTH,
-Mark
codegreen
 
Posts: 1518
Joined: Mon Jul 14, 2008 11:03 pm

Re: How can I change a button's number?

Postby Dan_Kelleher » Tue Jan 04, 2011 7:20 am

Thanks Mark.
So one of the things Mark's reply suggests is that in place of the following five lines

if tWord is tWordToFind then
if the visible of cd btn tWord then
set the visible of cd btn tWord to false
else set the visible of cd btn tWord to true
end if

I could substitute these two lines

if tWord ≠ tWordToFind then next repeat
set the vis of cd btn tWord to not the vis of cd btn tWord
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: How can I change a button's number?

Postby Lisa » Tue Jan 04, 2011 1:31 pm

I don't know about Richard, but I'm confused by some of the above, eg. the purpose of the field and tWordToFind?

If you can't use the "something button x" trick, then make a list of your button names and repeat through that list to toggle the visibility of those buttons. (If you need to change the properties of these buttons in more than one place, then put the list in a global variable in the openProject script, rather than listing them out each time.)

Code: Select all
put "Mind,Vertigo,Head,Eye,Ear,Nose,Face,Mouth,Teeth,Gums" into tBtnList
repeat for each item tBtn of tBtnList
  set the vis of cd btn tBtn to NOT (the vis of cd btn tBtn)
end repeat
iMac 24" 3.06 GHz Intel Core 2 Duo, 4 GB RAM, Mac OS X 10.6.8, SC 4.7.3
User avatar
Lisa
 
Posts: 303
Joined: Sun Jul 06, 2008 12:33 pm
Location: San Diego, CA

Re: How can I change a button's number?

Postby Dan_Kelleher » Tue Jan 04, 2011 8:02 pm

Thanks Lisa. That's probably just what's needed.
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: How can I change a button's number?

Postby johncollett » Wed Jan 05, 2011 10:54 am

If the original aim was to avoid the column of buttons becoming visible in an irregular order (displeasing to the eye) why not lock the screen, use a simple loop to set the visibility of all of the buttons, and then unlock the screen? In whatever vertical order their numbers happen to be, you will see none of them, and then all of them. JC
User avatar
johncollett
 
Posts: 100
Joined: Sat Aug 02, 2008 2:53 pm

Re: How can I change a button's number?

Postby LorenzT » Wed Jan 05, 2011 12:05 pm

In a similar situation I used the ID of btns. If you create your btns one after another they get their IDs in sequence. You can cut and paste your btns to get fresh IDs if they are not in sequence. Then you can use your repeat loop with IDs, you only need to know the ID of the first btn. E.g. show cd btn ID (myFirstID+i).
LorenzT
 
Posts: 176
Joined: Thu Dec 02, 2010 2:32 am
Location: Switzerland


Return to SuperEditing

Who is online

Users browsing this forum: No registered users and 1 guest

cron