Toggle Buttons question

Hello all!

I have created 3 toggle buttons, namely apple, pear and orange.
I have also input their respective names into the Pt_ARG_USER_DATA. For example under the toggle button apple, I have typed in ‘a’ as the user data. Then I grouped these 3 buttons into a single group and set the Pt_ARG_GROUP _FLAGS to Pt_GROUP _EXCLUSIVE.

But the problem now is that I cannot select the toggles’ individual user data anymore. My aim is to allow the user to first select only one of the 3 toggle buttons, then the user presses the start button and the respective program for each toggle button runs. I have also written a switch(mode) program in the callback of the start button.(where mode is either apple, orange or pear). For example, when the user selects apple and then press the start button, a sentence “apple chosen” will be printed out in a text box.

My question now is, is this the correct way of setting up toggle buttons?
Below is my code, which only displays the default statement no matter which toggle button is chosen.

int start(PtWidget_t *widget, Apinfo_t *apinfo, PtCallBackInfo_t *cbinfo)
{
char mode;
PtArg_t args[5];

switch(mode)
{
  case 'a': PtSetArg(&args[0], Pt_ARG_TEXT_STRING, "apple chosen",0)
               PtSetResources(ABW_base_text, 5, args);
  break;
  case 'p': PtSetArg(&args[0], Pt_ARG_TEXT_STRING, "pear chosen",0)
               PtSetResources(ABW_base_text, 5, args);
  break;
case 'o': PtSetArg(&args[0], Pt_ARG_TEXT_STRING, "orange chosen",0)
               PtSetResources(ABW_base_text, 5, args);
  break;

  default:PtSetArg(&args[0], Pt_ARG_TEXT_STRING, "Nil chosen",0)
               PtSetResources(ABW_base_text, 5, args);
  break;
 }

}

What is wrong? Can anyone help me?
Thanks in advance!

Hi,
Indeed this will (should) work fine.

Your Pt_ARG_USER_DATA will be strings if you enter them in PhAB tho, so you’d have to convert before using the switch.

Another way of doing it (if you are using phab) is to use the ABW_* manifests.

CommonToggleButtonCallback(PtWidget_t *w,…)
{
switch(w){
case ABW_apple:
break;
case ABW_pear:

}
}

I belive you mean you can’t select the widgets invidual data in phab? If so, that is correct, if it’s a in a group you can’t CLICK on them to select the PtToggleButtons, instead you must use the “Next Widget” “Previous Widget” IIRC it’s F10 hotkey (There is also the << >> arrows in the Resource Pane) and you can select them from the Module Tree.

Cheers, hope this helps
/Johan Björk

Hi phearbear!

I tried your method and it did not work. It gave me a error message saying that the error constant is too long.

Also, I did not attach a callback to my toggle group, instead, the callback is attached to another button called “start”. The code you see below is typed into the callback of the “start” button. Your reply mentioned about a commontogglegroup button, does it mean that I have attached the callback to the wrong button?

Yes, I am using phAB.

int start(PtWidget_t *widget, Apinfo_t *apinfo, PtCallBackInfo_t *cbinfo)
{
char mode;
PtArg_t args[5];

switch(mode)
{
case ‘ABW_apple’: PtSetArg(&args[0], Pt_ARG_TEXT_STRING, “apple chosen”,0)
PtSetResources(ABW_base_text, 5, args);
break;
case ‘ABW_pear’: PtSetArg(&args[0], Pt_ARG_TEXT_STRING, “pear chosen”,0)
PtSetResources(ABW_base_text, 5, args);
break;
case ‘ABW_orange’: PtSetArg(&args[0], Pt_ARG_TEXT_STRING, “orange chosen”,0)
PtSetResources(ABW_base_text, 5, args);
break;

default:PtSetArg(&args[0], Pt_ARG_TEXT_STRING, “Nil chosen”,0)
PtSetResources(ABW_base_text, 5, args);
break;
}
}

Hi,
You should change the Pt_ARG_USER_DATA of the “start” button in the 3 toggle buttons callbacks.
e.g. for the apple CB:

char mychar;

strcpy(mychar, “apple”);
PtSetResource(ABW_start, Pt_ARG_USER_DATA, &mychar, sizeof( mychar ));

in the start button callback:

int start(PtWidget_t *widget, Apinfo_t *apinfo, PtCallBackInfo_t *cbinfo)
{
char *mode;
PtArg_t args[5];

PtGetResource( widget, Pt_ARG_USER_DATA, &mode, 0);

switch(mode)
{
case ‘apple’: PtSetArg(&args[0], Pt_ARG_TEXT_STRING, “apple chosen”,0)
PtSetResources(ABW_base_text, 5, args);

Cheers,
Julius
julius.qnx.org.ru

Hi

Where did that code come from in the first post, odd.

I don’t agree with atjulius post at all, and I didn’t understand what you wanted to do in your first post. so here is my recommendation:

First off, skip the use of the Pt_ARG_USER_DATA, it’s totaly pointless in this case.

In your “Start” button callback:

Check if the Pt_ARG_SET is set in the Pt_ARG_FLAG resource for all of your togglebuttons.

Something like this

if(PtWidgetFlags(ABW_togglebuttonapple) & Pt_SET) {
PtSetResource(ABW_MyLabel,Pt_ARG_TEXT_STRING,“Apple!!”,0);
} else if(PtWidgetFlags(ABW_togglebuttonbanana) & Pt_SET) {
PtSetResource(…)
}…

Hello phearbear and Julius!

Julius, I tried your method and it was able to build and run but when I tried to press one of the toggle buttons, the whole window just closed. Do you know why it reacted in this way? What is wrong with it? Nontheless, I thank you for your help!

phearbear, I did your suggested way and it worked! Thanks a lot!