View topic - PtColorWell change color callback not working

Page 1 of 1

PtColorWell change color callback not working

PostPosted: Sat Jun 08, 2013 7:42 am
by sieudot
Hi everyone, please help me.

I have written an example with PtColorWell widget on PhAB, QNX 6.3.3.
I used a PtColorWell widget to change color of a PtRect, so I write a callback with event Pt_CS_COLOR_CHANGED, its name ColorChange() as below.

Code: Select all
PgColor_t *mau;
int ColorChange( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
   widget = widget, apinfo = apinfo, cbinfo = cbinfo;
   PtGetResource( widget, Pt_ARG_CS_COLOR, &mau, 0 );
   return( Pt_CONTINUE );
}


But when I changed the PtColorWell, the variable mau had not changed. :(( Can someone fix it for me? pls.

Re: PtColorWell change color callback not working

PostPosted: Sat Jun 08, 2013 6:59 pm
by maschoen
I found your problem.

In PtTimer_activate change the line listed below:

PtSetResource( ABW_PtRect1, Pt_ARG_FILL_COLOR, mau, 0);

to

PtSetResource( ABW_PtRect1, Pt_ARG_FILL_COLOR, *mau, 0);

Re: PtColorWell change color callback not working

PostPosted: Sun Jun 09, 2013 8:54 am
by sieudot
yes, thank for your reply, maschoen :idea: . I will try.

Re: PtColorWell change color callback not working

PostPosted: Sun Jun 09, 2013 11:39 am
by sieudot
maschoen wrote:I found your problem.

In PtTimer_activate change the line listed below:

PtSetResource( ABW_PtRect1, Pt_ARG_FILL_COLOR, mau, 0);

to

PtSetResource( ABW_PtRect1, Pt_ARG_FILL_COLOR, *mau, 0);


Hi maschoen, I have changed my code as you said, but it caused a SIGSEGV signal on that code line.

This happends on any codes with variable *mau, evently in debugging with printf() function.

Code: Select all
 printf("%ld", *mau);


..Is something wrong?

Re: PtColorWell change color callback not working

PostPosted: Sun Jun 09, 2013 1:02 pm
by sieudot
Hi, I found the problem! It has come from the PtGetResource() function.

I must using this function below to get CHANGED COLOR:

Code: Select all
PgColor_t getcolor( PtWidget_t *widget, long type)
{
   PtArg_t arg;
   PtSetArg( &arg, type, 0, 0);
   PtGetResources( widget,1,&arg );
   return (PgColor_t) arg.value;
}

And calling it in the PtColorWell 's callback function:
Code: Select all
int ColorChange( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo)
{
   mau= getcolor( widget, Pt_ARG_CS_COLOR );   
   // get the changed color to the variable mau

   PtSetResource( ABW_PtRect1, Pt_ARG_FILL_COLOR, mau, 0);
   // set this color to anothe widget
}


Thanks all :mrgreen: :mrgreen:

Re: PtColorWell change color callback not working

PostPosted: Sun Jun 09, 2013 6:56 pm
by maschoen
Hi maschoen, I have changed my code as you said, but it caused a SIGSEGV signal on that code line.

This happends on any codes with variable *mau, evently in debugging with printf() function.

Code: Select all
 printf("%ld", *mau);


..Is something wrong?[/quote]

I forgot to mention. I initialized mau when I first saw the SIGSEGV. Actually, the way you are doing things is rather strange. You update the color picker and the rectangle colors asynchronously. You update the rectangle in a timer widget call. This is strange and unnecessary. At the very least you should keep the color in a global variable instead of mau. But I would update the rectangle when the color picker call is completed. That's the obvious solution.

Re: PtColorWell change color callback not working

PostPosted: Mon Jun 10, 2013 2:55 am
by sieudot
maschoen wrote:I forgot to mention. I initialized mau when I first saw the SIGSEGV. Actually, the way you are doing things is rather strange. You update the color picker and the rectangle colors asynchronously. You update the rectangle in a timer widget call. This is strange and unnecessary. At the very least you should keep the color in a global variable instead of mau. But I would update the rectangle when the color picker call is completed. That's the obvious solution.


Thank you for your interest. The PtTimer I used as an example when looking for a solution to PtColorWell only.
I also found and corrected errors in the PtColorWell color change callback as above post.