RE: gtk-list Digest, Vol 55, Issue 42



plz unsubscribe this email from the list

> From: gtk-list-request gnome org
> Subject: gtk-list Digest, Vol 55, Issue 42
> To: gtk-list gnome org
> Date: Fri, 28 Nov 2008 12:00:34 +0000
>
> Send gtk-list mailing list submissions to
> gtk-list gnome org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.gnome.org/mailman/listinfo/gtk-list
> or, via email, send a message with subject or body 'help' to
> gtk-list-request gnome org
>
> You can reach the person managing the list at
> gtk-list-owner gnome org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of gtk-list digest..."
>
>
> Today's Topics:
>
> 1. If I have to call the gtk_dialog_run() in new thread, How
> shall I do? (haitao_yang foxitsoftware com)
>
>
> ------------- ---------------------------------------------------------
>
> Message: 1
> Date: Fri, 28 Nov 2008 16:35:59 +0800
> From: "haitao_yang foxitsoftware com" <haitao_yang foxitsoftware com>
> Subject: If I have to call the gtk_dialog_run() in new thread, How
> shall I do?
> To: gtklist <gtk-list gnome org>, "haitao_yang foxitsoftware com"
> <haitao_yang foxitsoftware com>
> Message-ID: <492FAD6F 9050800 foxitsoftware com>
> Content-Type: text/plain; charset=GB2312
>
> Hello,
> When I run gtk_dialog_run() in new created thread, an error occurs.
> Nevertheless, I can not find out the reason. I only want to immitate the
> action: open a "Find" dialog, then click "Find Next" button, then launch
> a thread that will do some search, then popup a dialog in the thread
> which will prompt that the search have been done.
> Following is my code, thanks adv ance!
> ------------
>
>
> //gcc -o tdlg tdlg.c `pkg-config --cflags --libs gtk+-2.0` -lgthread-2.0 -g
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <unistd.h>
> #include <string.h>
> #include <stdio.h>
> #include <gtk/gtk.h>
>
> #define _(x) x
> GtkWidget *win = NULL;
>
> static gpointer ThreadFun(gpointer arg)
> {
> GtkWidget *pWin = GTK_WIDGET(arg);
> GtkWidget *pDlg = gtk_message_dialog_new (GTK_WINDOW(pWin),
> GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s",
> "HELLO YHT");
> gtk_dialog_run( GTK_DIALOG(pDlg));
> gtk_widget_destroy(pDlg);
> }
>
>
> void RunThread(GtkButton *pBtn, gpointer user_data)
> {
> g_thread_create(ThreadFun, win, TRUE, NULL);
> /*if I call the callback function directly, then Everything will be OK.< br>> However, if I
> launch a thread in which It Call the gtk_dialog_run(), as a result, a
> Error occur.Could
> you help me find out the reason? If I have to call the gtk_dialog_run()
> in new thread, How
> shall I do?*/
>
> //ThreadFun(win);
>
> }
>
>
>
> GtkWidget*
> create_dlg_popup (void)
> {
> GtkWidget *dlg_popup;
> GtkWidget *dialog_vbox1;
> GtkWidget *btn_runthread;
> GtkWidget *dialog_action_area1;
> GtkWidget *okbutton1;
>
> dlg_popup = gtk_dialog_new ();
> gtk_window_set_title (GTK_WINDOW (dlg_popup), _("Popup"));
> gtk_window_set_modal (GTK_WINDOW (dlg_popup), TRUE);
> gtk_window_set_type_hint (GTK_WINDOW (dlg_popup),
> GDK_WINDOW_TYPE_HINT_DIALOG);
>
> dialog_vbox1 = GTK_DIALOG (dlg_popup)->vbox;
> gtk_widget_show (dialog_vbox1);
>
> btn_runthread = gtk_button_new_ with_mnemonic (_("RunThread"));
> gtk_widget_show (btn_runthread);
> gtk_box_pack_start (GTK_BOX (dialog_vbox1), btn_runthread, FALSE, FALSE, 0);
> g_signal_connect (btn_runthread, "clicked", G_CALLBACK(RunThread), NULL);
>
> dialog_action_area1 = GTK_DIALOG (dlg_popup)->action_area;
> gtk_widget_show (dialog_action_area1);
> gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1),
> GTK_BUTTONBOX_END);
>
> okbutton1 = gtk_button_new_from_stock ("gtk-ok");
> gtk_widget_show (okbutton1);
> gtk_dialog_add_action_widget (GTK_DIALOG (dlg_popup), okbutton1,
> GTK_RESPONSE_OK);
> GTK_WIDGET_SET_FLAGS (okbutton1, GTK_CAN_DEFAULT);
> return dlg_popup;
> }
>
> void FunPopup(GtkButton *pBtn, gpointer user_data)
> {
> GtkWidget *pDlg = create_dlg_popup();
> gint ret = gtk_dialog_run(GTK_DIALOG(pDlg));
> if(ret == GTK_RESPONSE_OK)
> {
> return;
> }
> }
>
>
> GtkWidget*
> create_win (void)
> {
>
> GtkWidget *table1;
> GtkWidget *btn_popup;
> GtkWidget *btn_cancel;
>
> win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> gtk_widget_show(win);
> gtk_window_set_title (GTK_WINDOW (win), _("window1"));
>
> table1 = gtk_table_new (1, 2, TRUE);
> gtk_widget_show (table1);
> gtk_container_add (GTK_CONTAINER (win), table1);
>
> btn_popup = gtk_button_new_with_mnemonic (_("Popup"));
> gtk_widget_show (btn_popup);
> gtk_table_attach (GTK_TABLE (table1), btn_popup, 0, 1, 0, 1,
> (GtkAttachOptions) (GTK_FILL),
> (GtkAttachOptions) (0), 0, 0);
> g_signal_connect(btn_popup, "clicked", G_CALLBACK(FunPopup), NULL);
>
> btn_cancel = gtk_button_new_with_mnemonic (_("Cancel"));
> gtk_widget_show (btn_cancel);
> gtk_table_attach (GTK_TABLE (table 1), btn_cancel, 1, 2, 0, 1,
> (GtkAttachOptions) (GTK_FILL),
> (GtkAttachOptions) (0), 0, 0);
>
> return win;
> }
>
>
> int main(int argc, char* argv[])
> {
> gtk_init(&argc, &argv);
> if (!g_thread_supported ())
> {
> g_thread_init(NULL);
> gdk_threads_init();
> }
> create_win();
> gtk_main();
> return 0;
> }
>
> --
> Sincerely,
> Alfred Young
> R&D, Application Architectures
> www.foxitsoftware.com
>
>
>
> ------------------------------
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
>
> End of gtk-list Digest, Vol 55, Issue 42
> ****************************************


使用新一代 Windows Live Messenger 轻松交流? 凸蚕恚?立刻下载!


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