Re: Simple(?) gtk_clist_moveto problem.



"José Miguel R. Barrientos" wrote:
> 
> "José Miguel R. Barrientos" wrote:
> >
> > Karol Bryd wrote:
> > >
> > > On 14-May-99, José Miguel R. Barrientos <jmiguel@ceselsa.es> wrote:
> > >
> > > >
> > > > The ScrolledWindow Widget has changed in recent releases of Gtk.
> > > > In your program, try this:
> > > >
> > > >    gtk_container_add(GTK_CONTAINER(scrolled_window), gtklist);
> > > >
> > > > REPLACING this
> > > >    gtk_scrolled_window_add_with_viewport(
> > > > GTK_SCROLLED_WINDOW(scrolled_window),
> > > >                                           gtklist);
> > > >
> > > >
> > > > Ah!, you CANNOT create a list with 0 (zero) columns. Create it with
> > > >
> > > >    gtklist=gtk_clist_new(1);
> > > >
> > > >
> > > > I've compiled your source with these changes and (apparently) is
> > > > working...
> > >
> > > Thanks for help, it indeed helped. But now I have other problem.
> > > I try to write a x11amp plugin, that will display a song's lyrics.
> > > I need for this a list view (for lyrics display) with ability of
> > > updating it every few seconds. So I have created a thread that will
> > > get current time from x11amp and accordingly update a gtk clist
> > > (that is why I needed help with gtk_clist_moveto). But it doesn't
> > > work...Everything is great but when I add a thread, that is
> > > manipulating a clist, it hangs and I get: "Xlib: unexpected async
> > > reply (sequence 0x102)", sometimes I even have to restart X...
> > >
> > > Are there any special functions to manipulate GtkWidgets from
> > > other threads? Or maybe should I use gdk's threads?
> > >
> > > I have included a source code, if you could look at I'd be grateful.
> > >
> > > Pozdrawiam.
> > > --
> > > Karol Bryd                                       //
> > > http://www.kki.net.pl/~kbryd                  \ //   Team *AMIGA*
> > > kbryd@femina.com.pl                           \X/  Powered by Linux
> > >
> > > The most exhausting thing in life is being insincere.  -- Anne Morrow
> > > Lindberg
> > >
> > >   --------------------------------------------------------------------------------
> > >                      Name: plugin.tar.bz2
> > >    plugin.tar.bz2    Type: unspecified type (application/octet-stream)
> > >                  Encoding: base64
> >
> > Perhaps you can better use a timer (see gdk_timer_set() ) in your program. It's
> > more simple than use threads.
> >
> >         - José Miguel
> 
> Sorry, and sorry, .... :)
> 
> Nothing about timers, but timeouts
> 
>         gtk_timeout_add()
> 
>         - José Miguel


Ah! this code with threads works in Linux, but not in Solaris, perhaps with
Solaris you need use the Solaris implementation of threads... I don't know why
it's not working...


#include <stdio.h>
#include <gtk/gtk.h>
#include <pthread.h>

/* */
main(int argc, char *argv[]) {
	void	init_thr();
	void	rellena(GtkWidget*);
	GtkWidget	*init_list();
	GtkWidget	*lista = NULL;
	gint		timer;
	void		*vamos(void*);
	pthread_t	thr;

	gtk_init(&argc, &argv);

	lista = init_list();
	rellena(lista);

	/* timer = gtk_timeout_add(900, vamos, lista); */

	pthread_create(&thr, NULL, vamos, lista);
	gtk_main();
	/* pthread_join(thr, NULL); */
	exit(0);
}

/* */
void rellena(GtkWidget *lista) {
	gchar	**texto;
	gint	i, j;

	texto = g_new(gchar*, 1);
	*texto = g_new(gchar, 50);

	for(i= 0; i<100; i++) {
		sprintf(texto[0], "Fila %d", i);
		gtk_clist_append(GTK_CLIST(lista), texto);
	}
	g_free(*texto);
	g_free(texto);
}

/* */
gint vamos(gpointer data) {
	static gint	i = 0;

	/* sleep(5); */

	do {
		usleep(990000);
		gtk_clist_moveto(GTK_CLIST(data), i, 0, 0.5, -1);
		gtk_clist_select_row(GTK_CLIST(data), i, 0);
	} while(++i < 20);
	pthread_exit(0);
}

/* */
GtkWidget* init_list() {
	GtkWidget	*topw = NULL,
				*view = NULL,
				*lista = NULL,
				*boton = NULL;

	gtk_widget_show(topw = gtk_window_new(GTK_WINDOW_TOPLEVEL));
    	gtk_window_set_title(GTK_WINDOW(topw), "GtkCList Example");
    	gtk_signal_connect(GTK_OBJECT(topw), "destroy",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

	gtk_widget_show(view = gtk_scrolled_window_new(NULL, NULL));
	gtk_container_set_border_width(GTK_CONTAINER(view), 5);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(view),
		GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
	gtk_container_add(GTK_CONTAINER(topw), view);

	/*
	gtk_widget_show(boton = gtk_button_new_with_label("Vamos ..."));
    	gtk_container_add(GTK_CONTAINER(topw), boton);
	gtk_signal_connect(GTK_OBJECT(boton), "clicked", (GtkSignalFunc)vamos,
(gpointer)lista);
	*/

	gtk_widget_show(lista = gtk_clist_new(1));
	gtk_container_add(GTK_CONTAINER(view), lista);

	return(lista);
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]