1

i am creating a basic GROUND CONTROL STATION for a CubeSat, dividing it in two parts: COMMANDS (with no problems) and TELEMETRY. I am using C code and GTK; in the telemetry windowt I need to show some info everytime a telemetry packet is received so I've tried to use a gtkview/gtkentry for each info, but I don't know, how to update the message shown in them.

In particular, an example is:

//View PACKET NUMBER    
 view = gtk_text_view_new();
 frame = gtk_frame_new("Packet number");    
 gtk_container_add(GTK_CONTAINER(frame), view);
 gtk_text_view_set_editable(GTK_TEXT_VIEW(view),FALSE);
 gtk_table_attach(GTK_TABLE(table2),frame,0,1,0,1,GTK_FILL,GTK_FILL,5,5);
 buff = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
 gtk_text_buffer_get_iter_at_offset(buff, &iter, 0);
 gtk_text_buffer_insert(buff, &iter,"waiting", -1);

so, first there is the text "WAITING", then when a packet is received I want to update that text: how can I do this?

I've tried repeating this code but changing "waiting" with a variable referring to "packet number", but I obtain core dump

I've also tried with this code, but I have always same problem.

viewprova = gtk_entry_new();
frameprova = gtk_frame_new("Packet number");
gtk_container_add(GTK_CONTAINER(frameprova), viewprova);
gtk_entry_set_editable(GTK_ENTRY(viewprova),FALSE);
gtk_table_attach(GTK_TABLE(table2),frameprova,0,1,0,1,GTK_FILL,GTK_FILL,5,5);
gtk_entry_set_text(GTK_ENTRY(viewprova),"waiting");



frameprova = gtk_frame_new("Packet number");    
viewprova = gtk_label_new ("waiting");
gtk_container_add(GTK_CONTAINER(frameprova), viewprova);
gtk_table_attach(GTK_TABLE(table2),frameprova,0,1,0,1,GTK_FILL,GTK_FILL,5,5);   

Thanks for the help!

geomerlin
  • 11
  • 2
  • What do you mean you tried "repeating this code"? You certainly didn't create a whole new Frame+TextView just to update the text. Can you please post the code you used to update the TextView? – Ancurio Oct 08 '12 at 19:20
  • To update TextView i've used the same code... I know that this is the problem, but I don't know how to do correctly! Cycle 1 = I create Text view with "waiting" text Cycle 2 = how do I update it? I've tried using same code (that is the first code I reported above, but with "waiting" changed with the text I want to show), but it didn't work (core dump) – geomerlin Oct 09 '12 at 09:34

2 Answers2

0

A function such as gtk_label_new() that accepts a C string can't take an integer instead, C functions are not polymorphic. You need to build a string representation and pass that, for instance using snprintf() to format the number into a string buffer.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • that's ok, but I have also tried changing the firts text (waiting) with another text (trying), but it gives me always core dump. – geomerlin Oct 08 '12 at 13:08
0

Ok, so if I understood you correctly, you know how to setup your text displaying widgets, but not, how to fill them with new contents, correct? Look at your code, and at what you're doing. First, you're creating a text widget. Then you fill it with initial text. This second part is the one you repeat:

In case of GtkEntry, gtk_entry_set_text(GTK_ENTRY(viewprova), "My new text");

In case of GtkTextView (actually you're using the underlying TextBuffer), gtk_text_buffer_set_text(buff, "My new text", -1);

Ancurio
  • 1,698
  • 1
  • 17
  • 32
  • thank you, I'll try this! probably I close the part where I create interface, so after I'am not able to modify it! – geomerlin Oct 10 '12 at 09:09