--- Begin Message ---
- From: Frederic Cazenave <frederic cazenave hmg inpg fr>
- To: scigraphica-gtkextra lists sourceforge net
- Subject: compaibility between 0.99.13 and 0.99.17
- Date: Tue, 26 Nov 2002 16:25:57 +0000
Hi
The following program linked with gtk+extra-0.99.13
displays data and not with gtk+extra-0.99.17.
Could you give me some help
Fred
--
_________________________________________________________
| |
| Frederic CAZENAVE |
| _/\_ /^= LTHE / IRD |
| \_/ \// BP 53 |
| | /-\ | 38041 Grenoble Cedex 9 |
| || || France |
| Tel 33 4 76 82 50 92 Fax 33 4 76 82 52 86 |
| mailto:Frederic Cazenave hmg inpg fr |
| http://www.lthe.hmg.inpg.from.fr/catch |
|__________________________________________________________|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include "gtkplot.h"
#include "gtkplotdata.h"
#include "gtkplotcanvas.h"
#include <sys/time.h>
#include <unistd.h>
#include "sharemem.h"
#include "dialog.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 = (GdkColor *) g_malloc (sizeof (GdkColor));
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_axis_set_ticks(GTK_PLOT(active_plot), GTK_PLOT_AXIS_X, 10, 1);
gtk_plot_axis_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(active_plot), GTK_PLOT_AXIS_TOP,FALSE);
gtk_plot_axis_set_visible(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(active_plot), GTK_PLOT_AXIS_TOP);
gtk_plot_axis_hide_title(GTK_PLOT(active_plot), GTK_PLOT_AXIS_RIGHT);
gtk_plot_axis_set_title(GTK_PLOT(active_plot), GTK_PLOT_AXIS_LEFT, "Intensity (dB)");
gtk_plot_axis_set_title(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,
1, color);
g_free(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;
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]= *(float *)(base + pos ) / 64;
// data1[i]= data1[i] > 0 ? 10*log10(data1[i]) - 163 : - 233;
i++;
// data1[i]= *(float *)(base + pos + 200 * 8 * sizeof(float) + sizeof(int)) / 64;
// data1[i]= data1[i] > 0 ? 10*log10(data1[i]) - 163 : - 233;
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() */
--- End Message ---