Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » GTK+
  • » changing the label according to time [RSS Feed]

#1 March 7, 2008 10:28:10

amit b.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

changing the label according to time


Hi All ,
I am doing a project in it I want to show the lyrics of a song which
is playing in the background .I use gtk label to show that lyrics .I use the
gtk window to show the lyrics on it .I read a file in which I have that lyrics
and the time at which it come from the start of the play .I sleep for that
time I read the next line and display it on the window with the help of the
label .I test that the lyrics are coming in properly or not so I put printf
and verify that it read that lyrics according to that time .But when I try to
show that lyrics in label on the windows It do not change according to time .I
mean to say that it changes but not on the windows .I make 2 threads one for
playing the music and other for showing that lyrics .If I regularly move the
mouse cursor on the window then the lyrics changes accordingly .But if I stay
ideal do not move the mouse cursor on it it do not change the lyrics .I think
it do not refresh after that sleep time on its
own .
I do that like follows
label=gtk_label_new(lyrics_line);
gtk_widget_show(label);
gtk_fixed_put(GTK_FIXED(fixed1),label,150,470);
gtk_widget_set_size_request(label,450,30);
//gtk_misc_set_alignment(GTK_MISC(label),0,0.5);
font_desc = pango_font_description_from_string("sans 15");
gtk_widget_modify_font(label,font_desc);
pango_font_description_free(font_desc);
gdk_color_parse("#D5D8D4", &color);
gtk_widget_modify_fg(label,GTK_STATE_NORMAL,&color);
Sleep(time*100);
gtk_widget_hide(label);

I use a while loop to read it to the end of that file .I think I am able to
explain my problem .If there is any option that refresh the windows after that
sleep time I think the lyrics changes properly .the lyrics are changing If
there is any movement on the windows other wise it do not change .
So there is some refreshing happens when some movement on the windows .But u
can't move the mouse cursor every time .So please tell my there is some way to
refresh that windows Programeticaly .
Thanks in advance .


Regards
Amit Kumar Bag



---------------------------------
Get the freedom to save as many mails as you wish. Click here to know how._______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#2 March 7, 2008 15:24:31

Lindley M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

changing the label according to time


It looks to me like you're making gtk calls in *both* threads?

This is bad, and can result in strange behavior. Don't do it. Secondary threads
should only make gtk calls via functions called via g_idle_add().

In this case, you may not even need a second thread. Instead of a loop with a
sleep in it, consider just using g_timeout_add().

Also, you should not be constantly creating new labels and then hiding them.
*Either* gtk_widget_destroy() each one as you're done, or else just keep one
label and use gtk_label_set_text().Hi All ,
I am doing a project in it I want to show the lyrics of a song which
is playing in the background .I use gtk label to show that lyrics .I use the
gtk window to show the lyrics on it .I read a file in which I have that lyrics
and the time at which it come from the start of the play .I sleep for that
time I read the next line and display it on the window with the help of the
label .I test that the lyrics are coming in properly or not so I put printf
and verify that it read that lyrics according to that time .But when I try to
show that lyrics in label on the windows It do not change according to time .I
mean to say that it changes but not on the windows .I make 2 threads one for
playing the music and other for showing that lyrics .If I regularly move the
mouse cursor on the window then the lyrics changes accordingly .But if I stay
ideal do not move the mouse cursor on it it do not change the lyrics .I think
it do not refresh after that sleep time on its
own .
I do that like follows
label=gtk_label_new(lyrics_line);
gtk_widget_show(label);
gtk_fixed_put(GTK_FIXED(fixed1),label,150,470);
gtk_widget_set_size_request(label,450,30);
//gtk_misc_set_alignment(GTK_MISC(label),0,0.5);
font_desc = pango_font_description_from_string("sans 15");
gtk_widget_modify_font(label,font_desc);
pango_font_description_free(font_desc);
gdk_color_parse("#D5D8D4", &color);
gtk_widget_modify_fg(label,GTK_STATE_NORMAL,&color);
Sleep(time*100);
gtk_widget_hide(label);

I use a while loop to read it to the end of that file .I think I am able to
explain my problem .If there is any option that refresh the windows after that
sleep time I think the lyrics changes properly .the lyrics are changing If
there is any movement on the windows other wise it do not change .
So there is some refreshing happens when some movement on the windows .But u
can't move the mouse cursor every time .So please tell my there is some way to
refresh that windows Programeticaly .
Thanks in advance .


Regards
Amit Kumar Bag



---------------------------------
Get the freedom to save as many mails as you wish. Click here to know how._______________________________________________
gtk-list mailing list
gtk-l***@*nome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#3 March 11, 2008 14:26:58

cosmo p.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

changing the label according to time


Hi!

Am not sure if this could help you, but I had a similar problem and it was a
matter of threads... so take a look to the functions gtk_threads_enter() and
gtk_threads_leave(). If your code is being executed outside a gtk callback and
you use threads, then you should add gtk_threads_enter() at the begining of the
code you posted and gtk_threads_leave() at the end.

If that doesn't work... maybe there is some kind of "gtk_flush()" or something
like that? I am sorry, I am not an expert... but I hope this could help you.

Best regards.
Cosmo.


Date: Fri, 7 Mar 2008 10:24:13 -0500From: : Re: changing the
label according to timeTo: : All ,
I am doing a project in it I want to show the lyrics of a song which is
playing in the background .I use gtk label to show that lyrics .I use the gtk
window to show the lyrics on it .I read a file in which I have that lyrics and
the time at which it come from the start of the play .I sleep for that time
I read the next line and display it on the window with the help of the label
.I test that the lyrics are coming in properly or not so I put printf and
verify that it read that lyrics according to that time .But when I try to show
that lyrics in label on the windows It do not change according to time .I mean
to say that it changes but not on the windows .I make 2 threads one for playing
the music and other for showing that lyrics .If I regularly move the mouse
cursor on the window then the lyrics changes accordingly .But if I stay ideal
do not move the mouse cursor on it it do not change the lyrics .I think it do
not refresh after that sleep time on its own .I do that like follows
label=gtk_label_new(lyrics_line); gtk_widget_show(label);
gtk_fixed_put(GTK_FIXED(fixed1),label,150,470);
gtk_widget_set_size_request(label,450,30);
//gtk_misc_set_alignment(GTK_MISC(label),0,0.5); font_desc =
pango_font_description_from_string("sans 15");
gtk_widget_modify_font(label,font_desc);
pango_font_description_free(font_desc);
gdk_color_parse("#D5D8D4", &color);
gtk_widget_modify_fg(label,GTK_STATE_NORMAL,&color);
Sleep(time*100); gtk_widget_hide(label);I use a while loop to
read it to the end of that file .I think I am able to explain my problem .If
there is any option that refresh the windows after that sleep time I think the
lyrics changes properly .the lyrics are changing If there is any movement on
the windows other wise it do not change .So there is some refreshing happens
when some movement on the windows .But u can't move the mouse cursor every time
.So please tell my there is some way to refresh that windows Programeticaly .
Thanks in advance .
Regards Amit Kumar Bag


Get the freedom to save as many mails as you wish. Click here to know how.
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

  • Root
  • » GTK+
  • » changing the label according to time [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support