LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2006, 07:12 AM   #1
ronald-be
Member
 
Registered: Aug 2004
Location: Belgium
Distribution: debian 5.02
Posts: 73

Rep: Reputation: 15
GTK-programs with glade


Hello all,

Building a GTK-application with glade seems ok, except... After closing the main window it doesn't kill its process... (did ps -A). I only provide a main window. Checked C++ builder under Windows but the programming structures seem to be the same. However I can't check the code Windows uses for the widgets : *.dfm files only contain the properties of the widget. Any ideas for the reason of this hanging? This is the code :

/*
* Initial main.c file generated by Glade. Edit as required.
* Glade will not overwrite this file.
*/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <gtk/gtk.h>

#include "interface.h"
#include "support.h"

int
main (int argc, char *argv[])
{
GtkWidget *window1;

#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif

gtk_set_locale ();
gtk_init (&argc, &argv);

add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");

/*
* The following code was added by Glade to create one of each component
* (except popup menus), just so that you see something after building
* the project. Delete any components that you don't want shown initially.
*/
window1 = create_window1 ();
gtk_widget_show (window1);

gtk_main ();
return 0;
}
----------------------------------------------------------------------------
/* interface.c
* DO NOT EDIT THIS FILE - it is generated by Glade.
*/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

#include "callbacks.h"
#include "interface.h"
#include "support.h"

#define GLADE_HOOKUP_OBJECT(component,widget,name) \
g_object_set_data_full (G_OBJECT (component), name, \
gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)

#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
g_object_set_data (G_OBJECT (component), name, widget)

GtkWidget*
create_window1 (void)
{
GtkWidget *window1;

window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window1), _("window1"));

/* Store pointers to all widgets, for use by lookup_widget(). */
GLADE_HOOKUP_OBJECT_NO_REF (window1, window1, "window1");

return window1;
}
----------------------------------------------------------------------------
/*support.c
* DO NOT EDIT THIS FILE - it is generated by Glade.
*/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>

#include <gtk/gtk.h>

#include "support.h"

GtkWidget*
lookup_widget (GtkWidget *widget,
const gchar *widget_name)
{
GtkWidget *parent, *found_widget;

for (;
{
if (GTK_IS_MENU (widget))
parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
else
parent = widget->parent;
if (!parent)
parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
if (parent == NULL)
break;
widget = parent;
}

found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
widget_name);
if (!found_widget)
g_warning ("Widget not found: %s", widget_name);
return found_widget;
}

static GList *pixmaps_directories = NULL;

/* Use this function to set the directory containing installed pixmaps. */
void
add_pixmap_directory (const gchar *directory)
{
pixmaps_directories = g_list_prepend (pixmaps_directories,
g_strdup (directory));
}

/* This is an internally used function to find pixmap files. */
static gchar*
find_pixmap_file (const gchar *filename)
{
GList *elem;

/* We step through each of the pixmaps directory to find it. */
elem = pixmaps_directories;
while (elem)
{
gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data,
G_DIR_SEPARATOR_S, filename);
if (g_file_test (pathname, G_FILE_TEST_EXISTS))
return pathname;
g_free (pathname);
elem = elem->next;
}
return NULL;
}

/* This is an internally used function to create pixmaps. */
GtkWidget*
create_pixmap (GtkWidget *widget,
const gchar *filename)
{
gchar *pathname = NULL;
GtkWidget *pixmap;

if (!filename || !filename[0])
return gtk_image_new ();

pathname = find_pixmap_file (filename);

if (!pathname)
{
g_warning (_("Couldn't find pixmap file: %s"), filename);
return gtk_image_new ();
}

pixmap = gtk_image_new_from_file (pathname);
g_free (pathname);
return pixmap;
}

/* This is an internally used function to create pixmaps. */
GdkPixbuf*
create_pixbuf (const gchar *filename)
{
gchar *pathname = NULL;
GdkPixbuf *pixbuf;
GError *error = NULL;

if (!filename || !filename[0])
return NULL;

pathname = find_pixmap_file (filename);

if (!pathname)
{
g_warning (_("Couldn't find pixmap file: %s"), filename);
return NULL;
}

pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
if (!pixbuf)
{
fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
pathname, error->message);
g_error_free (error);
}
g_free (pathname);
return pixbuf;
}

/* This is used to set ATK action descriptions. */
void
glade_set_atk_action_description (AtkAction *action,
const gchar *action_name,
const gchar *description)
{
gint n_actions, i;

n_actions = atk_action_get_n_actions (action);
for (i = 0; i < n_actions; i++)
{
if (!strcmp (atk_action_get_name (action, i), action_name))
atk_action_set_description (action, i, description);
}
}
-----------------------------------------------------------------------------
// callback.c

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <gtk/gtk.h>

#include "callbacks.h"
#include "interface.h"
#include "support.h"

Thanx

Ronald
 
Old 11-05-2006, 10:45 AM   #2
msyss
LQ Newbie
 
Registered: Mar 2006
Distribution: Arch Linux
Posts: 12

Rep: Reputation: 0
When you close your window, i.e. click the close button, the window manager in use sends a signal
to your application, which is running a message loop (see the call to gtk_main () in your application's main() function).
The reason why the window manager's call for deletion of the window isn't immediately honored is
to give an application the reason to display a "You have unsaved changes blah blah blah..." dialog before exiting.

So you need to tell your application explicitly to exit when it receives the window manager's notification. This message is called "delete_event" in gtk, and the default handler simply removes the widget. Exiting the app is done like so:

Code:
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
// further initialization...
The g_signal_connect call tells the GObject system to call the gtk_main_quit function as a
callback to the delete_event on the window.

Fortunately, Glade can do this for you to. When you created your toplevel window, go to its
attributes dialog an select the "signals" tab. Choose the "delete_event" in the list of signals
and in the callback list choose "gtk_main_quit". Glade will now create the call to g_signal_connect
for you.

Last edited by msyss; 11-05-2006 at 10:46 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
QT, Glade, GTK koolkarthikeyan Linux - General 1 10-16-2006 03:17 AM
GTK+ Glade shandy^^^ Programming 1 02-11-2006 11:42 PM
Learning C with Glade/for GTK+ J_K9 Programming 4 10-31-2005 02:21 PM
Glade / GTK 2.4 Kane635 Linux - Software 0 09-07-2004 07:53 PM
Using optionmenu with Glade/GTk robw Programming 0 11-16-2003 03:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration