remove image if exists
This commit is contained in:
11
main.c
11
main.c
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user