Re: help with window widgets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

You need to step back a second and think about some redesign  
following some simple guidelines.  If, after you've redesigned, your  
problem doesn't go away, it will, at the very least certainly change  
its nature.

Basically, you are mixing graphical and event-based programming  
domains (I think, a little hard to know since it's not obvious if  
your code follows your specifications precisely or not).  For  
example, do you require a new widget every time to display a new  
incoming value?  In the first instance, I will assume that you  
require a single widget to display all incoming values.  If this is  
the case, you should try to redesign your program flow thus:

main()
{
	// make ALL widgets necessary for program
	
	// enter while loop to read all values from stdin
		// for each value, update the entry widget to display accordingly
	
	gtk_main();
}

In other words, take all your widget creation out of the while loop,  
leaving only the reading from stdin and update of your display widget.

That said, as an example, this program will demonstrate output of  
text to a widget.  In the real world of event-driven programs,  
however, it won't do much, since your mainloop will sit and wait for  
user events which will never arrive, since there's nothing to do  
except screen refreshes.  Though I can't see the deleted code, so  
this may not be relevant.

Does/Will your program require reading from standard input for the  
entirety of its existence?  Or will these data be delivered to your  
program periodically from somewhere else (e.g., a program which has  
read the voltage from the battery)?  Whatever the case, the proper  
way to deal with this is to create your widgets, enter the main loop,  
and then wait for events to arrive which require processing.  You  
will need to define the method by which your external program will  
deliver its information to your display program and accommodate  
accordingly.

If, on the other hand, your requirements are that each data point  
instantiates a separate widget for display (as your program currently  
implies), then try the following:
1) inside your while loop, remove all gtk_widget_show() calls  
(typically, a call to gtk_widget_show() after each widget is created  
is unnecessary).
2) at the end of the while loop, make a single call to  
gtk_widget_show_all(), specifying the top-most widget in the  
hierarchy created within the while loop.

cheers,

richard


On Nov 13, 2006, at 6:41 AM, ybisou wrote:

>
>
>> Why do you put gtk_widget_show_all and gtk_main calls in the loop?  
>> You
>> should move at least the gtk_main call outside of the loop.
>
> I made some changes but I still can't have the widget to output all  
> the
> integers coming from the STDIN. Only the first one is on the  
> screen ! I will
> appreciate if you could help me, thanks !
> Here is a snipet of the code...
>
> // GTK initializations
>
>  int main( int   argc, char *argv[] )
> {
>
>   /*  GTK widget setup */
>
> unsigned int val;
> char buf[5];
>
> while(read(STDIN_FILENO, &val, sizeof(int)))  // here is my  
> problem, I'm not
> able to actually go through this while loop more than once or is  
> there a way
> to refresh the windows so their contents could also be refreshed 
> (variables)?
> {
> 	char temp[5];
> 	//read(STDIN_FILENO, &val, sizeof(int));
> 	buf[0]=ita(val/100);
> 	buf[1]=ita((val-((val/100)*100))/10);
> 	buf[2]='.';
> 	buf[3]=ita(val-((val/10)*10));
> 	
> 	printf(" reading %d",val); //just making sure i'm reading val
> 	
>
>     //  
> --------------------------------------------------------------------
>     // Create text entry widget and modify.
>     //  
> --------------------------------------------------------------------
>
>     text_entry_Widget = gtk_entry_new();
>
>     gtk_widget_modify_text(text_entry_Widget, GTK_STATE_NORMAL,
> &colorGreen);
>     gtk_widget_modify_base(text_entry_Widget, GTK_STATE_NORMAL,
> &colorBlack);
>
>     GtkStyle *style = gtk_widget_get_style(text_entry_Widget);
>     pango_font_description_set_weight(style->font_desc,  
> PANGO_WEIGHT_BOLD);
>
>     gtk_widget_modify_font(text_entry_Widget, style->font_desc);
>
>     int        text_width = 5;           // Width of field in  
> characters
>     gtk_entry_set_width_chars(GTK_ENTRY(text_entry_Widget),  
> text_width);
>
>     gtk_editable_set_editable(GTK_EDITABLE(text_entry_Widget), FALSE);
>     GTK_WIDGET_UNSET_FLAGS(text_entry_Widget, GTK_CAN_FOCUS);
>
>
>     strcat(buf," V");                    // V for volts after the int
>     gtk_entry_set_text(GTK_ENTRY(text_entry_Widget), buf); //  
> output the int
> value
>
>    PangoFontDescription *font_desc =  
> pango_font_description_from_string
> ("PANGO_STYLE_OBLIQUE,Monospace 30");
>     gtk_widget_modify_font (text_entry_Widget, font_desc);
>     pango_font_description_free (font_desc);
>
>
>     //  
> --------------------------------------------------------------------
>
>
>   vbox = gtk_vbox_new (FALSE, 5);
>   gtk_box_pack_start (GTK_BOX (vBox_Widget), vbox, FALSE, FALSE, 0);
>
>   frame = gtk_frame_new ("DC Voltages");
>
>
>   label = gtk_label_new ("\nThis voltage comes from 12 V battery \n"\
> 			 "It's value should be stable.\n"\
> 			 "When undervoltage, a signal is generated");
>
>     PangoFontDescription *font_desc2 =  
> pango_font_description_from_string
> ("PANGO_STYLE_OBLIQUE,Monospace 10");
> //PangoFontDescription *font_desc2 =  
> pango_font_description_from_string
> ("PANGO_STYLE_OBLIQUE,PANGO_VARIANT_NORMAL,PANGO_WEIGHT_BOLD,PANGO_STR 
> ETCH_EXPANDED
> ,Monospace 30");
>     gtk_widget_modify_font (label, font_desc2);
>     pango_font_description_free (font_desc2);
>
>     gtk_widget_show (label);
>
>
>   gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
>   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
>   gtk_container_add (GTK_CONTAINER (frame), label);
>   gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
>
>
>     gtk_box_pack_start (GTK_BOX (vbox), text_entry_Widget, NULL,  
> NULL, 0);
>     gtk_widget_show (text_entry_Widget);   // show the int value
>
>     gtk_container_add (GTK_CONTAINER (hbox), vBox_Widget);
>
>   text=gtk_text_new(NULL, NULL);
>   gtk_widget_show(text);
>   gtk_container_add(GTK_CONTAINER(vbox), text);
>   gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, buffer, strlen 
> (buffer));
>
> 	//Text motif
>
> fnt=gdk_font_load("-unknown-Arial-normal-r-normal-*-*-650-96-96-p-0- 
> iso8859-1");
>
>   gtk_text_insert (GTK_TEXT (text), fnt, &text->style->black, NULL,
> 		   "\nSupports ", -1);
>
> 	//creating a seperator
> 	separator = gtk_hseparator_new ();
> 	gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 5);
>         gtk_widget_show (separator);
>
> 	// some other stuff here
>
> }
>   gtk_widget_show_all (window);
>   gtk_main ();
>
>
>   close(fd);
>   return 0;
> }
>
> -- 
> View this message in context: http://www.nabble.com/help-with- 
> window-widgets-tf2615494.html#a7311745
> Sent from the Gtk+ - General mailing list archive at Nabble.com.
>
> _______________________________________________
> gtk-list mailing list
> gtk-list@xxxxxxxxx
> http://mail.gnome.org/mailman/listinfo/gtk-list
>

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux