I just don't understand gtk at all...

This commit is contained in:
Markus Koch 2016-06-05 17:16:25 +02:00
parent 7084a9a077
commit d909c40c13
4 changed files with 110 additions and 48 deletions

View File

@ -40,7 +40,6 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="kona_download_image" object="previewWidget" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>

View File

@ -26,11 +26,11 @@ int buildWindow() {
previewLayout = gtk_flow_box_new();
gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(previewLayout), 200);
for (int i = 0; i < 100; ++i) {
for (int i = 0; i < 2; ++i) {
// CUSTOM!!!!!
ki = kona_image_new();
temp = PreviewWidget_new(ki);
g_signal_connect(ki, "notify::previewFile", (GCallback)previewImage_update_preview_from_konaImage, temp);
gtk_flow_box_insert(GTK_FLOW_BOX(previewLayout),temp,0);
gtk_widget_show(temp);
// -------------------
@ -40,52 +40,57 @@ int buildWindow() {
gtk_widget_show(previewLayout);
gtk_container_add(GTK_CONTAINER(previewContainer), previewLayout);
gtk_container_add(GTK_CONTAINER(previewContainer), previewLayout);
g_object_unref(G_OBJECT(builder));
g_object_unref(G_OBJECT(builder));
gtk_widget_show(GTK_WIDGET(mainWindow));
gtk_widget_show(GTK_WIDGET(mainWindow));
/*** TESTING LIB ***/
GValue val = G_VALUE_INIT;
GValue sval = G_VALUE_INIT;
GValue sval = G_VALUE_INIT;
g_value_init(&sval, G_TYPE_STRING);
g_value_set_string(&sval, "/home/markus/Pictures/FFT-an.png");
g_object_set_property((GObject*) ki, "previewFile", &sval);
kona_image_meta meta;
ki = kona_image_new();
g_value_init(&val, G_TYPE_POINTER);
if (0) {
/*** TESTING LIB ***/
GValue val = G_VALUE_INIT;
kona_image_meta meta;
ki = kona_image_new();
g_value_init(&val, G_TYPE_POINTER);
meta.height = 100;
meta.width = 200;
meta.image_url = "MEOWMEOWMEOW";
meta.height = 100;
meta.width = 200;
meta.image_url = "MEOWMEOWMEOW";
g_value_set_pointer(&val, (gpointer) &meta);
g_object_set_property((GObject*) ki, "meta", &val);
g_value_set_pointer(&val, (gpointer) &meta);
g_object_set_property((GObject*) ki, "meta", &val);
g_value_init(&sval, G_TYPE_STRING);
g_value_set_string(&sval, "Hello world!");
g_object_set_property((GObject*) ki, "fullFile", &sval);
g_value_init(&sval, G_TYPE_STRING);
g_value_set_string(&sval, "Hello world!");
g_object_set_property((GObject*) ki, "fullFile", &sval);
g_value_reset(&val);
g_value_reset(&sval);
g_value_reset(&val);
g_value_reset(&sval);
meta.height = 0;
meta.width = 1;
meta.height = 0;
meta.width = 1;
// Read back
g_object_get_property((GObject*) ki, "meta", &val);
kona_image_meta *metret;
metret = g_value_get_pointer(&val);
printf("WIDTH=%i\n", metret->width);
printf("HEIGHT=%i\n", metret->height);
g_object_get_property((GObject*) ki, "fullFile", &sval);
printf("STRING=%s\n", g_value_get_string(&sval));
// Read back
g_object_get_property((GObject*) ki, "meta", &val);
kona_image_meta *metret;
metret = g_value_get_pointer(&val);
printf("WIDTH=%i\n", metret->width);
printf("HEIGHT=%i\n", metret->height);
g_object_get_property((GObject*) ki, "fullFile", &sval);
printf("STRING=%s\n", g_value_get_string(&sval));
}
}
int main(int argc, char **argv)

View File

@ -6,17 +6,17 @@ G_DEFINE_TYPE(PreviewWidget, PreviewWidget, GTK_TYPE_BIN)
void kona_download_image( GtkWidget *widget, gpointer data )
{
PreviewWidget_set_image(data, "/home/kurisu/Pictures/Screenshot from 2016-03-07 09-16-18.png"); // DEBUG ONLY!
PreviewWidget_set_image(data, "/home/markus/Pictures/ba5431ccdc292f920692d17bdfc2758d.png"); // DEBUG ONLY!
}
void PreviewWidget_set_image(PreviewWidget *widget, gchar *url) {
GtkWidget *w;
//GtkWidget *w;
GList *widgets;
int height, width;
float iheight, iwidth;
widgets = gtk_container_get_children(GTK_CONTAINER(widget));
w = widgets->data; // Grab GtkImage
//w = widgets->data; // Grab GtkImage
GdkPixbuf *p, *ps;
p = gdk_pixbuf_new_from_file(url, NULL);
@ -33,44 +33,81 @@ void PreviewWidget_set_image(PreviewWidget *widget, gchar *url) {
ps = gdk_pixbuf_scale_simple(p, width, height, GDK_INTERP_BILINEAR);
g_object_unref(p);
gtk_image_set_from_pixbuf(GTK_IMAGE(w), ps);
gtk_image_set_from_pixbuf(GTK_IMAGE(widget->image), ps);
gtk_widget_set_visible(w, TRUE);
gtk_widget_set_visible(widget->image, TRUE);
w = g_list_next(widgets)->data; // Grab Spinner
gtk_widget_set_visible(w, FALSE);
gtk_widget_set_visible(widget->spinner, FALSE);
}
enum {
PROP_KI=1,
PROP_COUNT
};
static GParamSpec *properties [PROP_COUNT];
static void preview_widget_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) {
PreviewWidget *self = (PreviewWidget*)object;
switch (prop_id) {
case PROP_KI:
g_value_set_pointer(value, self->ki);
break;
default:
break;
}
}
static void preview_widget_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) {
PreviewWidget *self = (PreviewWidget*)object;
switch (prop_id) {
case PROP_KI:
self->ki = g_value_get_pointer(value);
break;
default:
break;
}
}
void PreviewWidget_class_init(PreviewWidgetClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->set_property = preview_widget_set_property;
object_class->get_property = preview_widget_get_property;
properties [PROP_KI] =
g_param_spec_pointer("ki", "ki", "Pointer to corresponding KonaImage struct", G_PARAM_READWRITE);
g_object_class_install_properties(object_class, PROP_COUNT, properties);
}
void PreviewWidget_init(PreviewWidget *klass)
{
GtkWidget *widget;
GtkBuilder *builder;
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "glade/previewWidget.glade", NULL);
widget = GTK_WIDGET(gtk_builder_get_object(GTK_BUILDER(builder), "previewWidget"));
gtk_builder_connect_signals(builder, NULL);
gtk_container_add(GTK_CONTAINER(klass), widget);
GTK_WIDGET(gtk_builder_get_object(builder, "image"));
klass->image = GTK_WIDGET(gtk_builder_get_object(builder, "image"));
klass->button = GTK_WIDGET(gtk_builder_get_object(builder, "button"));
klass->spinner = GTK_WIDGET(gtk_builder_get_object(builder, "spinner"));
/*klass->image= GTK_WIDGET(gtk_builder_get_object(builder, "image"));
klass->button = GTK_WIDGET(gtk_builder_get_object(builder, "button"));
klass->spinner = GTK_WIDGET(gtk_builder_get_object(builder, "spinner"));*/
g_object_unref(G_OBJECT(builder));
}
GtkWidget *PreviewWidget_new(KonaImage* ki)
{
return g_object_new (TYPE_PREVIEWWIDGET, NULL);
PreviewWidget* w = g_object_new (TYPE_PREVIEWWIDGET, "ki", ki, NULL);
printf("c_pv=%p\n", w);
//g_signal_connect(ki, "notify::previewFile", (GCallback)previewImage_update_preview_from_konaImage, w);
return w;
}
@ -79,7 +116,20 @@ GtkWidget *PreviewWidget_new(KonaImage* ki)
void debugfoo(GtkButton *widget, GtkImage *img)
{
gtk_image_clear(img);
g_object_unref(gtk_image_get_pixbuf(img));
gtk_widget_destroy(img);
gtk_widget_destroy(GTK_WIDGET(img));
}
// CALLBACKS FROM KONAIMAGE
void previewImage_update_preview_from_konaImage( KonaImage *ki, PreviewWidget *pv)
{
GValue val = G_VALUE_INIT;
g_value_init(&val, G_TYPE_STRING);
g_object_get_property(ki, "previewFile", &val);
printf("SET IMAGE TO: %s\n", g_value_get_string(&val));
printf("h_pv=%p\n", pv);
gtk_widget_set_visible(pv->image, TRUE);
//PreviewWidget_set_image(pv, "hi");
}

View File

@ -18,6 +18,10 @@ typedef struct _PreviewWidgetClass PreviewWidgetClass;
struct _PreviewWidget {
GtkBin bin;
GtkWidget *image;
GtkWidget *button;
GtkWidget *spinner;
KonaImage *ki;
};
struct _PreviewWidgetClass {
@ -32,6 +36,10 @@ void PreviewWidget_set_image(PreviewWidget *widget, gchar *url);
void debugfoo(GtkButton *widget, GtkImage* img);
// CALLBACKS FROM KONAIMAGE
void previewImage_update_preview_from_konaImage( KonaImage *ki, PreviewWidget *pv);
G_END_DECLS
#endif // PREVIEWWIDGET_H