Re: Regarding Gtkdatabox modified example...



Hi Nisha,

the "signals" come through loud and clear for all gtkdatabox widgets.

The problem is, that you are using those static variables which you initialize over and over again for each box. When you modify them in the idle function, you modify the last data set only. You need to maintain three sets of data if you want to modify the data in three boxes.


Regards,

Roland

nisha jain wrote:
Hi All,
I am facing a small issue.. I have modified the Gtkdatabox lissajous.c file to create 3 boxes for displaying signals. I made following 3 functions for data display. But when i run the program i get signal in only 3rd box i tried to resolve it but i am not sure what is going on wrong. Even though i am passing different objects of Widget box[i] i am not able to get signal in first and second box... Please let me know if some one can find the bug? Following the function for drawing 3 boxes....

void create_box(GtkWidget *window)
{
       GtkWidget *box1;
       GtkWidget *box2;
        GtkWidget *box[4];
GtkWidget *table[3]; GtkDataboxGraph *graph;
        GtkWidget separator;
        GdkColor color;
        gint i;

gint signal_idle = 0;

box1 = gtk_vbox_new(FALSE, 0); gtk_container_add( GTK_CONTAINER(window), box1);

         /* Create the databoxes */
         for( i = 0; i<3; i++)
          {
/* Create a GtkDatabox widget along with scrollbars and rulers */ gtk_databox_create_box_with_scrollbars_and_rulers (&box[i], &table[i],
                                TRUE, TRUE, TRUE, TRUE);
gtk_box_pack_start (GTK_BOX (box1), table[i], TRUE, TRUE, 0);
          }
// To make cross lines on the boxes

          color.red = 32768;
          color.green = 32768;
          color.blue = 32768;

           graph = gtk_databox_cross_simple_new (&color, 0);
for( i = 0; i<3; i++)
            {
                     gtk_databox_graph_add (GTK_DATABOX (box[i]), graph);
            }

            // To fill up the boxes with black color
             color.red = 0;
             color.green = 0;
             color.blue = 0;//32768;

            for( i = 0; i<3; i++)
            {
gtk_widget_modify_bg (box[i], GTK_STATE_NORMAL, &color);
            }

             // Display signals on boxes
for( i = 0; i<3; i++)
             {
                      disp_signal(box[i],color,graph);

signal_idle = g_idle_add ((GSourceFunc) signal_idle_func, box[i]);
             }
}

And following functions for displaying signal called from previous function......

Here SignalX and SignalY are static variable intialized in beginning of program...

void disp_signal(GtkWidget *box, GdkColor color, GtkDataboxGraph *graph )
{
gint i; signal_frequency = 0;
         signal_frequency = 3. * G_PI / 2.;
         signal_counter = 0;

#if 1 /* For testing purpose putted here replace with suitable code later */
         signalX = g_new0 (gfloat, POINTS);
         signalY = g_new0 (gfloat, POINTS);

          for (i = 0; i < POINTS; i++)
          {
                      signalX[i] = 100. * sin (i * 4 * G_PI / POINTS);
                      signalY[i] = 100. * cos (i * 4 * G_PI / POINTS);
          }

            color.red = 65535;
            color.green = 65535;
            color.blue = 0;

graph = gtk_databox_lines_new (POINTS, signalX, signalY, &color, 1);

             gtk_databox_graph_add (GTK_DATABOX (box), graph);

            gtk_databox_auto_rescale (GTK_DATABOX (box), 0.05);
#endif
}

static gboolean
signal_idle_func (GtkDatabox * box)
{
       gfloat freq;
       gfloat off;
         gint i;

         if (!GTK_IS_DATABOX (box))
               return FALSE;

         signal_frequency += 0.001;
         off = signal_counter * 4 * G_PI / POINTS;
           freq = 14 + 10 * sin (signal_frequency);

         for (i = 0; i < POINTS; i++)
        {
                signalX[i] = 100. * sin (i * 4 * G_PI / POINTS + off);
                signalY[i] = 100. * cos (i * freq * G_PI / POINTS + off);
         }

         gtk_databox_redraw (GTK_DATABOX (box));
         return TRUE;
}

Regards,

Nisha


------------------------------------------------------------------------

_______________________________________________
gtkdatabox-list mailing list
gtkdatabox-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkdatabox-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]