location of widgets in a gtk_table

2013-11-20 Thread Eric Wajnberg
 to the window */
 /* gtk_container_add (GTK_CONTAINER (win), boxv2); */
gtk_container_add (GTK_CONTAINER (win), pTable);
 /* Enter the main loop */
 gtk_widget_show_all (win);
 gtk_main();
 return 0;

Hence, if the main windows only contains the Gtk_table, then everything 
works fine.


This looks really weird to me.  How come locations of widgets within a 
Gtk_table can be modified if such a Gtk_table is included in a box with 
other widgets??


I really do not have any idea, and any help on this will be more than 
welcomed!


Thanks is all cases for your time!

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

2013-11-07 Thread Eric Wajnberg

Thanks Michael for your answer.

The compilation is ok. No error message. This is the linker that 
reports, e.g.:


undefined reference to `pango_font_description_from_string'

The instruction I use to compile is (which is launched by CodeBlocks):

mingw32-g++.exe -LC:\Program Files (x86)\CodeBlocks\gtk\lib  -o 
bin\Release\entry2.exe obj\Release\main.o   -s  -lgtk-win32-2.0 
-lgobject-2.0 -lglib-2.0  -mwindows


So, all needed libraries are here, I think.

Of course, my code starts with:

#include pango/pango.h

So, there are apparently - in my view - no header or library missing.

In the meantime, I tried to do this on another computer at work. I got 
the same message. No way to have these pango functions recognized.


Is there something obvious I am missing?

Any help on this is welcomed!

Cheers, Eric.


Michael Cronenworth wrote, On 06/11/2013 15:22,

Eric Wajnberg wrote:

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).


Pango is not tied to a GTK version. You can use GTK 2 for this.

What do you mean not recognized? The compiler reports an undefined 
function? The linker reports an undefined function? The function has 
been around for a very long time (at least since Pango 1.10) so this 
is not something new. It appears your development environment is 
missing headers and/or libraries.


Something to consider: I cross-compile Windows binaries under Fedora 
using MinGW packages. You may find this a better alternative as 
packages will be up-to-date (GTK 2.24.22), packaged properly, and find 
some support from the packagers and upstream in case something like 
this goes wrong.

___
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


Re: changing font, color, size, etc. in a GtkEntry

2013-11-07 Thread Eric Wajnberg

Ok, I finally find out what was the problem..

I had to add the library pango-1.0.lib in the compiling options.

Strange that this was not included initially when building a project 
with gtk+.


P.. I spent days on this...

Thanks is all cases for your help on this.

Cheers, Eric.


Eric Wajnberg wrote, On 07/11/2013 11:48,

Thanks Michael for your answer.

The compilation is ok. No error message. This is the linker that 
reports, e.g.:


undefined reference to `pango_font_description_from_string'

The instruction I use to compile is (which is launched by CodeBlocks):

mingw32-g++.exe -LC:\Program Files (x86)\CodeBlocks\gtk\lib  -o 
bin\Release\entry2.exe obj\Release\main.o   -s  -lgtk-win32-2.0 
-lgobject-2.0 -lglib-2.0  -mwindows


So, all needed libraries are here, I think.

Of course, my code starts with:

#include pango/pango.h

So, there are apparently - in my view - no header or library missing.

In the meantime, I tried to do this on another computer at work. I got 
the same message. No way to have these pango functions recognized.


Is there something obvious I am missing?

Any help on this is welcomed!

Cheers, Eric.


Michael Cronenworth wrote, On 06/11/2013 15:22,

Eric Wajnberg wrote:

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).


Pango is not tied to a GTK version. You can use GTK 2 for this.

What do you mean not recognized? The compiler reports an undefined 
function? The linker reports an undefined function? The function has 
been around for a very long time (at least since Pango 1.10) so this 
is not something new. It appears your development environment is 
missing headers and/or libraries.


Something to consider: I cross-compile Windows binaries under Fedora 
using MinGW packages. You may find this a better alternative as 
packages will be up-to-date (GTK 2.24.22), packaged properly, and 
find some support from the packagers and upstream in case something 
like this goes wrong.

