Giter Site home page Giter Site logo

Comments (9)

diamondburned avatar diamondburned commented on May 25, 2024

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
}

from gotk4.

sqp avatar sqp commented on May 25, 2024

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

from gotk4.

diamondburned avatar diamondburned commented on May 25, 2024

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

This will only work on commit 5622f54 and later.

from gotk4.

diamondburned avatar diamondburned commented on May 25, 2024

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.

from gotk4.

sqp avatar sqp commented on May 25, 2024

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

from gotk4.

diamondburned avatar diamondburned commented on May 25, 2024

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

from gotk4.

diamondburned avatar diamondburned commented on May 25, 2024

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

from gotk4.

diamondburned avatar diamondburned commented on May 25, 2024

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.

from gotk4.

diamondburned avatar diamondburned commented on May 25, 2024

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.

from gotk4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.