remove image if exists

This commit is contained in:
2026-01-01 16:48:36 +05:00
parent 51ff8ae6e1
commit 0d29dc3d7e

17
main.c
View File

@@ -3,22 +3,23 @@
typedef struct{ typedef struct{
GtkApplication *app; GtkApplication *app;
GtkWidget *window; GtkWidget *window , *box ,*input, *image;
GtkWidget *box;
GtkWidget *input;
char dir[256]; char dir[256];
} Appdata; } Appdata;
static void load_image(Appdata *data){ static void load_image(Appdata *data){
GError *error = NULL; GError *error = NULL;
if (data->image != NULL){
gtk_box_remove(data->box,GTK_WIDGET(data->image));
}
GdkPixbuf *pix = gdk_pixbuf_new_from_file (("%s", data->dir), &error); GdkPixbuf *pix = gdk_pixbuf_new_from_file (("%s", data->dir), &error);
if (pix == NULL) { if (pix == NULL){
g_printerr ("Error loading file: #%d %s\n", error->code, error->message); g_printerr("Error loading file: #%d %s\n", error->code, error->message);
g_error_free (error); g_error_free(error);
exit (1); exit (1);
} }
GtkWidget *widget = gtk_image_new_from_pixbuf (pix); data->image = gtk_image_new_from_pixbuf(pix);
gtk_box_append(GTK_BOX(data->box),widget); gtk_box_append(GTK_BOX(data->box),data->image);
} }
// activates after enter dir in input // activates after enter dir in input