On Thu, Oct 30, 2003 at 09:15:52AM +0000, Alessandro Bottoni wrote:
> This morning I just tried to eliminate all pixmap from my Glade1 projects. In
> particular I eliminated all "stock" pushbottons (that contains small icons)
> and all "stock" menu items (that contains small icons, as well).
>
> This "clean up" action fixed all the GTK and GDK -related troubles: no more
> crashes at start-up time, no more GTK/GDK "assertion failed" warnings at run
> time (when resizing the window).
OH! I forgot this. You *can't* use stock icons in Glade if you're not
calling gnome.app_init() in your application!
> It looks like PyGTK (not Kiwi) has a problem in finding the pixmap files for
> the small icons of stock pushbuttons and stock menu items _and_ it has a
> problem in finding the text strings for stock menu items. I mean: all the
> resources that should available from the "standard" GTK/GDK/GLIB system seems
> to be unavailable or unreacheable.
No, the issue is that GTK+ 1.2 didn't supply stock icons for buttons
at all. Stock icons are only available if you enable gnome support and
initialize gnome in your application. IIRC, this has been discussed on
the mailing list in the past, and there's even a FAQ stub on the
matter:
http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq09.003.htp
> This probably means that I have to supply this stuff to the system but...:
> - where can I find those stock pixmap and those stock text strings? They are
> not available in the directory branch created by Glade 1. Most likely, Glade
> 1 is convinced to find them compiled into the gtk.so library as "resources".
No, they're actually gnome pixmaps, and they should be available on the
system. At any rate, you can download the new (GTK+2) stock icons from
http://art.gnome.org/art-icons/gtk-stock/index.php
Another good resource for artwork is
http://art.gnome.org/
> - once found the pixmaps, where can I put those pixmap and string text? Inside
> the same directory of the .glade file? This would be not clean: I need a way
> to organize my code. Is there any way to tell PyGTK where those elements were
> stored?
Well, now comes the part you won't like to hear. Glade requires the
pixmaps to be in the same directory [as the glade file] to be able to
edit them, and libglade requires the pixmaps to be in the same directory
to be able to load them. I dislike this immensely, and we've gone as far
as patching libglade to allow specifying a GLADE_PIXMAP_PATH directory,
from which pixmaps will be loaded if they're not found in the local
directory (IIRC, that's the search order).
I'm not sure libglade in GTK+2 allows something similar, but maybe
someone else knows and will tell us. I've attached the patch Johan wrote
in the hope it will be helpful (i.e. if using a hacked libglade is an
option for you).
Take care,
--
Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 261 2331
Index: glade/glade-gnome.c
===================================================================
RCS file: /cvs/gnome/libglade/glade/Attic/glade-gnome.c,v
retrieving revision 1.44
diff -u -u -r1.44 glade-gnome.c
--- glade/glade-gnome.c 12 Feb 2001 05:57:02 -0000 1.44
+++ glade/glade-gnome.c 20 Jan 2003 15:36:16 -0000
@@ -44,6 +44,7 @@
static const char *get_stock_name (const char *stock_name);
static gboolean get_stock_uiinfo (const char *stock_name, GnomeUIInfo *info);
+char * find_in_glade_pixmap_path (const char *filename);
static void
page_mapped (GtkWidget *page, GtkAccelGroup *accel_group)
@@ -398,9 +399,16 @@
} else if (icon) {
GdkPixmap *pix;
GdkBitmap *mask = NULL;
+ gchar *full_path;
+
+ full_path = find_in_glade_pixmap_path(icon);
+ if (full_path != NULL) {
+ icon = full_path;
+ }
+
pix = gdk_pixmap_colormap_create_from_xpm(NULL,
gtk_widget_get_colormap(w), &mask,
- NULL, icon);
+ NULL, full_path);
g_free(icon);
if (pix)
iconw = gtk_pixmap_new(pix, mask);
@@ -1515,7 +1523,7 @@
{
GtkWidget *wid;
GList *tmp;
- gchar *filename = NULL;
+ gchar *filename = NULL, *full_path;
for (tmp = info->attributes; tmp; tmp = tmp->next) {
GladeAttribute *attr = tmp->data;
@@ -1525,6 +1533,12 @@
filename = glade_xml_relative_file(xml, attr->value);
}
}
+
+ full_path = find_in_glade_pixmap_path(filename);
+ if (full_path != NULL) {
+ filename = full_path;
+ }
+
if (filename)
wid = gnome_pixmap_new_from_file(filename);
else
@@ -1693,8 +1707,15 @@
iconw);
gtk_widget_show(iconw);
} else if (user_icon) {
- gchar *iconfile = glade_xml_relative_file(xml, user_icon);
- GtkWidget *iconw = gnome_pixmap_new_from_file(iconfile);
+ gchar *iconfile = glade_xml_relative_file(xml, user_icon), *full_path;
+ GtkWidget *iconw;
+
+ full_path = find_in_glade_pixmap_path(iconfile);
+ if (full_path != NULL) {
+ iconfile = full_path;
+ }
+
+ iconw = gnome_pixmap_new_from_file(iconfile);
g_free(iconfile);
gtk_pixmap_menu_item_set_pixmap(GTK_PIXMAP_MENU_ITEM(wid),
Index: glade/glade-gtk.c
===================================================================
RCS file: /cvs/gnome/libglade/glade/glade-gtk.c,v
retrieving revision 1.51.2.2
diff -u -u -r1.51.2.2 glade-gtk.c
--- glade/glade-gtk.c 7 Jan 2002 14:14:47 -0000 1.51.2.2
+++ glade/glade-gtk.c 20 Jan 2003 15:36:23 -0000
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <glade/glade-build.h>
#include <glade/glade-private.h>
#include <gmodule.h>
@@ -37,6 +38,35 @@
#undef _
#define _(msgid) (glade_xml_gettext(xml, msgid))
+char *
+find_in_glade_pixmap_path (const char *filename)
+{
+ gchar *env, *pixmap;
+ gchar **parts;
+ gint i;
+
+ env = g_getenv("GLADE_PIXMAP_PATH");
+ if (env == NULL) {
+ return NULL;
+ }
+
+ parts = g_strsplit(env, ":", 255);
+ for (i = 0; parts[i] != NULL; i++) {
+ pixmap = g_strdup_printf("%s/%s", parts[i],
+ g_basename(filename));
+
+ /* Check if the pixmap exist and is readable */
+ if (!access(pixmap, R_OK)) {
+ return pixmap;
+ }
+
+ g_free(parts[i]);
+ g_free(pixmap);
+ }
+ g_free(parts);
+ return NULL;
+}
+
/* functions to actually build the widgets */
static void
@@ -580,6 +610,7 @@
g_free (vboxname);
}
+
static void
toolbar_build_children (GladeXML *xml, GtkWidget *w, GladeWidgetInfo *info,
const char *longname)
@@ -628,6 +659,13 @@
if (icon) {
GdkPixmap *pix;
GdkBitmap *mask = NULL;
+ gchar *full_path;
+
+ full_path = find_in_glade_pixmap_path(icon);
+ if (full_path != NULL) {
+ icon = full_path;
+ }
+
pix = gdk_pixmap_colormap_create_from_xpm(NULL,
gtk_widget_get_colormap(w), &mask,
NULL, icon);
@@ -1778,7 +1816,8 @@
GdkPixmap *pixmap;
GdkBitmap *bitmap = NULL;
char *filename = NULL;
-
+ char *full_path;
+
for (tmp = info->attributes; tmp; tmp = tmp->next) {
GladeAttribute *attr = tmp->data;
@@ -1788,6 +1827,12 @@
break;
}
}
+
+ full_path = find_in_glade_pixmap_path(filename);
+ if (full_path != NULL) {
+ filename = full_path;
+ }
+
pixmap = gdk_pixmap_colormap_create_from_xpm(NULL,
gtk_widget_get_default_colormap(), &bitmap, NULL, filename);
if (filename)
Index: glade/glade-private.h
===================================================================
RCS file: /cvs/gnome/libglade/glade/glade-private.h,v
retrieving revision 1.16
diff -u -u -r1.16 glade-private.h
--- glade/glade-private.h 10 Feb 2001 11:45:31 -0000 1.16
+++ glade/glade-private.h 20 Jan 2003 15:36:24 -0000
@@ -104,5 +104,7 @@
*/
GladeWidgetTree *glade_tree_get (const char *filename);
+char *find_in_glade_pixmap_path (const char *filename);
+
#endif
diff -ur glade-0.6.4/glade/glade_project.c glade-0.6.4-new/glade/glade_project.c
--- glade-0.6.4/glade/glade_project.c 2000-09-17 19:49:16.000000000 -0300
+++ glade-0.6.4-new/glade/glade_project.c 2003-01-08 15:49:22.000000000 -0200
@@ -836,7 +836,12 @@
GList *element;
GladeError *error = NULL;
gboolean checked_pixmaps_dir = FALSE;
-
+
+ if (g_getenv("GLADE_PIXMAP_PATH") != NULL)
+ {
+ return NULL;
+ }
+
pixmaps_dir = glade_project_get_pixmaps_directory (project);
if (!pixmaps_dir || pixmaps_dir[0] == '\0')
{
diff -ur glade-0.6.4/glade/load.c glade-0.6.4-new/glade/load.c
--- glade-0.6.4/glade/load.c 2001-02-15 01:42:33.000000000 -0200
+++ glade-0.6.4-new/glade/load.c 2003-01-08 16:09:50.000000000 -0200
@@ -20,6 +20,7 @@
#include <string.h>
#include <locale.h>
#include <stdlib.h>
+#include <unistd.h>
#include "gladeconfig.h"
@@ -810,6 +811,33 @@
return value ? value : "";
}
+char *
+find_in_glade_pixmap_path (const char *filename)
+{
+ gchar *env, *pixmap;
+ gchar **parts;
+ gint i;
+
+ env = g_getenv("GLADE_PIXMAP_PATH");
+ if (env == NULL) {
+ return NULL;
+ }
+
+ parts = g_strsplit(env, ":", 255);
+ for (i = 0; parts[i] != NULL; i++) {
+ pixmap = glade_util_make_absolute_path(parts[i], filename);
+
+ /* Check if the pixmap exist and is readable */
+ if (!access(pixmap, R_OK)) {
+ return pixmap;
+ }
+
+ g_free(parts[i]);
+ g_free(pixmap);
+ }
+ g_free(parts);
+ return NULL;
+}
/* If we are loading the XML file, we convert any relative filenames to
absolute ones, based on the project directory and/or pixmaps directory
@@ -819,11 +847,18 @@
const gchar * property_name)
{
gchar *value = load_get_value (data, property_name);
+ gchar *pixmap;
gchar *pixmaps_dir;
if (value == NULL)
return NULL;
+ pixmap = find_in_glade_pixmap_path(value);
+ if (pixmap != NULL)
+ {
+ return pixmap;
+ }
+
if (data->xml_buffer == NULL)
{
pixmaps_dir = glade_project_get_pixmaps_directory (data->project);
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/