In gtk3 how do I make it so gtk_image_new_from_file updates according to files inside the directory for button images?

the goal is to update my button images.

reading this post c - How to refresh an image in gtk? - Stack Overflow
and searching others
I found out after the application runs how to toggle images of the buttons (like pause/play)
But I want to essentially create and/or drop in image files in the directory and have my application accept it without restarting the whole thing. Is it possible to refresh to widget so it accepts a new file button image?

sample code:

#include <gtk/gtk.h>
static void
print_r (GtkWidget *widget,
              gpointer   data)
{
}
activate (GtkApplication *app,
          gpointer        user_data)
{
    GtkWidget *window;
    GtkWidget *grid;
    GtkWidget *image2 = gtk_image_new_from_file ("./1.png");
    GtkWidget *rbutton2 = gtk_button_new_with_label ("2");
    GtkWidget *button;

  window = gtk_application_window_new(app);
  gtk_window_set_title (GTK_WINDOW (window), "window");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

    grid = gtk_grid_new();
    gtk_container_add(GTK_CONTAINER (window), grid);


   gtk_button_set_always_show_image (GTK_BUTTON (rbutton2), TRUE);
   gtk_button_set_image (GTK_BUTTON (rbutton2), image2);
   g_signal_connect (rbutton2, "clicked", G_CALLBACK (print_r), NULL);
   gtk_grid_attach (GTK_GRID (grid), rbutton2, 0, 0, 1, 1);

  button = gtk_button_new_with_label ("Quit");
  g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
  gtk_grid_attach (GTK_GRID (grid), button, 1, 8, 1, 1);


    g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show_all(window);

    gtk_main();

}

int main( int argc, char **argv)
{
    gtk_init(&argc, &argv);

  GtkApplication *app;
  int status;
  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

    return status;

}

My application I’m applying this to using gdk-pixbuff-thumbnailer and would place the image where it expects it to be. Except I’m stuck at having to restart it everytime to see the new images. I want to post to see if it is possible to have it more seamless. Thanks for your time.
-Rod

That can be done, but requires quite some work. Is that only to aid in development or something for end users?

You should monitor the directory for changes (or even the single image files you care about). That can be done with GFileMonitor. You subscribe to the changed signal and load pixbufs again

OK. I’m having a little difficulty with the last part.

I don’t know how to load the pixbuf with the GFileMonitor. Something with the method in the callback… and this is only for helping develop. There aren’t end users. :smiley:

#include <gtk/gtk.h>
#include <unistd.h>


struct Icons{
  GtkWidget *image1;
  GtkWidget *image2;
  GtkWidget *button;
  GtkWidget *fpath;
  GtkWidget *fpath2;
  GtkWidget *monitor;
  GtkWidget *monitor2;
  
}
print_r (GFileMonitor *monitor, GFile *file, gpointer user_data, GtkWidget *button,
                struct Icons *icons){
      char *fpath = g_file_get_path(file);
      gtk_button_set_image(GTK_BUTTON(button), icons->monitor2);
}
print_r2 (GtkWidget *button,
                struct Icons *icons){
        static gboolean image2 = TRUE;
        image2 = !image2;
        if (image2)
                         gtk_button_set_image(GTK_BUTTON(button), icons->monitor2);

        else
             gtk_button_set_image (GTK_BUTTON (button), icons->monitor);

      
}

void file_changed_cb(GFileMonitor *monitor, GFile *file, gpointer user_data, GtkWidget *button, struct Icons *icons)
{
    char *fpath = g_file_get_path(file);
    g_print("%s\n", fpath);
    }

activate (GtkApplication *app,
          gpointer        user_data)
{
    GtkWidget *window;
    GtkWidget *grid;
    GtkWidget *rbutton2 = gtk_button_new_with_mnemonic ("1");
    GtkWidget *button;
    GError *err = NULL;
    GFile *monitor2 = g_file_new_for_path("images/1.png");
    GFileMonitor *fm = g_file_monitor(monitor2, G_FILE_MONITOR_WATCH_MOVES, NULL, &err);
    struct Icons icons;

  window = gtk_application_window_new(app);
  gtk_window_set_title (GTK_WINDOW (window), "window");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

    grid = gtk_grid_new();
    gtk_container_add(GTK_CONTAINER (window), grid);

   gtk_button_set_always_show_image (GTK_BUTTON (rbutton2), TRUE);
   /* icons.fpath = gtk_image_new_from_file ("./images/1.png"); */
   icons.monitor = gtk_image_new_from_file ("./images/1.png"); 
   /* gtk_button_set_image (GTK_BUTTON (rbutton2), icons.fpath); */
   gtk_button_set_image (GTK_BUTTON (rbutton2), icons.monitor);
   g_object_ref_sink (icons.fpath);
   g_signal_connect (rbutton2, "clicked", G_CALLBACK (print_r), &icons);
   g_signal_connect (rbutton2, "changed", G_CALLBACK (print_r), &icons);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb), &icons);
   gtk_grid_attach (GTK_GRID (grid), rbutton2, 0, 0, 1, 1);

  button = gtk_button_new_with_label ("Quit");
  g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
  gtk_grid_attach (GTK_GRID (grid), button, 1, 8, 1, 1);


    g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show_all(window);

    gtk_main();

}

int main( int argc, char **argv)
{
    gtk_init(&argc, &argv);

  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.examples", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

    return status;

}

You can call gtk_image_set_from_file to let GtkImage reload the file:

void
file_changed_cb(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type
                gpointer           user_data)
{
    struct Icons *icons = (struct Icons *) user_data;
    char *fpath = g_file_get_path(file);

    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons->image1, fpath);
    }

    g_free(fpath);
}

lb90 so grateful for all your help!!!
I had been fiddling with aa few templates. and on my second template and your last response manage to correct my syntax (thankfully!!!)
struggling a bit and after editing out a few too many variables went back to my old template with the old example variables and it hit just right.

thanks again man…

#include <gtk/gtk.h>
#include <unistd.h>

struct Icons{
  GtkWidget *image1;
  GtkWidget *image2;
  GtkWidget *image3;
  GtkWidget *button;
  char *fpath;
  GtkWidget *fpath2;
  
};

static void
print_r (GtkWidget *button,
                struct Icons *icons){
    static gboolean image2 = TRUE;
        image2 = !image2;
        if (image2)
        gtk_button_set_image(GTK_BUTTON(button), icons->image2);

        else
             gtk_button_set_image (GTK_BUTTON (button), icons->image1);
}
print_r2 (GFileMonitor *monitor, GFile *file, gpointer user_data, GtkWidget *button,
                struct Icons *icons){
      char *fpath = g_file_get_path(file);
}

    void
    file_changed_cb(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           user_data)
    {
    struct Icons *icons = (struct Icons *) user_data;
    char *fpath = g_file_get_path(file);

    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons->image1, fpath);
     g_print("%s\n", fpath);
    }
    g_free(fpath);
    }



activate (GtkApplication *app,
          gpointer        user_data)
{
    GtkWidget *window;
    GtkWidget *grid;
    GtkWidget *rbutton2 = gtk_button_new_with_mnemonic ("1");
    GtkWidget *button;
    GError *err = NULL;
    GFile *monitor2 = g_file_new_for_path("images/");
    GFileMonitor *fm = g_file_monitor(monitor2, G_FILE_MONITOR_WATCH_MOVES, NULL, &err);
    struct Icons icons;

  window = gtk_application_window_new(app);
  gtk_window_set_title (GTK_WINDOW (window), "window");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

    grid = gtk_grid_new();
    gtk_container_add(GTK_CONTAINER (window), grid);

   gtk_button_set_always_show_image (GTK_BUTTON (rbutton2), TRUE);
   icons.image1 = gtk_image_new_from_file ("./images/1.png");
   gtk_button_set_image (GTK_BUTTON (rbutton2), icons.image1);
   g_object_ref_sink (icons.fpath);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb), &icons);
   gtk_grid_attach (GTK_GRID (grid), rbutton2, 0, 0, 1, 1);

  button = gtk_button_new_with_label ("Quit");
  g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
  gtk_grid_attach (GTK_GRID (grid), button, 1, 8, 1, 1);


    g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show_all(window);

    gtk_main();

}

int main( int argc, char **argv)
{
    gtk_init(&argc, &argv);

  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.examples", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

    return status;

}
1 Like

Side note: you should not call gtk_init() and gtk_main() yourself, the GtkApplication will take care of that for you :slight_smile: .

1 Like
/* gcc -g `pkg-config --cflags gtk+-3.0` -O3 -o first first.c `pkg-config --libs gtk+-3.0`
*/

    #include <gtk/gtk.h>
    #include <unistd.h>
    static void
    print_r2 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    
    static void
    print_r3 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    static void
    print_r4 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    static void
    print_r5 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    static void
    print_r6 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    static void
    print_r7 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    static void
    print_r8 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    static void
    print_r9 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    static void
    print_r10 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    static void
    print_r11 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    static void
    print_r12 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    static void
    print_r13 (GtkWidget *widget,
                    gpointer    data) 
    {
    }
    
    struct Icons2{
    GtkWidget *widgetimageupdatefpathnew2;
    };
    struct Icons3{
    GtkWidget *widgetimageupdatefpathnew3;
    };
    struct Icons4{
    GtkWidget *widgetimageupdatefpathnew4;
    };
    struct Icons5{
    GtkWidget *widgetimageupdatefpathnew5;
    };
    struct Icons6{
    GtkWidget *widgetimageupdatefpathnew6;
    };
    struct Icons7{
    GtkWidget *widgetimageupdatefpathnew7;
    };
    struct Icons8{
    GtkWidget *widgetimageupdatefpathnew8;
    };
    struct Icons9{
    GtkWidget *widgetimageupdatefpathnew9;
    };
    struct Icons10{
    GtkWidget *widgetimageupdatefpathnew10;
    };
    struct Icons11{
    GtkWidget *widgetimageupdatefpathnew11;
    };
    struct Icons12{
    GtkWidget *widgetimageupdatefpathnew12;
    };
    struct Icons13{
    GtkWidget *widgetimageupdatefpathnew13;
    };

        void
    file_changed_cb2(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons2 *icons2 = (struct Icons2 *) pos;
    char *fpath2 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons2->widgetimageupdatefpathnew2, fpath2);    }
    g_free(fpath2);
    }
    void
    file_changed_cb3(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons3 *icons3 = (struct Icons3 *) pos;
    char *fpath3 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons3->widgetimageupdatefpathnew3, fpath3);    }
    g_free(fpath3);
    }
    void
    file_changed_cb4(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons4 *icons4 = (struct Icons4 *) pos;
    char *fpath4 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons4->widgetimageupdatefpathnew4, fpath4);    }
    g_free(fpath4);
    }
    void
    file_changed_cb5(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons5 *icons5 = (struct Icons5 *) pos;
    char *fpath5 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons5->widgetimageupdatefpathnew5, fpath5);    }
    g_free(fpath5);
    }
    void
    file_changed_cb6(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons6 *icons6 = (struct Icons6 *) pos;
    char *fpath6 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons6->widgetimageupdatefpathnew6, fpath6);    }
    g_free(fpath6);
    }
    void
    file_changed_cb7(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons7 *icons7 = (struct Icons7 *) pos;
    char *fpath7 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons7->widgetimageupdatefpathnew7, fpath7);    }
    g_free(fpath7);
    }
    void
    file_changed_cb8(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons8 *icons8 = (struct Icons8 *) pos;
    char *fpath8 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons8->widgetimageupdatefpathnew8, fpath8);    }
    g_free(fpath8);
    }
    void
    file_changed_cb9(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons9 *icons9 = (struct Icons9 *) pos;
    char *fpath9 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons9->widgetimageupdatefpathnew9, fpath9);    }
    g_free(fpath9);
    }
    void
    file_changed_cb10(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons10 *icons10 = (struct Icons10 *) pos;
    char *fpath10 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons10->widgetimageupdatefpathnew10, fpath10);    }
    g_free(fpath10);
    }
    void
    file_changed_cb11(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons11 *icons11 = (struct Icons11 *) pos;
    char *fpath11 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons11->widgetimageupdatefpathnew11, fpath11);    }
    g_free(fpath11);
    }

    void
    file_changed_cb12(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons12 *icons12 = (struct Icons12 *) pos;
    char *fpath12 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons12->widgetimageupdatefpathnew12, fpath12);    }
    g_free(fpath12);
    }

    void
    file_changed_cb13(GFileMonitor      *monitor,
                GFile             *file,
                GFile             *other_file,
                GFileMonitorEvent  event_type,
                gpointer           pos)
    {
    struct Icons13 *icons13 = (struct Icons13 *) pos;
    char *fpath13 = g_file_get_path(file);
    if (event_type ==  G_FILE_MONITOR_EVENT_CHANGED) {
        gtk_image_set_from_file(icons13->widgetimageupdatefpathnew13, fpath13);    }
    g_free(fpath13);
    }



   static void activate (GtkApplication *app, 
                            gpointer pos)
{
    GtkWidget *window;
    GtkWidget *widget;
    GtkWidget *grid;
    GtkWidget *button;
    GtkWidget *label;

    GError *err = NULL;
    GFile *monitor2 = g_file_new_for_path("./images/");
    GFileMonitor *fm = g_file_monitor(monitor2, G_FILE_MONITOR_WATCH_MOVES, NULL, &err);

        struct Icons2 icons2;
        struct Icons3 icons3;
        struct Icons4 icons4;
        struct Icons5 icons5;
        struct Icons6 icons6;
        struct Icons7 icons7;
        struct Icons8 icons8;
        struct Icons9 icons9;
        struct Icons10 icons10;
        struct Icons11 icons11;
        struct Icons12 icons12;
        struct Icons13 icons13;

    /* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); */
      window = gtk_application_window_new(app);
    gtk_window_set_title (GTK_WINDOW (window), "dozenbuttons");
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);


    grid = gtk_grid_new();
    gtk_container_add (GTK_CONTAINER (window), grid);

   GtkWidget *rbutton2 = gtk_button_new_with_mnemonic ("_2");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton2), TRUE);
   icons2.widgetimageupdatefpathnew2 = gtk_image_new_from_file ("./images/-1.png");
   gtk_button_set_image (GTK_BUTTON (rbutton2), icons2.widgetimageupdatefpathnew2);
   g_signal_connect (rbutton2, "clicked", G_CALLBACK (print_r2), &icons2);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb2), &icons2);
   gtk_grid_attach (GTK_GRID (grid), rbutton2, 0, 0, 1, 1);

   GtkWidget *rbutton3 = gtk_button_new_with_mnemonic ("_3");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton3), TRUE);
   icons3.widgetimageupdatefpathnew3 = gtk_image_new_from_file ("./images/0.png");
   gtk_button_set_image (GTK_BUTTON (rbutton3), icons3.widgetimageupdatefpathnew3);
   g_signal_connect (rbutton3, "clicked", G_CALLBACK (print_r3), &icons3);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb3), &icons3);
   gtk_grid_attach (GTK_GRID (grid), rbutton3, 1, 0, 1, 1);

   GtkWidget *rbutton4 = gtk_button_new_with_mnemonic ("_4");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton4), TRUE);
   icons4.widgetimageupdatefpathnew4 = gtk_image_new_from_file ("./images/1.png");
   gtk_button_set_image (GTK_BUTTON (rbutton4), icons4.widgetimageupdatefpathnew4);
   g_signal_connect (rbutton4, "clicked", G_CALLBACK (print_r4), &icons4);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb4), &icons4);
   gtk_grid_attach (GTK_GRID (grid), rbutton4, 2, 0, 1, 1);

   GtkWidget *rbutton5 = gtk_button_new_with_mnemonic ("_5");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton5), TRUE);
   icons5.widgetimageupdatefpathnew5 = gtk_image_new_from_file ("./images/2.png");
   gtk_button_set_image (GTK_BUTTON (rbutton5), icons5.widgetimageupdatefpathnew5);
   g_signal_connect (rbutton5, "clicked", G_CALLBACK (print_r5), &icons5);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb5), &icons5);
   gtk_grid_attach (GTK_GRID (grid), rbutton5, 3, 0, 1, 1);

   GtkWidget *rbutton6 = gtk_button_new_with_mnemonic ("_6");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton6), TRUE);
   icons6.widgetimageupdatefpathnew6 = gtk_image_new_from_file ("./images/3.png");
   gtk_button_set_image (GTK_BUTTON (rbutton6), icons6.widgetimageupdatefpathnew6);
   g_signal_connect (rbutton6, "clicked", G_CALLBACK (print_r6), &icons6);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb6), &icons6);
   gtk_grid_attach (GTK_GRID (grid), rbutton6, 4, 0, 1, 1);

   GtkWidget *rbutton7 = gtk_button_new_with_mnemonic ("_7");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton7), TRUE);
   icons7.widgetimageupdatefpathnew7 = gtk_image_new_from_file ("./images/4.png");
   gtk_button_set_image (GTK_BUTTON (rbutton7), icons7.widgetimageupdatefpathnew7);
   g_signal_connect (rbutton7, "clicked", G_CALLBACK (print_r7), &icons7);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb7), &icons7);
   gtk_grid_attach (GTK_GRID (grid), rbutton7, 5, 0, 1, 1);

   GtkWidget *rbutton8 = gtk_button_new_with_mnemonic ("_8");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton8), TRUE);
   icons8.widgetimageupdatefpathnew8 = gtk_image_new_from_file ("./images/5.png");
   gtk_button_set_image (GTK_BUTTON (rbutton8), icons8.widgetimageupdatefpathnew8);
   g_signal_connect (rbutton8, "clicked", G_CALLBACK (print_r8), &icons8);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb8), &icons8);
   gtk_grid_attach (GTK_GRID (grid), rbutton8, 6, 0, 1, 1);

   GtkWidget *rbutton9 = gtk_button_new_with_mnemonic ("_9");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton9), TRUE);
   icons9.widgetimageupdatefpathnew9 = gtk_image_new_from_file ("./images/6.png");
   gtk_button_set_image (GTK_BUTTON (rbutton9), icons9.widgetimageupdatefpathnew9);
   g_signal_connect (rbutton9, "clicked", G_CALLBACK (print_r9), &icons9);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb9), &icons9);
   gtk_grid_attach (GTK_GRID (grid), rbutton9, 0, 1, 1, 1);

   GtkWidget *rbutton10 = gtk_button_new_with_mnemonic ("_10");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton10), TRUE);
   icons10.widgetimageupdatefpathnew10 = gtk_image_new_from_file ("./images/7.png");
   gtk_button_set_image (GTK_BUTTON (rbutton10), icons10.widgetimageupdatefpathnew10);
   g_signal_connect (rbutton10, "clicked", G_CALLBACK (print_r10), &icons10);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb10), &icons10);
   gtk_grid_attach (GTK_GRID (grid), rbutton10, 1, 1, 1, 1);

   GtkWidget *rbutton11 = gtk_button_new_with_mnemonic ("_11");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton11), TRUE);
   icons11.widgetimageupdatefpathnew11 = gtk_image_new_from_file ("./images/8.png");
   gtk_button_set_image (GTK_BUTTON (rbutton11), icons11.widgetimageupdatefpathnew11);
   g_signal_connect (rbutton11, "clicked", G_CALLBACK (print_r11), &icons11);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb11), &icons11);
   gtk_grid_attach (GTK_GRID (grid), rbutton11, 2, 1, 1, 1);

   GtkWidget *rbutton12 = gtk_button_new_with_mnemonic ("_12");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton12), TRUE);
   icons12.widgetimageupdatefpathnew12 = gtk_image_new_from_file ("./images/9.png");
   gtk_button_set_image (GTK_BUTTON (rbutton12), icons12.widgetimageupdatefpathnew12);
   g_signal_connect (rbutton12, "clicked", G_CALLBACK (print_r12), &icons12);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb12), &icons12);
   gtk_grid_attach (GTK_GRID (grid), rbutton12, 3, 1, 1, 1);

   GtkWidget *rbutton13 = gtk_button_new_with_mnemonic ("_13");
   gtk_button_set_always_show_image (GTK_BUTTON (rbutton13), TRUE);
   icons13.widgetimageupdatefpathnew13 = gtk_image_new_from_file ("./images/10.png");
   gtk_button_set_image (GTK_BUTTON (rbutton13), icons13.widgetimageupdatefpathnew13);
   g_signal_connect (rbutton13, "clicked", G_CALLBACK (print_r13), &icons13);
   g_signal_connect(G_OBJECT(fm), "changed", G_CALLBACK(file_changed_cb13), &icons13);
   gtk_grid_attach (GTK_GRID (grid), rbutton13, 4, 1, 1, 1);

   button = gtk_button_new_with_mnemonic ("_Quit");
   g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
   gtk_grid_attach (GTK_GRID (grid), button, 6, 2, 1, 1);

    g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
    gtk_widget_show_all(window);
    gtk_main();
    }

    int main( int argc, char **argv)
    {
      gtk_init(&argc, &argv);
      GtkApplication *app;
      int status;
    
      app = gtk_application_new ("org.gtk.first", G_APPLICATION_FLAGS_NONE);
      g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
      status = g_application_run (G_APPLICATION (app), argc, argv);
      g_object_unref (app);
    
        return status;
    }

THanks for the input.

I would take that out but it seems to be a lifeline for the way i went about coding my application. See above example. It still has bugs. for instaance if I leave those lines that you mention in my code rather than segfaulting it goes through with my intentions and replaces all button icons with the one icon in ./images/ . Or it will run my two gigs of laptop memory to lockup… But last night I starting to use earlyoom and the experience has been awesome.

all in all I am very please with what I got . Any suggestions welcomed.

p.s. - without memory lockup and using earlyoom I think I’d mind the icons all getting an update instead of one icon which is what I want.