Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need access to gdk_pixbuf_get_type (ListStore for IconView / TreeView) #37

Closed
sqp opened this issue Sep 19, 2021 · 9 comments
Closed

Need access to gdk_pixbuf_get_type (ListStore for IconView / TreeView) #37

sqp opened this issue Sep 19, 2021 · 9 comments
Labels
question Further information is requested

Comments

@sqp
Copy link

sqp commented Sep 19, 2021

I know it's possible to do this in the builder (I used to do it before gotk3 had the function) but that seem like driving a heavy truck to move a letter. And I'd prefer not to show that in the gallery example.
IconView is not really usable without that.
Here's the gotk3 code:

// PixbufGetType is a wrapper around gdk_pixbuf_get_type().
func PixbufGetType() glib.Type {
	return glib.Type(C.gdk_pixbuf_get_type())
}

This was in gdk/pixbuf.go, I'm not sure if it belongs in the gdkpixbuf package like : gdkpixbuf.GetType() or just gdkpixbuf.Type()

@diamondburned
Copy link
Owner

I'm not sure how viable generating a type getter for every single class is. The
generated documentation for packages are already really big, but this will make
it a lot bigger.


Does this code work?

var pixbufType = glib.TypeFromName("GdkPixbuf")

The code used to get the GdkPixbuf string is below:

package main

import (
	"log"

	"github.com/diamondburned/gotk4/pkg/core/glib"
	"github.com/diamondburned/gotk4/pkg/gdkpixbuf/v2"
)

func main() {
	pixbuf := gdkpixbuf.NewPixbuf(
		gdkpixbuf.ColorspaceRGB,
		false, 8, 1, 1,
	)

	log.Println(pixbuf.TypeFromInstance())
	log.Println(pixbuf.TypeFromInstance().Name())
	log.Println(glib.TypeFromName("GdkPixbuf"))

	// Output:
	// GdkPixbuf
	// GdkPixbuf
	// GdkPixbuf
}

@sqp
Copy link
Author

sqp commented Sep 19, 2021

AFAIK there was no other specific need like this, but the IconView is not usable without it.
Your answer seem perfect: efficient and readable.
It would be nice to add an information in the ListStore doc, as it's one of its hidden options.

For the gallery I wanted to get pixbuf from icon name, which seem pretty hard now that everything is wrapped in Paintable or other, so for now it will be from download.

Side question now that my gallery is almost ready, is there a way to make a screenshot of the window (or part of) :

mainW := app.Win.Child()
snap := gtk.NewSnapshot()
mainW.SnapshotChild(mainW.FirstChild(), snap)
renderNode := snap.ToNode()
renderNode.WriteToFile("screenshot.png")

Panics in the ToNode() method.

panic: interface conversion: *glib.Object is not gsk.RenderNoder: missing method Bounds
pkg/gtk/v4/gtksnapshot.go:895

Example found on the gnome forums

@diamondburned
Copy link
Owner

diamondburned commented Sep 19, 2021

Is there a log print that says "missing marshaler for type"?

This will only work on commit 5622f54 and later.

@diamondburned
Copy link
Owner

diamondburned commented Sep 19, 2021

I should probably change the code generator to generate an assertion that vomits
out a more helpful message when the type mismatches.

Edit: commit 2625db3 implements this.

@sqp
Copy link
Author

sqp commented Sep 20, 2021

your new error message:

gotk4: marshaler error for : invalid type

Need to make more changes in pkg/core/glib/glib.go to print the real type:

-  log.Printf("gotk4: missing marshaler for type %s (i.e. %s)", v.Type(), fundamental)
+  log.Printf("gotk4: missing marshaler for type %s (%T): %s", v.Type(), v, fundamental)

-  log.Printf("gotk4: marshaler error for %s: %v", v.Type(), err)
+  log.Printf("gotk4: marshaler error for type %s (%T): %v", v.Type(), v, err)

Which now crash my screenshot attempt like this:


Gtk-WARNING: Trying to snapshot GtkViewport 0x2dfc7e0 without a current allocation
GLib-GObject-WARNING: invalid (NULL) pointer instance
GLib-GObject-CRITICAL: g_value_init_from_instance: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

With my new error message and its magical %T
gotk4: missing marshaler for type (*glib.Value): invalid type

@diamondburned
Copy link
Owner

That's unusual. Can you make a working piece of code that reproduces the
problem?

@diamondburned
Copy link
Owner

Wait... I'm wondering if this is because the returned renderNode is nil...

@diamondburned
Copy link
Owner

I think the most appropriate fix in this case would be to fix the bug that's
causing ToNode to return nil.

For now, commit 1988d98 now panics with a message indicating that an object that
wasn't supposed to be nil is now nil, which should crash the application with a
more helpful and less confusing error.

@diamondburned diamondburned added the question Further information is requested label Oct 6, 2021
@diamondburned
Copy link
Owner

I'm not sure how viable generating a type getter for every single class is. The
generated documentation for packages are already really big, but this will make
it a lot bigger.

Latest commit now generates a gdkpixbuf.GTypePixbuf value. TypeFromName is no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants