Last active
May 12, 2023 09:39
-
-
Save angstyloop/e0faf930b4978a8fcd24e5c9255f884e to your computer and use it in GitHub Desktop.
Use VIPS to show the metadata of a test image in a non-editable GTK4 4 popover text view.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Use VIPS to show the metadata of a test image in a non-editable GTK4 | |
popover text view. | |
COMPILE | |
gcc `pkg-config --cflags gtk4 vips` -o metadata-popover metadata-popover.c `pkg-config --libs gtk4 vips` | |
RUN | |
./metadata-popover | |
NOTE | |
The "print_field_fn" function was inspired by libvips/vipsheader.c | |
https://github.com/libvips/libvips/blob/master/tools/vipsheader.c | |
*/ | |
#include <vips/vips.h> | |
#include <gtk/gtk.h> | |
static void * | |
print_field_fn( VipsImage *image, const char *field, GValue *value, void *a ) | |
{ | |
char str[256]; | |
GtkTextBuffer *text_buffer = GTK_TEXT_BUFFER( a ); | |
VipsBuf buf = VIPS_BUF_STATIC( str ); | |
gtk_text_buffer_insert_at_cursor( text_buffer, | |
field, strlen( field ) ); | |
gtk_text_buffer_insert_at_cursor( text_buffer, ":", 1 ); | |
vips_buf_appendgv( &buf, value ); | |
gtk_text_buffer_insert_at_cursor( text_buffer, | |
vips_buf_all( &buf ), vips_buf_len( &buf) ); | |
gtk_text_buffer_insert_at_cursor( text_buffer, "\n", 1 ); | |
return( NULL ); | |
} | |
//static int app_flags = G_APPLICATION_FLAGS_NONE; | |
static void | |
activate( GtkApplication *app, gpointer user_data ) | |
{ | |
GtkWidget *window, *box, *popover, *text_view; | |
GtkTextBuffer *text_buffer; | |
VipsImage *image; | |
image = vips_image_new_temp_file( "a.jpg" ); | |
window = gtk_application_window_new( app ); | |
gtk_window_set_title( GTK_WINDOW( window ), "Window" ); | |
gtk_window_set_default_size( GTK_WINDOW( window ), 500, 500 ); | |
box = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 ); | |
gtk_window_set_child( GTK_WINDOW( window ), box ); | |
popover = gtk_popover_new(); | |
gtk_widget_set_parent( popover, box ); | |
gtk_popover_set_has_arrow( GTK_POPOVER( popover ), FALSE ); | |
gtk_popover_set_position( GTK_POPOVER( popover ), GTK_POS_RIGHT ); | |
text_view = gtk_text_view_new(); | |
gtk_text_view_set_editable( GTK_TEXT_VIEW( text_view ), FALSE ); | |
gtk_text_view_set_cursor_visible( GTK_TEXT_VIEW( text_view ), FALSE ); | |
gtk_popover_set_child( GTK_POPOVER( popover ), text_view ); | |
gtk_popover_set_autohide( GTK_POPOVER( popover ), FALSE ); | |
gtk_widget_set_size_request( popover, 200, 500 ); | |
text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( text_view ) ); | |
(void) vips_image_map( image, print_field_fn, text_buffer ); | |
gtk_widget_show( window ); | |
gtk_popover_popup( GTK_POPOVER( popover ) ); | |
} | |
int | |
main( int argc, char **argv ) | |
{ | |
GtkApplication *app; | |
int status; | |
VIPS_INIT( argv[0] ); | |
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; | |
} |
Author
angstyloop
commented
May 12, 2023
The output is as though we typed vipsheader -a
at the command line.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment