Page 1 of 2

Shared checkboxes - "disabled" always shared?

Posted: Thu Oct 18, 2012 3:25 pm
by japino
Hi,

I have a checkbox which appears on all cards of my stack. Depending on a certain value the checkbox is disabled (greyed out) on the card using this code.

Code: Select all

set the disabled of button "blabla" of current card to true


The checkbox is part of a group. It seems that if I disable the checkbox on 1 card it gets disabled on all cards. This behaviour seems to be different from the "hilite" property which can be different (if you uncheck "Shared hilite" for the checkbox in the inspector window). Is this true or am I overlooking something?

Thanks!

Re: Shared checkboxes - "disabled" always shared?

Posted: Thu Oct 18, 2012 3:34 pm
by Klaus
Hi japino,

yes this is true, since it is the SAME checkbox you see on different cards in the same group
and Livecode can only manage different HILITES for a "shared" checkbox/radiobutton
but not en- or disabled states.

Set a custom property for the card(s) where you want the button en/disabled!

Like this in the script that en- or disables the button:
...
set the checkbox_enabled of THIS cd to false
...

Then in the script of the card(s) or in a generic "opencard" handler in the stackscript:

Code: Select all

on opencard
  set the enabled of btn "your checkbox here" of grp "wahtever" to (the checkbox_enabled of htis cd = TRUE)
  ## other opencard stuff here...
end opencard

Best

Klaus

Re: Shared checkboxes - "disabled" always shared?

Posted: Thu Oct 18, 2012 4:59 pm
by japino
Thanks Klaus, I did what you suggested - not really understanding what's going on, I need to read a bit more about custom properties I guess - and it works... partly.
For testing, I have 2 cards in the stack. Card 1 has the checkbox enabled. When I go the next card, card 2 has the checkbox disabled. This is very nice, exactly what I want to see - it shows that the disabled/enabled state of the checkbox can vary between cards. But when I go back to card 1, the checkbox is now suddenly disabled again...

Re: Shared checkboxes - "disabled" always shared?

Posted: Thu Oct 18, 2012 5:31 pm
by Klaus
Hi japino,

well, see custom properties as some kind of variable, with some differences:
1. they are attached to a specific object, so you can have more than one CPs with the same name,
as long as the are attached to different objects.

2. They will be saved with the stack! Not so imported in this case.

3. They can bve accessed from everywhere (put the cWhatever of btn "the cool button" of cd 2 of stack XYZ into tWhatever),
similar to GLOBAL variables but without the need of DECLARING them!

What is in the card script of cd 1?

If you have my "opencard" handler in the script of the STACK, and your cards do already have a "opencard" handler in their (card) script,
you will need to add a "pass opencard" at the end of these handlers (in the card script), so the handler in the STACK script will also get executed.

OK, this is a bit of advanced stuff, but I'm sure you'll figure this out 8)
But once you "get" custom properties, you will ask yourself how you could live without them :D


Best

Klaus

Re: Shared checkboxes - "disabled" always shared?

Posted: Thu Oct 18, 2012 7:03 pm
by japino
Hi Klaus,

My card scripts are empty at the moment. I have this in my stack script:

Code: Select all

on closeStack
   save this stack
   pass closeStack
end closeStack

on opencard
    set the enabled of btn "TR_Translate" of grp id 1111 to (the checkbox_enabled of this cd = TRUE)
    pass opencard
end opencard
and I now have this in my Test checkbox which toggles the enabled state of the "TR_Translate" button:

Code: Select all

on mouseUp
   if the hilite of me then set the checkbox_enabled of THIS cd to true else set the checkbox_enabled of THIS cd to false
   send opencard
end mouseUp
This seems to work! But does it all make sense? I put "send opencard" in the mouseUp handler otherwise nothing would happen.
And I have another checkbox which controls the enabled state of a few other buttons. Do I need another custom property for that? It seems so... all this makes me dizzy... :x

But thanks so much for your help!

japino

Re: Shared checkboxes - "disabled" always shared?

Posted: Thu Oct 18, 2012 7:16 pm
by Klaus
Hi japino,
japino wrote:Hi Klaus,

My card scripts are empty at the moment. I have this in my stack script:

Code: Select all

on closeStack
   save this stack
   pass closeStack
end closeStack

on opencard
    set the enabled of btn "TR_Translate" of grp id 1111 to (the checkbox_enabled of this cd = TRUE)
    pass opencard
end opencard
OK.
japino wrote:and I now have this in my Test checkbox which toggles the enabled state of the "TR_Translate" button:

Code: Select all

on mouseUp
   if the hilite of me then set the checkbox_enabled of THIS cd to true else set the checkbox_enabled of THIS cd to false
   send opencard
end mouseUp
Change this to:

Code: Select all

on mouseup
  set the checkbox_enabled of THIS cd to the hilite of me
  opencard
end mosueup
This seems to work! But does it all make sense?
??? Don't ask me, I just gave you some hints :D
? I put "send opencard" in the mouseUp handler otherwise nothing would happen.
See above for correct syntax
And I have another checkbox which controls the enabled state of a few other buttons.
Do I need another custom property for that? It seems so... all this makes me dizzy...
I did not promise you a rosegarden! 8)
This IS in fact advanced stuff!


Best

Klaus

Re: Shared checkboxes - "disabled" always shared?

Posted: Thu Oct 18, 2012 7:31 pm
by japino
Thank you Klaus! Has anyone ever told you that you are brilliant?!? :D Thanks again!

Re: Shared checkboxes - "disabled" always shared?

Posted: Thu Oct 18, 2012 7:34 pm
by Klaus
Has anyone ever told you that you are brilliant?!?
Yes, I hear that all the time! :D

Re: Shared checkboxes - "disabled" always shared?

Posted: Fri Oct 19, 2012 8:35 am
by japino
I now have everything working - checkboxes are getting enabled or disabled depending on the state of other checkboxes, which is exactly what I want.

But now there is one vital final thing that does not work. I couldn't figure it out last night, in the middle of the night I woke up with a Eureka thought, but that thought didn't work either. :?

For testing, I now how 2 cds in my stack. On card 1 the checkbox "TR_Translate" is enabled. On card 2 the checkbox "TR_Translate" is disabled.

I have a button with this (simplified - the real script is a bit more intricate) script:

Code: Select all

on mouseUp
   put empty into field "ToDo"
   repeat with x = 1 to the number of cds of stack "MainApplication"
      repeat with y = 1 to the number of buttons of cd x of stack "MainApplication"
         put name of button y of cd x of stack "MainApplication" into myButtonName
            if  not the checkbox_enabled of btn myButtonName of cd x of stack "MainApplication" then put myButtonName & return after field "ToDo"
      end repeat
      put return after field "ToDo"
   end repeat   
end mouseUp
Now, the strange thing is that after running this script, my field "ToDo" has 2 lines with "button "TR_Translate"" - there should be only 1 because that button is only enabled on 1 card. May be I should sleep another night on this, but if you see something obvious that is wrong, please let me know! I'm 99% there!

Re: Shared checkboxes - "disabled" always shared?

Posted: Fri Oct 19, 2012 10:37 am
by Klaus
Hi japino,

the scripts looks ok, and scripts always tell the truth :D

But I see that you are querying a custom property and not the actual "enabled" or "disabled" state.
So maybe there is a discrepancy: custom prop <-> real state of button?


Best

Klaus

Re: Shared checkboxes - "disabled" always shared?

Posted: Fri Oct 19, 2012 11:07 am
by japino
Hi Klaus,

No, that's not it. That was my Eureka moment from last night, I was querying the actual state and I thought that querying the custom property would be the answer. It's bizarre. No matter whether I query the actual state or the custom property, I get the same results twice for, once for every card. I know that I'm moving from card to card because the script looks OK and I verified it by adding another element from each card to the "ToDo" field to confirm that information is taken from the correct card. Could it be that querying the enabled/disabled state of a button always gives the same result even though the state may vary between cards?

Cheers,
japino

Re: Shared checkboxes - "disabled" always shared?

Posted: Fri Oct 19, 2012 11:27 am
by Klaus
Hi japino,

after some coffee... :D
Since you set the en-/disabled state of a button "on opencard", querying its state this way will of course return the CURRENTLY SET state!
So you might need to set and use custom properties for this to check!



Best

Klaus

Re: Shared checkboxes - "disabled" always shared?

Posted: Fri Oct 19, 2012 12:09 pm
by japino
Hi Klaus,

I need hundreds more cups of coffees to make this work with custom properties I think... :oops:

But I really don't get it. I'm moving from card to card in the stack. I think that the opencard message isn't sent when moving from card to card using the script.
Why doesn't this work when I add this line to the first repeat loop in the code?

Code: Select all

send opencard to cd x stack "MainApplication"
I had hoped that that would change the currently set state, and that a new query would give different results.

This is getting complicated, may be I should go back and design something different that works for me and that I understand! This seemed such a nice approach, but I find it hard to implement! Arggh!

Anyway, thanks for all your help and ideas that you've given me!

Cheers,
japino

Re: Shared checkboxes - "disabled" always shared?

Posted: Fri Oct 19, 2012 12:31 pm
by Klaus
Hi japino,
japino wrote:This is getting complicated, may be I should go back and design something different that works for me and that I understand!
without knowing exactly what your goal is, I think this is a good idea!
Sometimes it is better to rethink the problem than to make it even more complicated.

Maybe you can even use one or more SEPARATE checkboxes (not part of a shared group) on each card, that doesn't take too much
diskspace or memory and will surely make things less complicated in your case!


Best

Klaus

Re: Shared checkboxes - "disabled" always shared?

Posted: Fri Oct 19, 2012 1:20 pm
by japino
Separate checkboxes sound like a good idea! I think I will let my New Card script create these checkboxes that will then only live on that card. That should make everything much easier (and understandable for me!) Thanks Klaus!!