using GtkPlot from Gtk+Extra without canvas
- From: François Galea <Francois Galea prism uvsq fr>
- To: gtk-app-devel-list gnome org
- Subject: using GtkPlot from Gtk+Extra without canvas
- Date: Tue, 09 Jan 2007 15:27:30 +0100
hi,
I have just subscibed to this mailing list.
I would like some help concerning the use of simple GtkPlot widgets
inside Gtk containers, such as GtkFrame, GtkVbox, etc.
I have read in the mailing list archive it could be possible using a
GtkDrawingArea for drawing the plots. But I personnaly never managed to
get anything displayed.
I took an example code from this mailing list archive, but never managed
to get it into running on Gtk+extra 2.0.
Here is the link for the original program :
http://mail.gnome.org/archives/gtk-app-devel-list/2002-December/msg00037.html
My modified version in order to get it compiling with GTK+Extra 2 follows.
The results are a bunch of messages of the form :
(plot2:3556): Gtk-CRITICAL **: gtk_widget_realize: assertion
`GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed
(plot2:3556): Gtk-CRITICAL **: gtk_widget_real_map: assertion
`GTK_WIDGET_REALIZED (widget) == TRUE' failed
(plot2:3556): Gdk-CRITICAL **: gdk_window_invalidate_rect: assertion
`window != NULL' failed
(plot2:3556): Gtk-CRITICAL **: gtk_widget_realize: assertion
`GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed
....... and so on.
No data is displayed, the allocated drawing frame stays grey.
Could anybody have a look at the code of this program and tell me where
the problem is ?
Thanks in advance,
--
François Galea
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include "gtkextra/gtkplot.h"
#include "gtkextra/gtkplotdata.h"
#include "gtkextra/gtkplotcanvas.h"
#include "gtkextra/gtkplotcanvasplot.h"
#include "gtkextra/gtkplotcanvastext.h"
static gboolean drawing_area_events(GtkWidget * calling_widget,
GdkEvent * event, GtkWidget *
da_window);
GdkPixmap *pixmap = NULL;
GtkPlotData *dataset;
gint32 timer;
volatile unsigned long *share;
void set_plot(GtkWidget * active_plot)
{
GdkColor color;
color.red = 0x0000;
color.green = 0x9999;
color.blue = 0x0000;
gdk_color_alloc(gtk_widget_get_colormap(active_plot), &color);
gtk_plot_set_background(GTK_PLOT(active_plot), &color);
gtk_plot_set_range(GTK_PLOT(active_plot), 0., 400, -80, 20);
gtk_plot_set_ticks(GTK_PLOT(active_plot), GTK_PLOT_AXIS_X, 10, 1);
gtk_plot_set_ticks(GTK_PLOT(active_plot), GTK_PLOT_AXIS_Y, 10, 1);
/* gtk_plot_axis_labels_set_numbers( GTK_PLOT( active_plot ), 2, 0, 0 );
gtk_plot_axis_labels_set_numbers( GTK_PLOT( active_plot ), 3, 0, 0 );
*/
gtk_plot_axis_set_visible(gtk_plot_get_axis(GTK_PLOT(active_plot),
GTK_PLOT_AXIS_TOP), FALSE);
gtk_plot_axis_set_visible(gtk_plot_get_axis(GTK_PLOT(active_plot),
GTK_PLOT_AXIS_RIGHT), FALSE);
gtk_plot_hide_legends(GTK_PLOT(active_plot));
gtk_plot_grids_set_visible(GTK_PLOT(active_plot), TRUE, TRUE, TRUE,
TRUE);
gtk_plot_axis_hide_title(gtk_plot_get_axis(GTK_PLOT(active_plot),
GTK_PLOT_AXIS_TOP));
gtk_plot_axis_hide_title(gtk_plot_get_axis(GTK_PLOT(active_plot),
GTK_PLOT_AXIS_RIGHT));
gtk_plot_axis_set_title(gtk_plot_get_axis(GTK_PLOT(active_plot),
GTK_PLOT_AXIS_LEFT),
"Intensity (dB)");
gtk_plot_axis_set_title(gtk_plot_get_axis
(GTK_PLOT(active_plot), GTK_PLOT_AXIS_BOTTOM),
"Time (s)");
gtk_widget_show(active_plot);
dataset = GTK_PLOT_DATA(gtk_plot_data_new());
gtk_plot_add_data(GTK_PLOT(active_plot), dataset);
gdk_color_parse("red", &color);
gdk_color_alloc(gtk_widget_get_colormap(active_plot), &color);
//gdk_color_alloc(gdk_colormap_get_system(), color);
gtk_plot_data_set_line_attributes(dataset,
GTK_PLOT_LINE_SOLID,
0, 0, 1, &color);
}
void quit()
{
if (timer)
gtk_timeout_remove(timer);
gtk_main_quit();
}
gint update(gpointer data)
{
GtkPlot *plot;
gdouble x, y;
gdouble xmin, xmax;
gdouble data1[1024], data2[1024];
/* int Pos, pos, i; */
int i;
/* unsigned char *base;
base = (unsigned char *) ((unsigned char *) share + POS_SIZE);
Pos = pos = *(int *) share + 2 * sizeof(float) + header_size +
sizeof(int);
*/
for (i = 0; i < 400; i++ /*, pos += 8 * sizeof(float) */)
{
data1[i] = rand() % 20;
}
plot = GTK_PLOT(data);
// gtk_plot_remove_data(plot,dataset);
gtk_plot_paint(plot);
gtk_plot_refresh(plot, NULL);
gtk_plot_data_set_numpoints(dataset, 400);
for (i = 0; i < 400; i++)
data2[i] = i;
gtk_plot_data_set_x(dataset, data2);
gtk_plot_data_set_y(dataset, data1);
gtk_plot_get_xrange(plot, &data2[0], &data2[400 - 1]);
gtk_plot_data_draw_points(dataset, 400);
gtk_plot_refresh(plot, NULL);
//gtk_plot_refresh(GTK_PLOT(active_plot),GTK_WIDGET(drawing_area)->allocation);
return TRUE;
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *plot;
GtkWidget *drawing;
GtkWidget *vbox1;
GtkWidget *hbuttonbox1;
GtkWidget *Rec_Acq;
GtkWidget *hbox1;
GtkPlot *ptr;
// Connect to share memory SHMEM to get IQ
/* share = (unsigned long *) get_share_mem(); */
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Real Time PII Display");
gtk_widget_set_usize(window, 400, 400);
gtk_container_border_width(GTK_CONTAINER(window), 0);
gtk_widget_show(window);
gtk_signal_connect(GTK_OBJECT(window), "destroy",
GTK_SIGNAL_FUNC(quit), NULL);
vbox1 = gtk_vbox_new(FALSE, 0);
gtk_widget_ref(vbox1);
gtk_object_set_data_full(GTK_OBJECT(window), "vbox1", vbox1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show(vbox1);
gtk_container_add(GTK_CONTAINER(window), vbox1);
hbuttonbox1 = gtk_hbutton_box_new();
gtk_widget_ref(hbuttonbox1);
gtk_object_set_data_full(GTK_OBJECT(window), "hbuttonbox1", hbuttonbox1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show(hbuttonbox1);
gtk_box_pack_start(GTK_BOX(vbox1), hbuttonbox1, FALSE, FALSE, 1);
gtk_widget_set_usize(hbuttonbox1, -2, 33);
gtk_container_set_border_width(GTK_CONTAINER(hbuttonbox1), 0);
gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox1),
GTK_BUTTONBOX_START);
gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbuttonbox1), 10);
Rec_Acq = gtk_button_new_with_label("Rec Acq");
gtk_widget_ref(Rec_Acq);
gtk_object_set_data_full(GTK_OBJECT(window), "Configure", Rec_Acq,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show(Rec_Acq);
gtk_box_pack_start(GTK_BOX(hbuttonbox1), Rec_Acq, FALSE, FALSE, 0);
GTK_WIDGET_SET_FLAGS(Rec_Acq, GTK_CAN_DEFAULT);
hbox1 = gtk_hbox_new(FALSE, 0);
gtk_widget_ref(hbox1);
gtk_object_set_data_full(GTK_OBJECT(window), "hbox1", hbox1,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show(hbox1);
gtk_box_pack_end(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0);
gtk_container_set_border_width(GTK_CONTAINER(hbox1), 5);
drawing = gtk_drawing_area_new();
gtk_container_add(GTK_CONTAINER(hbox1), drawing);
gtk_object_set_data(GTK_OBJECT(hbox1), "drawing area", drawing);
gtk_widget_show(drawing);
plot = gtk_plot_new(NULL);
ptr = (GtkPlot *) plot;
ptr->width = .8;
ptr->height = .8;
ptr->bottom->title.y = ptr->height + .185;
// gtk_widget_show(plot);
gtk_object_set_data(GTK_OBJECT(hbox1), "active plot", plot);
//gtk_plot_set_drawable(GTK_PLOT(plot),GTK_WIDGET(drawing)->window);
gtk_signal_connect(GTK_OBJECT(drawing), "configure_event",
GTK_SIGNAL_FUNC(drawing_area_events), hbox1);
gtk_signal_connect(GTK_OBJECT(drawing), "expose_event",
GTK_SIGNAL_FUNC(drawing_area_events), hbox1);
gtk_signal_connect(GTK_OBJECT(drawing), "destroy_event",
GTK_SIGNAL_FUNC(drawing_area_events), hbox1);
gtk_main();
return (0);
}
/* Function to handle drawing area events */
gboolean drawing_area_events(GtkWidget * calling_widget, GdkEvent * event,
GtkWidget * da_window)
{
/* Declaring local variables */
GtkWidget *drawing_area;
GtkWidget *active_plot;
GdkColor color;
/* If event is "destroy"... */
if (event->type == GDK_DESTROY)
return (TRUE);
/* If event is "configure"... */
if (event->type == GDK_CONFIGURE)
{
drawing_area = gtk_object_get_data(GTK_OBJECT(da_window), "drawing
area");
active_plot = gtk_object_get_data(GTK_OBJECT(da_window), "active
plot");
if (drawing_area && active_plot)
{
if (!GTK_WIDGET_REALIZED(drawing_area))
return FALSE;
if (!GTK_PLOT(active_plot)->drawable)
{
GTK_WIDGET(active_plot)->parent = GTK_WIDGET(drawing_area)->parent;
if (!GTK_WIDGET_DRAWABLE(GTK_WIDGET(active_plot)))
{
gtk_widget_show(GTK_WIDGET(active_plot));
gtk_widget_map(GTK_WIDGET(active_plot));
}
GTK_WIDGET(active_plot)->window = GTK_WIDGET(drawing_area)->window;
}
if (GTK_PLOT(active_plot)->drawable)
gdk_pixmap_unref(GTK_PLOT(active_plot)->drawable);
GTK_PLOT(active_plot)->drawable =
gdk_pixmap_new(GTK_WIDGET(drawing_area)->window,
GTK_WIDGET(drawing_area)->allocation.width,
GTK_WIDGET(drawing_area)->allocation.height, -1);
gdk_draw_rectangle(GTK_PLOT(active_plot)->drawable,
GTK_WIDGET(drawing_area)->style->white_gc,
TRUE, 0, 0,
GTK_WIDGET(drawing_area)->allocation.width,
GTK_WIDGET(drawing_area)->allocation.height);
gtk_plot_set_drawable(GTK_PLOT(active_plot),
GTK_PLOT(active_plot)->drawable);
GTK_WIDGET(active_plot)->allocation.x = 0;
GTK_WIDGET(active_plot)->allocation.y = 0;
GTK_WIDGET(active_plot)->allocation.width =
GTK_WIDGET(drawing_area)->allocation.width;
GTK_WIDGET(active_plot)->allocation.height =
GTK_WIDGET(drawing_area)->allocation.height;
set_plot(active_plot);
gtk_widget_show_all(da_window);
if (!timer)
timer = gtk_timeout_add(300, update, active_plot);
//gtk_plot_export_ps (GTK_PLOT(active_plot), "demo.ps", 0, 0,
GTK_PLOT_LETTER);
}
}
/* If event is "expose"... */
if (event->type == GDK_EXPOSE)
{
active_plot = gtk_object_get_data(GTK_OBJECT(da_window), "active
plot");
if (active_plot)
gtk_plot_refresh(GTK_PLOT(active_plot), NULL);
}
/* Do not propogate event? */
return (TRUE);
}
/* End of drawing_area_events() */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]