Commit ee3d1376 authored by GMT 1999 Tony Gale's avatar GMT 1999 Tony Gale Committed by Tony Gale
Browse files

threads example from Erik Mouw. New question on GtkLabel background

Sat Nov 13 22:30:29 GMT 1999 Tony Gale  <gale@gtk.org>

        * docs/gtkfaq.sgml: threads example from Erik Mouw.
        New question on GtkLabel background colors.

        * docs/gtk_tut.sgml:
          - Correct the example code callback
            function definitions.
          - Update the gtkdial example code, from Frans van Schaik.
          - Update setselection.c to current API.

        * examples/Makefile examples/*/*.c: Update to code
        listed in tutorial.
parent e4df9fa9
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
* docs/gtkfaq.sgml: threads example from Erik Mouw.
New question on GtkLabel background colors.
* docs/gtk_tut.sgml:
- Correct the example code callback
function definitions.
- Update the gtkdial example code, from Frans van Schaik.
- Update setselection.c to current API.
* examples/Makefile examples/*/*.c: Update to code
listed in tutorial.
1999-11-10 Tor Lillqvist <tml@iki.fi> 1999-11-10 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
......
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
* docs/gtkfaq.sgml: threads example from Erik Mouw.
New question on GtkLabel background colors.
* docs/gtk_tut.sgml:
- Correct the example code callback
function definitions.
- Update the gtkdial example code, from Frans van Schaik.
- Update setselection.c to current API.
* examples/Makefile examples/*/*.c: Update to code
listed in tutorial.
1999-11-10 Tor Lillqvist <tml@iki.fi> 1999-11-10 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
......
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
* docs/gtkfaq.sgml: threads example from Erik Mouw.
New question on GtkLabel background colors.
* docs/gtk_tut.sgml:
- Correct the example code callback
function definitions.
- Update the gtkdial example code, from Frans van Schaik.
- Update setselection.c to current API.
* examples/Makefile examples/*/*.c: Update to code
listed in tutorial.
1999-11-10 Tor Lillqvist <tml@iki.fi> 1999-11-10 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
......
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
* docs/gtkfaq.sgml: threads example from Erik Mouw.
New question on GtkLabel background colors.
* docs/gtk_tut.sgml:
- Correct the example code callback
function definitions.
- Update the gtkdial example code, from Frans van Schaik.
- Update setselection.c to current API.
* examples/Makefile examples/*/*.c: Update to code
listed in tutorial.
1999-11-10 Tor Lillqvist <tml@iki.fi> 1999-11-10 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
......
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
* docs/gtkfaq.sgml: threads example from Erik Mouw.
New question on GtkLabel background colors.
* docs/gtk_tut.sgml:
- Correct the example code callback
function definitions.
- Update the gtkdial example code, from Frans van Schaik.
- Update setselection.c to current API.
* examples/Makefile examples/*/*.c: Update to code
listed in tutorial.
1999-11-10 Tor Lillqvist <tml@iki.fi> 1999-11-10 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
......
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
* docs/gtkfaq.sgml: threads example from Erik Mouw.
New question on GtkLabel background colors.
* docs/gtk_tut.sgml:
- Correct the example code callback
function definitions.
- Update the gtkdial example code, from Frans van Schaik.
- Update setselection.c to current API.
* examples/Makefile examples/*/*.c: Update to code
listed in tutorial.
1999-11-10 Tor Lillqvist <tml@iki.fi> 1999-11-10 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
......
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org>
* docs/gtkfaq.sgml: threads example from Erik Mouw.
New question on GtkLabel background colors.
* docs/gtk_tut.sgml:
- Correct the example code callback
function definitions.
- Update the gtkdial example code, from Frans van Schaik.
- Update setselection.c to current API.
* examples/Makefile examples/*/*.c: Update to code
listed in tutorial.
1999-11-10 Tor Lillqvist <tml@iki.fi> 1999-11-10 Tor Lillqvist <tml@iki.fi>
* gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode * gdk/win32/gdkfont-win32.c: Fix a couple of bugs. The Unicode
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<!-- NOTE: Use only one author tag, otherwise sgml2txt barfs - TRG --> <!-- NOTE: Use only one author tag, otherwise sgml2txt barfs - TRG -->
<author>Tony Gale, Shawn T. Amundson, Emmanuel Deloget, Nathan Froyd <author>Tony Gale, Shawn T. Amundson, Emmanuel Deloget, Nathan Froyd
<date>October 30th 1999 <date>November 9th 1999
<abstract> This document is intended to answer questions that are likely to be <abstract> This document is intended to answer questions that are likely to be
frequently asked by programmers using GTK+ or people who are just looking at frequently asked by programmers using GTK+ or people who are just looking at
...@@ -950,6 +950,149 @@ are made outside of the GTK+ lock. So, within a signal ...@@ -950,6 +950,149 @@ are made outside of the GTK+ lock. So, within a signal
handler you do not need to call gdk_threads_enter(), but handler you do not need to call gdk_threads_enter(), but
within the other types of callbacks, you do. within the other types of callbacks, you do.
Erik Mouw contributed the following code example to illustrate how to
use threads within GTK+ programs.
<tscreen><verb>
/*-------------------------------------------------------------------------
* Filename: gtk-thread.c
* Version: 0.99.1
* Copyright: Copyright (C) 1999, Erik Mouw
* Author: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
* Description: GTK threads example.
* Created at: Sun Oct 17 21:27:09 1999
* Modified by: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
* Modified at: Sun Oct 24 17:21:41 1999
*-----------------------------------------------------------------------*/
/*
* Compile with:
*
* cc -o gtk-thread gtk-thread.c `gtk-config --cflags --libs gthread`
*
* Thanks to Sebastian Wilhelmi and Owen Taylor for pointing out some
* bugs.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <pthread.h>
#define YES_IT_IS (1)
#define NO_IT_IS_NOT (0)
typedef struct
{
GtkWidget *label;
int what;
} yes_or_no_args;
G_LOCK_DEFINE_STATIC (yes_or_no);
static volatile int yes_or_no = YES_IT_IS;
void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
void *argument_thread(void *args)
{
yes_or_no_args *data = (yes_or_no_args *)args;
gboolean say_something;
for(;;)
{
/* sleep a while */
sleep(rand() / (RAND_MAX / 3) + 1);
/* lock the yes_or_no_variable */
G_LOCK(yes_or_no);
/* do we have to say something? */
say_something = (yes_or_no != data->what);
if(say_something)
{
/* set the variable */
yes_or_no = data->what;
}
/* Unlock the yes_or_no variable */
G_UNLOCK(yes_or_no);
if(say_something)
{
/* get GTK thread lock */
gdk_threads_enter();
/* set label text */
if(data->what == YES_IT_IS)
gtk_label_set_text(GTK_LABEL(data->label), "O yes, it is!");
else
gtk_label_set_text(GTK_LABEL(data->label), "O no, it isn't!");
/* release GTK thread lock */
gdk_threads_leave();
}
}
return(NULL);
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *label;
yes_or_no_args yes_args, no_args;
pthread_t no_tid, yes_tid;
/* init threads */
g_thread_init(NULL);
/* init gtk */
gtk_init(&amp;argc, &amp;argv);
/* init random number generator */
srand((unsigned int)time(NULL));
/* create a window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC(destroy), NULL);
gtk_container_set_border_width(GTK_CONTAINER (window), 10);
/* create a label */
label = gtk_label_new("And now for something completely different ...");
gtk_container_add(GTK_CONTAINER(window), label);
/* show everything */
gtk_widget_show(label);
gtk_widget_show (window);
/* create the threads */
yes_args.label = label;
yes_args.what = YES_IT_IS;
pthread_create(&amp;yes_tid, NULL, argument_thread, &amp;yes_args);
no_args.label = label;
no_args.what = NO_IT_IS_NOT;
pthread_create(&amp;no_tid, NULL, argument_thread, &amp;no_args);
/* enter the GTK main loop */
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
return(0);
}
</verb></tscreen>
<!-- This is the old answer - TRG <!-- This is the old answer - TRG
...@@ -1002,7 +1145,7 @@ carefully. ...@@ -1002,7 +1145,7 @@ carefully.
Regardless, it's especially not a priority since relatively good Regardless, it's especially not a priority since relatively good
workarounds exist. --> workarounds exist. -->
<!-- ----------------------------------------------------------------- --> <!-- ----------------------------------------------------------------- -->
<sect1>Why do this strange 'x io error' occur when I <tt/fork()/ in my GTK+ app? <sect1>Why does this strange 'x io error' occur when I <tt/fork()/ in my GTK+ app?
<p> <p>
This is not really a GTK+ problem, and the problem is not related to <tt/fork()/ This is not really a GTK+ problem, and the problem is not related to <tt/fork()/
either. If the 'x io error' occurs then you probably use the <tt/exit()/ function either. If the 'x io error' occurs then you probably use the <tt/exit()/ function
...@@ -1014,7 +1157,7 @@ and the underlying X library really doesn't like this. ...@@ -1014,7 +1157,7 @@ and the underlying X library really doesn't like this.
The right function to use here is <tt/_exit()/. The right function to use here is <tt/_exit()/.
Erik Mouw gave the following code example to illustrate handling Erik Mouw contributed the following code example to illustrate handling
fork() and exit(). fork() and exit().
<tscreen><verb> <tscreen><verb>
...@@ -1833,6 +1976,17 @@ gtk_misc_set_alignment(GTK_MISK(label), 0.5f, 0.5f); ...@@ -1833,6 +1976,17 @@ gtk_misc_set_alignment(GTK_MISK(label), 0.5f, 0.5f);
gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f); gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f);
</verb></tscreen> </verb></tscreen>
<!-- ----------------------------------------------------------------- -->
<sect1>How do I set the background color of a GtkLabel widget?
<p>
The Gtklabel widget is one of a few GTK+ widgets that don't create
their own window to render themselves into. Instead, they draw
themselves directly onto their parents window.
This means that in order to set the background color for a GtkLabel
widget, you need to change the background color of its parent,
i.e. the object that you pack it into.
<!-- ----------------------------------------------------------------- --> <!-- ----------------------------------------------------------------- -->
<sect1>How do I set the color and font of a GtkLabel using a Resource File? <sect1>How do I set the color and font of a GtkLabel using a Resource File?
<p> <p>
......
This diff is collapsed.
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<!-- NOTE: Use only one author tag, otherwise sgml2txt barfs - TRG --> <!-- NOTE: Use only one author tag, otherwise sgml2txt barfs - TRG -->
<author>Tony Gale, Shawn T. Amundson, Emmanuel Deloget, Nathan Froyd <author>Tony Gale, Shawn T. Amundson, Emmanuel Deloget, Nathan Froyd
<date>October 30th 1999 <date>November 9th 1999
<abstract> This document is intended to answer questions that are likely to be <abstract> This document is intended to answer questions that are likely to be
frequently asked by programmers using GTK+ or people who are just looking at frequently asked by programmers using GTK+ or people who are just looking at
...@@ -950,6 +950,149 @@ are made outside of the GTK+ lock. So, within a signal ...@@ -950,6 +950,149 @@ are made outside of the GTK+ lock. So, within a signal
handler you do not need to call gdk_threads_enter(), but handler you do not need to call gdk_threads_enter(), but
within the other types of callbacks, you do. within the other types of callbacks, you do.
Erik Mouw contributed the following code example to illustrate how to
use threads within GTK+ programs.
<tscreen><verb>
/*-------------------------------------------------------------------------
* Filename: gtk-thread.c
* Version: 0.99.1
* Copyright: Copyright (C) 1999, Erik Mouw
* Author: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
* Description: GTK threads example.
* Created at: Sun Oct 17 21:27:09 1999
* Modified by: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
* Modified at: Sun Oct 24 17:21:41 1999
*-----------------------------------------------------------------------*/
/*
* Compile with:
*
* cc -o gtk-thread gtk-thread.c `gtk-config --cflags --libs gthread`
*
* Thanks to Sebastian Wilhelmi and Owen Taylor for pointing out some
* bugs.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <pthread.h>
#define YES_IT_IS (1)
#define NO_IT_IS_NOT (0)
typedef struct
{
GtkWidget *label;
int what;
} yes_or_no_args;
G_LOCK_DEFINE_STATIC (yes_or_no);
static volatile int yes_or_no = YES_IT_IS;
void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
void *argument_thread(void *args)
{
yes_or_no_args *data = (yes_or_no_args *)args;
gboolean say_something;
for(;;)
{
/* sleep a while */
sleep(rand() / (RAND_MAX / 3) + 1);
/* lock the yes_or_no_variable */
G_LOCK(yes_or_no);
/* do we have to say something? */
say_something = (yes_or_no != data->what);
if(say_something)
{
/* set the variable */
yes_or_no = data->what;
}
/* Unlock the yes_or_no variable */
G_UNLOCK(yes_or_no);
if(say_something)
{
/* get GTK thread lock */
gdk_threads_enter();
/* set label text */
if(data->what == YES_IT_IS)
gtk_label_set_text(GTK_LABEL(data->label), "O yes, it is!");
else
gtk_label_set_text(GTK_LABEL(data->label), "O no, it isn't!");
/* release GTK thread lock */
gdk_threads_leave();
}
}
return(NULL);
}
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *label;
yes_or_no_args yes_args, no_args;
pthread_t no_tid, yes_tid;
/* init threads */
g_thread_init(NULL);
/* init gtk */
gtk_init(&amp;argc, &amp;argv);
/* init random number generator */
srand((unsigned int)time(NULL));
/* create a window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC(destroy), NULL);
gtk_container_set_border_width(GTK_CONTAINER (window), 10);
/* create a label */
label = gtk_label_new("And now for something completely different ...");
gtk_container_add(GTK_CONTAINER(window), label);
/* show everything */
gtk_widget_show(label);
gtk_widget_show (window);
/* create the threads */
yes_args.label = label;
yes_args.what = YES_IT_IS;
pthread_create(&amp;yes_tid, NULL, argument_thread, &amp;yes_args);
no_args.label = label;
no_args.what = NO_IT_IS_NOT;
pthread_create(&amp;no_tid, NULL, argument_thread, &amp;no_args);
/* enter the GTK main loop */
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
return(0);
}
</verb></tscreen>
<!-- This is the old answer - TRG <!-- This is the old answer - TRG
...@@ -1002,7 +1145,7 @@ carefully. ...@@ -1002,7 +1145,7 @@ carefully.
Regardless, it's especially not a priority since relatively good Regardless, it's especially not a priority since relatively good
workarounds exist. --> workarounds exist. -->
<!-- ----------------------------------------------------------------- --> <!-- ----------------------------------------------------------------- -->
<sect1>Why do this strange 'x io error' occur when I <tt/fork()/ in my GTK+ app? <sect1>Why does this strange 'x io error' occur when I <tt/fork()/ in my GTK+ app?
<p> <p>
This is not really a GTK+ problem, and the problem is not related to <tt/fork()/ This is not really a GTK+ problem, and the problem is not related to <tt/fork()/
either. If the 'x io error' occurs then you probably use the <tt/exit()/ function either. If the 'x io error' occurs then you probably use the <tt/exit()/ function
...@@ -1014,7 +1157,7 @@ and the underlying X library really doesn't like this. ...@@ -1014,7 +1157,7 @@ and the underlying X library really doesn't like this.
The right function to use here is <tt/_exit()/. The right function to use here is <tt/_exit()/.
Erik Mouw gave the following code example to illustrate handling Erik Mouw contributed the following code example to illustrate handling
fork() and exit(). fork() and exit().
<tscreen><verb> <tscreen><verb>
...@@ -1833,6 +1976,17 @@ gtk_misc_set_alignment(GTK_MISK(label), 0.5f, 0.5f); ...@@ -1833,6 +1976,17 @@ gtk_misc_set_alignment(GTK_MISK(label), 0.5f, 0.5f);
gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f); gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f);
</verb></tscreen> </verb></tscreen>
<!-- ----------------------------------------------------------------- -->
<sect1>How do I set the background color of a GtkLabel widget?
<p>
The Gtklabel widget is one of a few GTK+ widgets that don't create
their own window to render themselves into. Instead, they draw
themselves directly onto their parents window.
This means that in order to set the background color for a GtkLabel
widget, you need to change the background color of its parent,
i.e. the object that you pack it into.
<!-- ----------------------------------------------------------------- --> <!-- ----------------------------------------------------------------- -->
<sect1>How do I set the color and font of a GtkLabel using a Resource File? <sect1>How do I set the color and font of a GtkLabel using a Resource File?
<p> <p>
......
This diff is collapsed.
...@@ -27,6 +27,7 @@ SUBDIRS = arrow \ ...@@ -27,6 +27,7 @@ SUBDIRS = arrow \
rangewidgets \ rangewidgets \
rulers \ rulers \
scribble-simple \ scribble-simple \
scribble-xinput \
scrolledwin \ scrolledwin \
selection \ selection \
spinbutton \ spinbutton \
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
int int main( int argc,
main (int argc, char *argv[]) char *argv[] )
{ {
GtkWidget *window; GtkWidget *window;
GtkWidget *aspect_frame; GtkWidget *aspect_frame;
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
/* Create a Button Box with the specified parameters */ /* Create a Button Box with the specified parameters */
GtkWidget *create_bbox (gint horizontal, GtkWidget *create_bbox( gint horizontal,
char* title,