gtk-plot experience, need help with gtk_plot_remove_data()

arne <[email protected]> Wed, 02 Apr 2008 21:56:34 +0200
Newsgroups gmane.comp.scigraphica.gtkextra
Message-ID <[email protected]>
Hello,
i am writing a smal gtk applikation using gtk-plot.
The goal at the moment is to display up to 16 graphs of sampled data with 512 support points.

Since i have not much experience with GUI Programming,
i started modifing the gtk-plot example.

I have a gtk_plot within a gtk_plot_canvas, like in the example.
now i have added some graphs with gtk_plot_add_function(..).

Modifing these graphs and refreshing works as i expected, but removing one or more of these graphs 
using gtk_plot_remove_data() is not my friend at the moment.

Really stange is, that, in some cases, the removing works, but not reproducible and not for all 
graphs. If I restart my application, it is over, then it works for no graph, until, so good is in 
good humor, it works agine after several restarts.

I dont get any gtk-error messages. I tried to hide the praph-widget, but this has no effect. 
Destroying the graph-widget cause a segmentation fault later on.


Greetings
Arne


###My Code for Drawing the graphs (stripped)

  if (gui.cctrl.data_ok)
   {
     for (i = 0;i < 16; i++)
     {
       if (gui.channel[i].channel_active)
       {
         gui.channel[i].plot_data = gtk_plot_add_function(GTK_PLOT(plot), 
(GtkPlotFunc)get_channel_data);
         gui.channel[i].plot_data->iterator_mask = i;  //use iterator_mask for channel identifkation 
in callback
         gtk_widget_show(GTK_WIDGET(gui.channel[i].plot_data));
         gtk_plot_data_set_line_attributes(gui.channel[i].plot_data,GTK_PLOT_LINE_SOLID,0, 0, 1, 
&gui.channel[i].color);
       }
       else
       {
         if (gui.channel[i].plot_data != NULL)
         {
           printf ("remove %d\n",i);
           gtk_widget_hide(GTK_WIDGET(gui.channel[i].plot_data));
           gtk_plot_remove_data (GTK_PLOT(plot),gui.channel[i].plot_data);

           //gtk_widget_destroy(GTK_WIDGET(gui.channel[i].plot_data));
           gui.channel[i].plot_data = NULL;
         }
       }
     }
   }

   gtk_plot_canvas_paint (GTK_PLOT_CANVAS(gui.canvas));
   gtk_plot_canvas_refresh (GTK_PLOT_CANVAS(gui.canvas));




###Callback with creation of some test Data:

gdouble get_channel_data(GtkPlot *plot, GtkPlotData *data, gdouble x, gboolean *err)
{
  gdouble y;
  *err = FALSE;
  int e,p;

  e = x -gui.cctrl.x_start;

  //Testdate for channel 0 to 3
  if (data->iterator_mask == 0) p = g_ossi_data[e];
  else if (data->iterator_mask == 1) p = g_ossi_data[512 - e];
  else if (data->iterator_mask == 2) p = g_ossi_data[e] - 128;
  else if (data->iterator_mask == 3) p = g_ossi_data[512 -e] - 128;
  else p = 0;

  if (p > scale_y.max) *err = 1;
  else if (p < scale_y.min) *err = 1;

  y = p;
  return y;
}


###Creation of the gtk_plot (stripped):

  gui.canvas = gtk_plot_canvas_new(600, 400, 1.0);
  gtk_widget_show(gui.canvas);

  gui.plot = gtk_plot_new_with_size(NULL, 1.0, 1.0);
  gtk_plot_hide_legends (GTK_PLOT(gui.plot));

  gui.cctrl.x_start = -256.;
  gui.cctrl.x_end = gui.cctrl.x_start + 512.;
  gtk_plot_set_xrange(GTK_PLOT(gui.plot), gui.cctrl.x_start, gui.cctrl.x_end);

  child = gtk_plot_canvas_plot_new(GTK_PLOT(gui.plot));
  gtk_plot_canvas_put_child(GTK_PLOT_CANVAS(gui.canvas), child, .02, .01, .92, .95);
  gtk_widget_show(gui.plot);

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace