Elena Sebe
|
Accessing a custom widget's resources
|
Elena Sebe
04/30/2010 3:56 PM
post53342
|
Accessing a custom widget's resources
Hello,
I have been trying unsuccessfully to access a custom widget's resources. Any help would be greatly appreciated!
Details:
A trending widget was created some time ago which has worked well in the past. This time, I tried to get the value of
one of the resources of this custom-made widget. The resource was set from the resources tab of the control panel for
the widget. Internally, this resource is a char *.
At first, PtGetResources was returning NULL for the resource. To overcome the issue, I wrote my own getter function for
the resource, and told my custom widget to use it. That also returned null. I started printing things from within the
widget's code only to realize that the structure holding this resource is returning this resource as NULL.
My guess is that I'm somehow trying to get this resource too early (I'm calling my callback in the widget's realize
callback section.)
Here's some code that might be of help:
This is the custom widget's internal struct:
typedef struct
{
....
char *idcode0;
char *idcode1;
char *idcode2;
char *idcode3;
....
} CqTrendWidget_t;
t I altered the resource setting to add my getter function:
static PtResourceRec_t resources[] =
{
RESOURCE1, setter, getter,
Pt_ARG_IS_STRING( CqTrendWidget_t, idcode0 ), 0,
....
This is my setter function:
static int
getter( PtWidget_t *widget, PtArg_t *argt )
{
CqTrendWidget_t *w = ( CqTrendWidget_t * ) widget;
if (w->idcode0 == 0) fprintf(stderr, "NULL!\n");
fprintf(stderr, "My resource =[%s]", w->idcode0);
fflush(stderr);
// The address of a pointer to a char is in argt->value
*(char **)argt->value = w->idcode0;
return Pt_TRUE;
}
And in my callback function for my application (which I added as a realize callback for the widget), I try to retrieve
the resource like so:
char * blah;
PtArg_t args[1];
PtSetArg(&args[0], RESOURCE1 , &blah, 0);
fprintf(stderr, "HERE: [%s] \n", blah);
fflush(stderr);
Results:
blah is NULL (in my callback function)
w->idcode0 is also NULL ( in the getter function)
|
|
|