I did misunderstood you completely. I though GFile represents icon, not arbitrary file.
There is no guarantee that GIcon returned by get_icon() method will be GThemedIcon. This will be true most of the time, since file type icons are usually obtained from icon theme, but I would avoid doing any hardcoded assumption and allow icon loading function to work with GFileIcon types too.
I cannot provide python sample code since I'm not too familiar with python, but in C, icon loading function would look something like this:
* @filename: path to file from which to obtain mime type icon
* This function takes path to file and returns pixbuf with mime type icon of
* this file. If mime type icon cannot be loaded, function returns NULL.
* Return: #GdkPixbuf on success, NULL on failure. Returned #GdkPixbuf should be
* freed using g_object_unref() when not needed anymore.
load_icon( const gchar *filename )
GdkPixbuf *pix = NULL;
file = g_file_new_for_path( filename );
info = g_file_query_info( file, G_FILE_ATTRIBUTE_STANDARD_ICON,
G_FILE_QUERY_INFO_NONE, NULL, NULL );
icon = g_file_info_get_icon( info );
if( G_IS_THEMED_ICON( icon ) )
gchar const * const *names;
names = g_themed_icon_get_names( G_THEMED_ICON( icon ) );
pix = gtk_icon_theme_load_icon(
gtk_icon_theme_get_default(), *names, 16, 0, NULL );
else if( G_IS_FILE_ICON( icon ) )
icon_file = g_file_icon_get_file( G_FILE_ICON( icon ) );
path = g_file_get_path( icon_file );
pix = gdk_pixbuf_new_from_file_at_size( path, 16, 16, NULL );
g_free( path );
g_object_unref( G_OBJECT( icon_file ) );
g_object_unref( G_OBJECT( icon ) );
g_object_unref( G_OBJECT( info ) );
g_object_unref( G_OBJECT( file ) );
return( pix );