changing font, color, size, etc. in a GtkEntry
Hi there, I have a simple problem for weeks that I remain unable to solve. I simply want to modify the font, color, size, etc. of the characters entered while they are typed in a GtkEntry. I am coding with GTK 2.24.0. Looking around on the web, I found several possible functions to do that, some of them seem to be specific to GTK3, however. I found - and tried to play with - things like: gtk_entry_set_attributes gtk_widget_modify_text gtk_widget_modify_base gtk_widget_modify_font gtk_widget_create_pango_layout gtk_widget_create_pango_context Some of them lead me to define and to argument a pointer to a struct of type PangoFontDescription or GtkStyle. Hence, it seems that I also need to use function like, e.g., pango_font_description_set_weight, etc., but I'm not fully sure about this. I remained unable to sort this out, and some of these functions are even not recognized in my coding environment.. Hence, I just have now no idea about how to solve this. Code examples (for example, like here: http://www.yolinux.com/TUTORIALS/GTK+ProgrammingTips.html#TEXTBOXESFONTS) and/or explanations would be more than welcomed! Thanks for any help in this. Cheers, Eric. -- ~~ Eric Wajnberg Associated Professor at the University of Montreal (Quebec, Canada) I.N.R.A. 400 Route des Chappes, BP 167, 06903 Sophia Antipolis Cedex, France Tel: (33-0) 4.92.38.64.47 Fax: (33-0) 4.92.38.65.57 e-mail: wajnb...@sophia.inra.fr Web page: http://www.sophia.inra.fr/perso/wajnberg/ Editor-in-Chief of BioControl, Published by Springer. ~~ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: changing font, color, size, etc. in a GtkEntry
Eric Wajnberg wrote: I simply want to modify the font, color, size, etc. of the characters entered while they are typed in a GtkEntry. I am coding with GTK 2.24.0. Looking around on the web, I found several possible functions to do that, some of them seem to be specific to GTK3, however. I found - and tried to play with - things like: gtk_entry_set_attributes gtk_widget_modify_text gtk_widget_modify_base gtk_widget_modify_font gtk_widget_create_pango_layout gtk_widget_create_pango_context Some of them lead me to define and to argument a pointer to a struct of type PangoFontDescription or GtkStyle. Hence, it seems that I also need to use function like, e.g., pango_font_description_set_weight, etc., but I'm not fully sure about this. You are close. You need to use gtk_widget_modify_font(). You pass in a font description created by: PangoFontDescription *fontDesc = pango_font_description_from_string( monospace 10 ); This would set the entry text to a monospace-type font with 10 point size. Don't forget to call pango_font_description_free() afterwards. If you wish to change font while typing you need to connect to the key-press-event signal on the GtkEntry widget and handle key presses that way. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Valgrind is grinding my gears
I have a rather large program I've written in C language which uses GTK+2. My Makefile has: CCFLAGS = `pkg-config --cflags gtk+-2.0 gmodule-2.0` LIBS = `pkg-config --libs gtk+-2.0 gmodule-2.0` GCC compiles it without warnings using flags: -Wall -O -Wuninitialized My program has several user interface files prepared using Glade. I use the program quite a bit and have no stability issues. But when I invoke Valgrind at runtime, I get a lot of errors which I can't make any sense of. I have grabbed a small sample of them here: http://pdbuchan.com/valgrind.txt I don't like ignoring errors and warnings, but I don't know what to do with these. Has anybody else come across these types of Valgrind notifications? Dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Valgrind is grinding my gears
Perhaps relevant, is that I have a large struct which I use to pass stuff amongst functions and callbacks and I allocate memory for it in main() thus: // Allocate data structure data = g_slice_new (MyData); and then free it at the end: g_slice_free (MyData, data); Maybe Valgrind has trouble with g-sliced memory? From: David Buchan pdbuc...@yahoo.com To: gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 12:47 PM Subject: Valgrind is grinding my gears I have a rather large program I've written in C language which uses GTK+2. My Makefile has: CCFLAGS = `pkg-config --cflags gtk+-2.0 gmodule-2.0` LIBS = `pkg-config --libs gtk+-2.0 gmodule-2.0` GCC compiles it without warnings using flags: -Wall -O -Wuninitialized My program has several user interface files prepared using Glade. I use the program quite a bit and have no stability issues. But when I invoke Valgrind at runtime, I get a lot of errors which I can't make any sense of. I have grabbed a small sample of them here: http://pdbuchan.com/valgrind.txt I don't like ignoring errors and warnings, but I don't know what to do with these. Has anybody else come across these types of Valgrind notifications? Dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Valgrind is grinding my gears
Sorry for peppering you with emails but I just noticed this statement: For newly written code it is recommended to use the new g_slice API instead of g_malloc() and friends, as long as objects are not resized during their lifetime and the object size used at allocation time is still available when freeing - https://developer.gnome.org/glib/unstable/glib-Memory-Slices.html I do indeed change dimensions of arrays declared within my struct (a lot, in fact). Could this be the cause? From: David Buchan pdbuc...@yahoo.com To: gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 1:09 PM Subject: Re: Valgrind is grinding my gears Perhaps relevant, is that I have a large struct which I use to pass stuff amongst functions and callbacks and I allocate memory for it in main() thus: // Allocate data structure data = g_slice_new (MyData); and then free it at the end: g_slice_free (MyData, data); Maybe Valgrind has trouble with g-sliced memory? From: David Buchan pdbuc...@yahoo.com To: gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 12:47 PM Subject: Valgrind is grinding my gears I have a rather large program I've written in C language which uses GTK+2. My Makefile has: CCFLAGS = `pkg-config --cflags gtk+-2.0 gmodule-2.0` LIBS = `pkg-config --libs gtk+-2.0 gmodule-2.0` GCC compiles it without warnings using flags: -Wall -O -Wuninitialized My program has several user interface files prepared using Glade. I use the program quite a bit and have no stability issues. But when I invoke Valgrind at runtime, I get a lot of errors which I can't make any sense of. I have grabbed a small sample of them here: http://pdbuchan.com/valgrind.txt I don't like ignoring errors and warnings, but I don't know what to do with these. Has anybody else come across these types of Valgrind notifications? Dave ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Valgrind is grinding my gears
On Tue, Nov 05, 2013 at 09:47:13AM -0800, David Buchan wrote: But when I invoke Valgrind at runtime, I get a lot of errors which I can't make any sense of. I have grabbed a small sample of them here: http://pdbuchan.com/valgrind.txt I don't like ignoring errors and warnings, but I don't know what to do with these. Has anybody else come across these types of Valgrind notifications? Yes, everyone. You must understand that all the GObject type registration machinery is, under normal circumstances, only ever used to create structures that will exist during the entire program lifetime. So although things such as class reference leaks can exists, eveything inside g_type_class_ref() should be ignorable – and you can clearly see from the log that these allocations happen once, not a thousand times. The same for g_thread_init(), gtk_init(), etc. Create a suppression file or google one... Regards, Yeti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Valgrind is grinding my gears
Hi Dave, GObject type registration machinery is, under normal circumstances, only ever used tocreate structures that will exist during the entire program lifetime. Does that mean that if I just use straight old malloc() instead of g_slice(), most of the errors would go away? I gather that's essentially what using G_SLICE=always-malloc would do. I can't try this out until late tonight, unfortunately. From: David Nečas y...@physics.muni.cz To: David Buchan pdbuc...@yahoo.com Cc: gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 2:51 PM Subject: Re: Valgrind is grinding my gears On Tue, Nov 05, 2013 at 09:47:13AM -0800, David Buchan wrote: But when I invoke Valgrind at runtime, I get a lot of errors which I can't make any sense of. I have grabbed a small sample of them here: http://pdbuchan.com/valgrind.txt I don't like ignoring errors and warnings, but I don't know what to do with these. Has anybody else come across these types of Valgrind notifications? Yes, everyone. You must understand that all the GObject type registration machinery is, under normal circumstances, only ever used to create structures that will exist during the entire program lifetime. So although things such as class reference leaks can exists, eveything inside g_type_class_ref() should be ignorable – and you can clearly see from the log that these allocations happen once, not a thousand times. The same for g_thread_init(), gtk_init(), etc. Create a suppression file or google one... Regards, Yeti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Valgrind is grinding my gears
Aaaah. I see. Thanks guys. From: Bernhard Schuster schuster.bernh...@gmail.com To: David Buchan pdbuc...@yahoo.com Cc: David Nečas y...@physics.muni.cz; gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 3:59 PM Subject: Re: Valgrind is grinding my gears No, as soon as you use GObject derived types (or call g_types_init/gtk_init) the class structures for all your gobject derived classes will be created _once_. This unevitable, but nothing to worry about (same for GThread and friends), just be aware of their existance (and/or suppress them in the valgrind output). This has nothing to do with G_SLICE=always-malloc, it actually just reduces the false-positives of valgrind as g_malloc internally allocates big chunks of memory and feeds them as chunks to g_malloc calls, which in turn valgrind sometimes counts as possibly lost and clutters the output. Bernhard On Tue, Nov 5, 2013 at 9:54 PM, David Buchan pdbuc...@yahoo.com wrote: Hi Dave, GObject type registration machinery is, under normal circumstances, only ever used tocreate structures that will exist during the entire program lifetime. Does that mean that if I just use straight old malloc() instead of g_slice(), most of the errors would go away? I gather that's essentially what using G_SLICE=always-malloc would do. I can't try this out until late tonight, unfortunately. From: David Nečas y...@physics.muni.cz To: David Buchan pdbuc...@yahoo.com Cc: gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 2:51 PM Subject: Re: Valgrind is grinding my gears On Tue, Nov 05, 2013 at 09:47:13AM -0800, David Buchan wrote: But when I invoke Valgrind at runtime, I get a lot of errors which I can't make any sense of. I have grabbed a small sample of them here: http://pdbuchan.com/valgrind.txt I don't like ignoring errors and warnings, but I don't know what to do with these. Has anybody else come across these types of Valgrind notifications? Yes, everyone. You must understand that all the GObject type registration machinery is, under normal circumstances, only ever used to create structures that will exist during the entire program lifetime. So although things such as class reference leaks can exists, eveything inside g_type_class_ref() should be ignorable – and you can clearly see from the log that these allocations happen once, not a thousand times. The same for g_thread_init(), gtk_init(), etc. Create a suppression file or google one... Regards, Yeti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Valgrind is grinding my gears
I have a valgrind file here I use for my large gtk2 program: http://www.vips.ecs.soton.ac.uk/development/nip2a.supp I get clean runs with this file. Run with something like: export G_DEBUG=gc-friendly export G_SLICE=always-malloc valgrind --suppressions=/home/john/nip2.supp \ --leak-check=yes \ nip2 ... nip2-vg.log 21 I've not used it for a while, it might need a bit of updating. On 5 November 2013 21:01, David Buchan pdbuc...@yahoo.com wrote: Aaaah. I see. Thanks guys. From: Bernhard Schuster schuster.bernh...@gmail.com To: David Buchan pdbuc...@yahoo.com Cc: David Nečas y...@physics.muni.cz; gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 3:59 PM Subject: Re: Valgrind is grinding my gears No, as soon as you use GObject derived types (or call g_types_init/gtk_init) the class structures for all your gobject derived classes will be created _once_. This unevitable, but nothing to worry about (same for GThread and friends), just be aware of their existance (and/or suppress them in the valgrind output). This has nothing to do with G_SLICE=always-malloc, it actually just reduces the false-positives of valgrind as g_malloc internally allocates big chunks of memory and feeds them as chunks to g_malloc calls, which in turn valgrind sometimes counts as possibly lost and clutters the output. Bernhard On Tue, Nov 5, 2013 at 9:54 PM, David Buchan pdbuc...@yahoo.com wrote: Hi Dave, GObject type registration machinery is, under normal circumstances, only ever used tocreate structures that will exist during the entire program lifetime. Does that mean that if I just use straight old malloc() instead of g_slice(), most of the errors would go away? I gather that's essentially what using G_SLICE=always-malloc would do. I can't try this out until late tonight, unfortunately. From: David Nečas y...@physics.muni.cz To: David Buchan pdbuc...@yahoo.com Cc: gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 2:51 PM Subject: Re: Valgrind is grinding my gears On Tue, Nov 05, 2013 at 09:47:13AM -0800, David Buchan wrote: But when I invoke Valgrind at runtime, I get a lot of errors which I can't make any sense of. I have grabbed a small sample of them here: http://pdbuchan.com/valgrind.txt I don't like ignoring errors and warnings, but I don't know what to do with these. Has anybody else come across these types of Valgrind notifications? Yes, everyone. You must understand that all the GObject type registration machinery is, under normal circumstances, only ever used to create structures that will exist during the entire program lifetime. So although things such as class reference leaks can exists, eveything inside g_type_class_ref() should be ignorable – and you can clearly see from the log that these allocations happen once, not a thousand times. The same for g_thread_init(), gtk_init(), etc. Create a suppression file or google one... Regards, Yeti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Valgrind is grinding my gears
Great! Thanks! Dave From: jcup...@gmail.com jcup...@gmail.com To: David Buchan pdbuc...@yahoo.com Cc: gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 4:56 PM Subject: Re: Valgrind is grinding my gears I have a valgrind file here I use for my large gtk2 program: http://www.vips.ecs.soton.ac.uk/development/nip2a.supp I get clean runs with this file. Run with something like: export G_DEBUG=gc-friendly export G_SLICE=always-malloc valgrind --suppressions=/home/john/nip2.supp \ --leak-check=yes \ nip2 ... nip2-vg.log 21 I've not used it for a while, it might need a bit of updating. On 5 November 2013 21:01, David Buchan pdbuc...@yahoo.com wrote: Aaaah. I see. Thanks guys. From: Bernhard Schuster schuster.bernh...@gmail.com To: David Buchan pdbuc...@yahoo.com Cc: David Nečas y...@physics.muni.cz; gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 3:59 PM Subject: Re: Valgrind is grinding my gears No, as soon as you use GObject derived types (or call g_types_init/gtk_init) the class structures for all your gobject derived classes will be created _once_. This unevitable, but nothing to worry about (same for GThread and friends), just be aware of their existance (and/or suppress them in the valgrind output). This has nothing to do with G_SLICE=always-malloc, it actually just reduces the false-positives of valgrind as g_malloc internally allocates big chunks of memory and feeds them as chunks to g_malloc calls, which in turn valgrind sometimes counts as possibly lost and clutters the output. Bernhard On Tue, Nov 5, 2013 at 9:54 PM, David Buchan pdbuc...@yahoo.com wrote: Hi Dave, GObject type registration machinery is, under normal circumstances, only ever used tocreate structures that will exist during the entire program lifetime. Does that mean that if I just use straight old malloc() instead of g_slice(), most of the errors would go away? I gather that's essentially what using G_SLICE=always-malloc would do. I can't try this out until late tonight, unfortunately. From: David Nečas y...@physics.muni.cz To: David Buchan pdbuc...@yahoo.com Cc: gtk-app-devel-list list gtk-app-devel-list@gnome.org Sent: Tuesday, November 5, 2013 2:51 PM Subject: Re: Valgrind is grinding my gears On Tue, Nov 05, 2013 at 09:47:13AM -0800, David Buchan wrote: But when I invoke Valgrind at runtime, I get a lot of errors which I can't make any sense of. I have grabbed a small sample of them here: http://pdbuchan.com/valgrind.txt I don't like ignoring errors and warnings, but I don't know what to do with these. Has anybody else come across these types of Valgrind notifications? Yes, everyone. You must understand that all the GObject type registration machinery is, under normal circumstances, only ever used to create structures that will exist during the entire program lifetime. So although things such as class reference leaks can exists, eveything inside g_type_class_ref() should be ignorable – and you can clearly see from the log that these allocations happen once, not a thousand times. The same for g_thread_init(), gtk_init(), etc. Create a suppression file or google one... Regards, Yeti ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: changing font, color, size, etc. in a GtkEntry
Thanks Michael, This is indeed the sort of solutions I've tried. However, as I've mentioned in my original post, functions like pango_font_description_from_string, etc. are not recognized in my coding environment (while I can define pointer to things like PangoFontDescription without problem). This looks weird to me. Is there some specific libraries or headers I have to load or declare before? Or are these fonctions available on GTK 3 only, and - if yes - what can I do, then? (I am coding on Windows with CodeBlocks 12.11 and GTK 2.24.0). Any help on this will be welcomed! Cheers, Eric. Michael Cronenworth wrote, On 05/11/2013 17:15, Eric Wajnberg wrote: I simply want to modify the font, color, size, etc. of the characters entered while they are typed in a GtkEntry. I am coding with GTK 2.24.0. Looking around on the web, I found several possible functions to do that, some of them seem to be specific to GTK3, however. I found - and tried to play with - things like: gtk_entry_set_attributes gtk_widget_modify_text gtk_widget_modify_base gtk_widget_modify_font gtk_widget_create_pango_layout gtk_widget_create_pango_context Some of them lead me to define and to argument a pointer to a struct of type PangoFontDescription or GtkStyle. Hence, it seems that I also need to use function like, e.g., pango_font_description_set_weight, etc., but I'm not fully sure about this. I remained unable to sort this out, and some of these functions are even not recognized in my coding environment.. You are close. You need to use gtk_widget_modify_font(). You pass in a font description created by: PangoFontDescription *fontDesc = pango_font_description_from_string( monospace 10 ); This would set the entry text to a monospace-type font with 10 point size. Don't forget to call pango_font_description_free() afterwards. If you wish to change font while typing you need to connect to the key-press-event signal on the GtkEntry widget and handle key presses that way. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list -- ~~ Eric Wajnberg Associated Professor at the University of Montreal (Quebec, Canada) I.N.R.A. 400 Route des Chappes, BP 167, 06903 Sophia Antipolis Cedex, France Tel: (33-0) 4.92.38.64.47 Fax: (33-0) 4.92.38.65.57 e-mail: wajnb...@sophia.inra.fr Web page: http://www.sophia.inra.fr/perso/wajnberg/ Editor-in-Chief of BioControl, Published by Springer. ~~ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list