[Glade-users] Glade widget updating problem.
- From: email at micahcarrick.com (Micah Carrick)
- Subject: [Glade-users] Glade widget updating problem.
- Date: Thu, 28 Dec 2006 16:18:17 -0800
You could use the callback for the button's "clicked" event to create a
g_timeout with the 1s interval. The function handling the g_timeout
could contain update your GtkRange and then call:
while (gtk_events_pending ()) gtk_main_iteration ();
This will ensure that the GUI is updated each time. When you're done
incrementing the range, you can return FALSE from the g_timout function
to destroy the timeout.
- Micah Carrick
http://www.micahcarrick.com | http://www.gtkforums.com
Koen Lekkerkerker wrote:
Hi everybody, I have a problem (again) with glade. Or actually GTK2. The
problem is that my GUI (or better GUI-elements) isn't updated frequently
enough (or at least, that is my conclusion). I my case it is like this:
I have a button. When i click it i want a scale to be set to a value 0,
a second later it needs to be 1, another second later 2, and so one
untill 10. When I make a GUI with code that fits this, it will work. But
the scale goes from 0 to 1 to 2 to 4 to 5 to 7 to 8 to 10. These double
steps dure 2 seconds (as logical). I found out that de widgets
themselves are updated directly (by using g_print(x); in my terminal)
but that their graphical appearance in the GUI isn't updated frequently
enough. Point is that I wan't the GUI to be synced with the value of the
widgets. I have this problem using glade3 and libglade2. I had the exact
same problem with glade2 using the code of it's built-in code generator.
Can anybody please help me with this? The code of my app is below. But
first another little question: is it possible to make a complete
compilation of a libglade/gtk program with the GUI built in? So that it
doesn't need the libglade library and the xml-file to run?
Thanks a lot in advance!
Koen
Here is my terminal command:
cc -o testprogram gl3test.c `pkg-config --cflags --libs
libglade-2.0` -export-dynamic
And here is my c file (gl3test.c):
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gtk/gtk.h>
#include <stdio.h>
#include <glade/glade.h>
static GtkWidget *label;
static GtkWidget *scale;
void
on_button1_clicked (GtkButton *button,
gpointer
user_data)
{
int x;
char test[3];
gtk_label_set_text(GTK_LABEL(label),"goedzo");
for( x=0;x<=10;x++){
gtk_range_set_value(GTK_RANGE(scale),x);
usleep(1000000);
sprintf(test,"%d",x);
gtk_label_set_text(GTK_LABEL(label),test);
g_print("%d\n",x);
}
gtk_range_set_value(GTK_RANGE(scale),0);
gtk_label_set_text(GTK_LABEL(label),"klik nog een keer");
g_print("klaar");
}
int main(int argc, char *argv[]) {
GladeXML *xml;
gtk_init(&argc, &argv);
/* load the interface */
xml = glade_xml_new("gl3test.glade", NULL, NULL);
scale = glade_xml_get_widget(xml, "hscale1");
label = glade_xml_get_widget(xml, "label1");
/* connect the signals in the interface */
glade_xml_signal_autoconnect(xml);
/* start the event loop */
gtk_main();
return 0;
}
and this is my xml-file (gl3test.glade):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.0.3 on Mon Dec 25 22:08:52 2006 by
koen at koen-desktop-->
<glade-interface>
<widget class="GtkWindow" id="window1">
<property name="width_request">200</property>
<property name="height_request">599</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="title" translatable="yes">testje</property>
<property
name="window_position">GTK_WIN_POS_CENTER</property>
<property name="default_width">199</property>
<property name="default_height">600</property>
<property name="icon">itunes-blue150.jpg</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<widget class="GtkHScale" id="hscale1">
<property name="visible">True</property>
<property name="adjustment">2 0 10 1 0 0</property>
<property name="value_pos">GTK_POS_LEFT</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="button1">
<property name="visible">True</property>
<property name="label"
translatable="yes">button</property>
<signal name="clicked"
handler="on_button1_clicked"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label"
translatable="yes">tekst</property>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
_______________________________________________
Glade-users maillist - Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]