Sample program doesn't build & possible library bug
"Nickolai Dobrynin" <[email protected]> Fri, 17 Feb 2006 19:11:24 -0600
| Newsgroups | gmane.comp.scigraphica.gtkextra |
|---|---|
| Message-ID | <[email protected]> |
Greetings,
1. I was using gcc-3.4.4 to source-install the latest CVS snapshot of the
GtkExtra library.
The installation didn't give me any troubles at all, but when I tried to
compile one of
the sample programs, called testrealtime.c, that didn't work:
testrealtime.cc:154: error: invalid conversion from `int' to
`GtkPlotAxisPos'
testrealtime.cc:154: error: initializing argument 2 of `GtkPlotAxis*
gtk_plot_get_axis(GtkPlot*, GtkPlotAxisPos)'
testrealtime.cc:154: error: invalid conversion from `int' to
`GtkPlotLabelStyle'
testrealtime.cc:154: error: initializing argument 2 of `void
gtk_plot_axis_set_labels_style (GtkPlotAxis*, GtkPlotLabelStyle, gint)'
testrealtime.cc:155: error: invalid conversion from `int' to
`GtkPlotAxisPos'
testrealtime.cc:155: error: initializing argument 2 of `GtkPlotAxis*
gtk_plot_get_axis(GtkPlot*, GtkPlotAxisPos)'
testrealtime.cc:155: error: invalid conversion from `int' to
`GtkPlotLabelStyle'
testrealtime.cc:155: error: initializing argument 2 of `void
gtk_plot_axis_set_labels_style(GtkPlotAxis*, GtkPlotLabelStyle, gint)'
testrealtime.cc:168: error: invalid conversion from `int' to
`GtkPlotBorderStyle'
testrealtime.cc:168: error: initializing argument 2 of `void
gtk_plot_set_legends_border(GtkPlot*, GtkPlotBorderStyle, gint)'
testrealtime.cc:190: error: invalid conversion from `int' to `GdkCapStyle'
testrealtime.cc:190: error: initializing argument 3 of `void
gtk_plot_data_set_line_attributes(GtkPlotData*, GtkPlotLineStyle,
GdkCapStyle, GdkJoinStyle, gfloat, const GdkColor*)'
Please note that I did get a testrealtime executable built for me by the
installer. It's that I myself wasn't able
to build it from source. After some digging, I realized that it was the way
'enum's were treated that the compiler
was upset with. Whenever you declare an 'enum', the compiler insists that
its elements be referred to explicitly by
name and not by the numerical value associated with each individual one.
For example, after declaring
enum{NOTHING, SOMETHING}, any code that uses 0 and 1 to refer to these two
constants, respectively, would be
rejected. I am copy-pasting the modified version of the file below. Would
it make sense to use it in the distribution
rather than the original one.
For completeness sake, these are the options "pkg-config --cflags --libs
gtkextra-2.0" produces on my machine:
-DXTHREADS -D_REENTRANT -DXUSE_MTSAFE_API
-I/home/ndobrynin/main/testing/gtk+extra-2-CVS-02032006/include/gtkextra-2.0-I/usr/include/glib-
2.0 -I/usr/lib/glib-2.0/include -I/usr/include/gtk-2.0
-I/usr/lib/gtk-2.0/include
-I/usr/include/atk-1.0 -I/usr/include/pango-1.0 -I/usr/include/freetype2
-I/usr/include/freetype2/config
-L/home/ndobrynin/main/testing/gtk+extra-2-CVS-02032006/lib -
lgtkextra-x11-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm
-lpangoxft-1.0 -lpangox-1.0 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -
lglib-2.0
Is this possible that some C compatibility option may be needed in order for
this enum-hack to be accepted?
1a. The same issue also happens with testiterator.c, and I didn't try
building any other sample files other than the
two I just mentioned.
2. In the code below (which is a slight deviation from testrealtime.c, as I
had just explained), I tried commenting all
gtk_widget_show calls and inserting one "big" gtk_widget_show_all(window1)
call at the end. Normally, as I would
expect, no difference should result. However, it did cause some abnormal
behavior: the plot first appeared on the
screen when it was half way through the drawing area. In other words, it
just appeared at once when half of the
window was already painted. There seem to have been problems of that nature
before:
http://sourceforge.net/mailarchive/forum.php?thread_id=8154315&forum_id=4125
Best regards,
Nickolai
#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"
GdkPixmap *pixmap=NULL;
GtkWidget **plots;
GtkPlotData *dataset;
gint nlayers = 0;
gint32 timer;
GtkWidget *canvas;
gdouble *px;
gdouble *py;
void
quit ()
{
gtk_timeout_remove(timer);
gtk_main_quit();
g_free(px);
g_free(py);
g_free(plots);
}
GtkWidget *
new_layer(GtkWidget *)
{
gchar label[10];
nlayers++;
plots = (GtkWidget **)g_realloc(plots, nlayers * sizeof(GtkWidget *));
sprintf(label, "%d", nlayers);
plots[nlayers-1] = gtk_plot_new_with_size(NULL, .65, .45);
return plots[nlayers-1];
}
gint
update(gpointer data)
{
GtkPlot *plot;
gdouble x, y;
gdouble xmin, xmax;
plot = GTK_PLOT(data);
px = (gdouble *)g_realloc(px, (dataset->num_points+1)*sizeof(gdouble));
py = (gdouble *)g_realloc(py, (dataset->num_points+1)*sizeof(gdouble));
y = rand()%10/10.;
if(dataset->num_points == 0)
x = 1;
else
x = px[dataset->num_points-1] + 1;
px[dataset->num_points] = x;
py[dataset->num_points] = y;
gtk_plot_data_set_numpoints(dataset, dataset->num_points+1);
gtk_plot_data_set_x(dataset, px);
gtk_plot_data_set_y(dataset, py);
gtk_plot_get_xrange(plot, &xmin , &xmax);
if(x > xmax){
gtk_plot_set_xrange(plot, xmin + 5. , xmax + 5.);
gtk_plot_canvas_paint(GTK_PLOT_CANVAS(canvas));
gtk_widget_queue_draw(GTK_WIDGET(canvas));
} else {
gtk_plot_data_draw_points(dataset, 1);
gtk_plot_refresh(plot, NULL);
}
return TRUE;
}
int main(int argc, char *argv[]){
GtkWidget *window1;
GtkWidget *vbox1;
GtkWidget *scrollw1;
GtkWidget *active_plot;
GtkPlotCanvasChild *child;
GdkColor color;
gint page_width, page_height;
gfloat scale = 1.;
page_width = (guint)(GTK_PLOT_LETTER_W * scale);
page_height = (guint)(GTK_PLOT_LETTER_H * scale);
gtk_init(&argc,&argv);
window1=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window1), "GtkPlot Real Time Demo");
gtk_widget_set_usize(window1,550,600);
gtk_container_border_width(GTK_CONTAINER(window1),0);
gtk_widget_show(window1);
gtk_signal_connect (GTK_OBJECT (window1), "destroy",
GTK_SIGNAL_FUNC (quit), NULL);
vbox1=gtk_vbox_new(FALSE,0);
gtk_container_add(GTK_CONTAINER(window1),vbox1);
gtk_widget_show(vbox1);
scrollw1=gtk_scrolled_window_new(NULL, NULL);
gtk_container_border_width(GTK_CONTAINER(scrollw1),0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollw1),
GTK_POLICY_ALWAYS,GTK_POLICY_ALWAYS);
gtk_box_pack_start(GTK_BOX(vbox1),scrollw1, TRUE, TRUE,0);
gtk_widget_show(scrollw1);
canvas = gtk_plot_canvas_new(page_width, page_height, 1.);
GTK_PLOT_CANVAS_UNSET_FLAGS(GTK_PLOT_CANVAS(canvas),
GTK_PLOT_CANVAS_DND_FLAGS);
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrollw1),
canvas);
gdk_color_parse("light blue", &color);
gdk_color_alloc(gtk_widget_get_colormap(canvas), &color);
gtk_plot_canvas_set_background(GTK_PLOT_CANVAS(canvas), &color);
gtk_widget_show(canvas);
active_plot = new_layer(canvas);
gdk_color_parse("light yellow", &color);
gdk_color_alloc(gtk_widget_get_colormap(active_plot), &color);
gtk_plot_set_background(GTK_PLOT(active_plot), &color);
gdk_color_parse("white", &color);
gdk_color_alloc(gtk_widget_get_colormap(canvas), &color);
gtk_plot_legends_set_attributes(GTK_PLOT(active_plot),
NULL, 0,
NULL,
&color);
gtk_plot_set_range(GTK_PLOT(active_plot), 0. ,20., 0., 1.);
gtk_plot_set_ticks(GTK_PLOT(active_plot), GTK_PLOT_AXIS_X, 2, 1);
gtk_plot_set_ticks(GTK_PLOT(active_plot), GTK_PLOT_AXIS_Y, .1, 1);
gtk_plot_axis_set_labels_style(gtk_plot_get_axis(GTK_PLOT(active_plot),
GTK_PLOT_AXIS_RIGHT), GTK_PLOT_LABEL_FLOAT, 0);
gtk_plot_axis_set_labels_style(gtk_plot_get_axis(GTK_PLOT(active_plot),
GTK_PLOT_AXIS_TOP), GTK_PLOT_LABEL_FLOAT, 0);
gtk_plot_axis_set_visible(gtk_plot_get_axis(GTK_PLOT(active_plot),
GTK_PLOT_AXIS_TOP), TRUE);
gtk_plot_axis_set_visible(gtk_plot_get_axis(GTK_PLOT(active_plot),
GTK_PLOT_AXIS_RIGHT), TRUE);
gtk_plot_grids_set_visible(GTK_PLOT(active_plot), TRUE, TRUE, TRUE, TRUE);
child = gtk_plot_canvas_plot_new(GTK_PLOT(active_plot));
gtk_plot_canvas_put_child(GTK_PLOT_CANVAS(canvas), child, .15, .15, .80,
.65);
gtk_widget_show(active_plot);
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");
gtk_plot_axis_set_title(gtk_plot_get_axis(GTK_PLOT(active_plot),
GTK_PLOT_AXIS_BOTTOM), "Time (s)");
gtk_plot_set_legends_border(GTK_PLOT(active_plot), GTK_PLOT_BORDER_SHADOW,
3);
gtk_plot_legends_move(GTK_PLOT(active_plot), .60, .10);
child = gtk_plot_canvas_text_new("Times-BoldItalic", 20, 0, NULL, NULL,
TRUE,
GTK_JUSTIFY_CENTER,
"Real Time Demo");
gtk_plot_canvas_put_child(GTK_PLOT_CANVAS(canvas), child, .45, .05, 0.,
0.);
dataset = GTK_PLOT_DATA(gtk_plot_data_new());
gtk_plot_add_data(GTK_PLOT(active_plot), dataset);
gtk_widget_show(GTK_WIDGET(dataset));
gdk_color_parse("red", &color);
gdk_color_alloc(gdk_colormap_get_system(), &color);
gtk_plot_data_set_legend(dataset, "Random pulse");
gtk_plot_data_set_symbol(dataset,
GTK_PLOT_SYMBOL_DIAMOND,
GTK_PLOT_SYMBOL_OPAQUE,
10, 2, &color, &color);
gtk_plot_data_set_line_attributes(dataset,
GTK_PLOT_LINE_SOLID,
GDK_CAP_NOT_LAST, GDK_JOIN_MITER, 1,
&color);
gtk_plot_canvas_paint(GTK_PLOT_CANVAS(canvas));
gtk_plot_canvas_refresh(GTK_PLOT_CANVAS(canvas));
gtk_plot_clip_data(GTK_PLOT(active_plot), TRUE);
/* gtk_widget_show_all(GTK_WIDGET(window1)); */
timer = gtk_timeout_add(300, update, active_plot);
gtk_main();
return(0);
}