___
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


changing font, color, size, etc. in a GtkEntry

2013-11-05 Thread Eric Wajnberg

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

2013-11-05 Thread Eric Wajnberg

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


Re: updating labels when a key is stroked

2013-08-09 Thread Eric Wajnberg

Ok, thanks!

I'm just plain stupid. I indeed just have to collect a key_press_event 
event and that's it!


Sorry for disturbing the list with such a basic question (I am still 
learning how to use gtk)..


Cheers to all,

Eric.

Kang Hu wrote, On 09/08/2013 09:39,

all you need is an event filter.

remove the 'g_timeout_add' line with the following code.
0. get the gdk window of the created top-level gtk window.
GdkWindow 
https://developer.gnome.org/gdk2/stable/gdk3-Windows.html#GdkWindow* 
gtk_widget_get_window 
https://developer.gnome.org/gtk3/3.8/GtkWidget.html#gtk-widget-get-window(/|GtkWidget 
https://developer.gnome.org/gtk3/3.8/GtkWidget.html *widget|/);


GdkWindow* gdkwindow = gtk_widget_get_window (pWindow);

1. add event mask you're interested in
voidgdk_window_set_events 
https://developer.gnome.org/gdk3/3.8/gdk3-Windows.html#gdk-window-set-events(/|GdkWindow 
https://developer.gnome.org/gdk3/3.8/gdk3-Windows.html#GdkWindow 
*window|/,/|GdkEventMask 
https://developer.gnome.org/gdk3/3.8/gdk3-Events.html#GdkEventMask 
event_mask|/);


gdk_window_set_events (gdkwindow, GDK_KEY_PRESS_MASK);

2. register an event filter
voidgdk_window_add_filter (/|GdkWindow 
https://developer.gnome.org/gdk3/3.8/gdk3-Windows.html#GdkWindow 
*window|/,/|GdkFilterFunc 
https://developer.gnome.org/gdk3/3.8/gdk3-Windows.html#GdkFilterFunc 
function|/,/|gpointer 
https://developer.gnome.org/glib/unstable/glib-Basic-Types.html#gpointer 
data|/);

   gdk_window_add_filter (gdkwindow, key_press_filter, pWindow);

3. write the filter function.

GdkFilterReturn 
https://developer.gnome.org/gdk3/3.8/gdk3-Windows.html#GdkFilterReturn (*GdkFilterFunc) 
(/|GdkXEvent 
https://developer.gnome.org/gdk3/3.8/gdk3-Windows.html#GdkXEvent *xevent|/,/|GdkEvent 
https://developer.gnome.org/gdk3/3.8/gdk3-Event-Structures.html#GdkEvent *event|/,/|gpointer 
https://developer.gnome.org/glib/unstable/glib-Basic-Types.html#gpointer data|/); 



   GdkFilterReturn key_press_filter (GdkXEvent* xevent, GdkEvent* 
event, gpointer data)

   {
 // how to process key press events.
   }


On Wed, Aug 7, 2013 at 8:48 PM, Eric Wajnberg 
eric.wajnb...@sophia.inra.fr mailto:eric.wajnb...@sophia.inra.fr 
wrote:


Hi there,

I need to develop a gtk code in which a label is changed each time
a key is stroked on the keyboad. I thus use g_timeout_add() to
launch on a regular basis a function that listens to key strokes.
Within this function, I used a combination of kbhit()/getch() to
collected the stroken keys (because I do not want the user to hit
the return key all the time) and update the label accordingly.
The following code is just a try, and seems ok:

#include stdlib.h
#include stdio.h
#include conio.h
#include gtk/gtk.h

int key=0;
char string[500];

int main(int argc, char **argv)
{
/* declaration of widgets */
GtkWidget *pWindow; /*main windows */
GtkWidget *pLabel; /* a label */

void OnDestroy(GtkWidget *pWidget, gpointer pData); /*
function call back destroy */
gboolean update(gpointer pData); /* function called at regular
intervals */

/* Initialisation of GTK+ */
gtk_init(argc, argv);

/* creation of the main window */
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);

/* parameters of the window */
gtk_window_set_position(GTK_WINDOW(pWindow), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(pWindow), 300, 100);
gtk_window_set_title(GTK_WINDOW(pWindow), testing key input);

/* creation of the label */
(void)sprintf(string,%d,key);
pLabel=gtk_label_new(string);

/* adding the label to the window */
gtk_container_add(GTK_CONTAINER(pWindow), pLabel);

/* signal connexion */
g_signal_connect(G_OBJECT(pWindow), destroy,
G_CALLBACK(OnDestroy), NULL);

/* function called at regular intervals .. */
g_timeout_add((guint)1, update,(gpointer *)pLabel);

/* showing the window */
gtk_widget_show_all(pWindow);

/* starting the loop */
gtk_main();

return EXIT_SUCCESS;
}

gboolean update(gpointer pData)
{
/* updating the label */
if (kbhit())
{
key=getch();
(void)sprintf(string, %d,key);
gtk_label_set_label(GTK_LABEL(pData), string);
}
return TRUE;
}

void OnDestroy(GtkWidget *pWidget, gpointer pData)
{
/* stopping the loop */
gtk_main_quit();
}



The point is that this is actually not working correctly, because
the keystrokes are collected on a console that is not there! In
other words, the code above works well in debug mode (e.g., on
Code::Blocks) when a debugging console is available, but not in
release mode running without a console.

My question is thus: is there a way to listen to key

updating labels when a key is stroked

2013-08-08 Thread Eric Wajnberg

Hi there,

I need to develop a gtk code in which a label is changed each time a key 
is stroked on the keyboad. I thus use g_timeout_add() to launch on a 
regular basis a function that listens to key strokes. Within this 
function, I used a combination of kbhit()/getch() to collected the 
stroken keys (because I do not want the user to hit the return key all 
the time) and update the label accordingly. The following code is just a 
try, and seems ok:


#include stdlib.h
#include stdio.h
#include conio.h
#include gtk/gtk.h

int key=0;
char string[500];

int main(int argc, char **argv)
{
/* declaration of widgets */
GtkWidget *pWindow; /*main windows */
GtkWidget *pLabel; /* a label */

void OnDestroy(GtkWidget *pWidget, gpointer pData); /* function 
call back destroy */
gboolean update(gpointer pData); /* function called at regular 
intervals */


/* Initialisation of GTK+ */
gtk_init(argc, argv);

/* creation of the main window */
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);

/* parameters of the window */
gtk_window_set_position(GTK_WINDOW(pWindow), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(pWindow), 300, 100);
gtk_window_set_title(GTK_WINDOW(pWindow), testing key input);

/* creation of the label */
(void)sprintf(string,%d,key);
pLabel=gtk_label_new(string);

/* adding the label to the window */
gtk_container_add(GTK_CONTAINER(pWindow), pLabel);

/* signal connexion */
g_signal_connect(G_OBJECT(pWindow), destroy, 
G_CALLBACK(OnDestroy), NULL);


/* function called at regular intervals .. */
g_timeout_add((guint)1, update,(gpointer *)pLabel);

/* showing the window */
gtk_widget_show_all(pWindow);

/* starting the loop */
gtk_main();

return EXIT_SUCCESS;
}

gboolean update(gpointer pData)
{
/* updating the label */
if (kbhit())
{
key=getch();
(void)sprintf(string, %d,key);
gtk_label_set_label(GTK_LABEL(pData), string);
}
return TRUE;
}

void OnDestroy(GtkWidget *pWidget, gpointer pData)
{
/* stopping the loop */
gtk_main_quit();
}



The point is that this is actually not working correctly, because the 
keystrokes are collected on a console that is not there! In other words, 
the code above works well in debug mode (e.g., on Code::Blocks) when a 
debugging console is available, but not in release mode running 
without a console.


My question is thus: is there a way to listen to key stroked on the 
keyboard within a gtk application?


Thanks for any help on 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


code crash after 25-30 min only!

2013-04-19 Thread Eric Wajnberg

Hi there,

I just remain unable to debug this code. Actually, it runs very well but 
crashes after 30-35 minutes only.


This is a stopwatch-type app. However, I actually need to refresh 
things on a continuous basis. Hence, a g_timeout_add_seconds() is 
**not** what I need. The idea of a stopwatch is just a way for me to 
learn and practice.


The code that I have is more or less this one:

#include stdlib.h
#include gtk/gtk.h
#include strings.h

int flag_depart=1;
char format_sortie[100];
typedef struct
{
GtkWidget *widget1;
GTimer *widget2;
} MyStruct; /* a struct to pass several arguments to an callback */

int main(int argc, char **argv)
{
/* declaration of widgets */
[...]
GtkWidget *pLabel; /* a label */
GTimer *timer; /* a timer */
gchar* sUtf8;  /* to format a char string */
[...]
MyStruct struct_tempo; /* a struct to pass several arguments to an 
callback */

[...]
gboolean OnExpose(GtkWidget *pWidget, GdkEvent *event, gpointer 
pData); /* function callback expose-event */

[...]
/* creation of the label */
pLabel=gtk_label_new(NULL);
(void)sprintf(format_sortie, span font_desc=\25\b00 : 00 : 
00/b/span);

sUtf8 = g_locale_to_utf8(format_sortie, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(pLabel), sUtf8);
g_free(sUtf8);
/* we put the label in the struct */
struct_tempo.widget1=pLabel;

/* creation of the timer */
timer=g_timer_new();
/* we put the timer in the struct */
struct_tempo.widget2=timer;

/* Connexion of signals */
g_signal_connect(G_OBJECT(pWindow), expose-event, 
G_CALLBACK(OnExpose), (gpointer )struct_tempo);


[...]

return EXIT_SUCCESS;
}
gboolean OnExpose(GtkWidget *pWidget, GdkEvent *event, gpointer pData)
{
/* updating the label */
char tempo[1000],h[3],m[3],s[3];
int heures=0, minutes=0;
GTimeSpan secondes=0;
gchar* sUtf8;
MyStruct *struct_tempo2;
struct_tempo2= (MyStruct *)pData;
float convertir(GTimeSpan *secondes, int *minutes, int *heures);
if (flag_depart)
{
secondes=(GTimeSpan)g_timer_elapsed(struct_tempo2-widget2, NULL);
convertir(secondes, minutes, heures);
if (secondes9)
(void)sprintf(s, %d,secondes);
else
(void)sprintf(s, 0%d,secondes);
if (minutes9)
(void)sprintf(m, %d,minutes);
else
(void)sprintf(m, 0%d,minutes);
if (heures9)
(void)sprintf(h, %d,heures);
else
(void)sprintf(h, 0%d,heures);
(void)sprintf(tempo, span font_desc=\25\b%s : %s : 
%s/b/span,h, m, s);

sUtf8 = g_locale_to_utf8(tempo, -1, NULL, NULL, NULL);
gtk_label_set_markup(GTK_LABEL(struct_tempo2-widget1), tempo);
}
g_free(sUtf8);
return FALSE;
}
float convertir(GTimeSpan *secondes, int *minutes, int * heures)
{
/* convert seconds into hours, minuts and seconds */
while (*secondes59)
{
*minutes=*minutes+1;
*secondes=*secondes-60;
}
while (*minutes59)
{
*heures=*heures+1;
*minutes=*minutes-60;
}
}

This codes works well but crashes avec about 30-35 minutes. I code in 
Windows 7 with CodeBlock. I've tried to use a debugger, but I get a:


Segmentation fault.
In ntdll!LdrWx86FormatVirtualImage () (C:\Windows\system32\ntdll.dll)

as soon as the gtk_main() is launched. I have really no idea about how I 
can solve this now.


Any help will be welcomed!!

Thanks in advance for 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