romgrk / node-gtk

GTK+ bindings for NodeJS (via GObject introspection)
MIT License
493 stars 41 forks source link

Gtk Image code sample? #318

Closed sarnobat closed 2 years ago

sarnobat commented 2 years ago

Sorry for filing a ticket, this is more of a question: how can I display a local file system image? Is there any sample code that resembles what I need to do?

I'm assuming there's a more direct way than the browser WebView.

sarnobat commented 2 years ago

Is this the "normal" way to do it? https://github.com/romgrk/node-gtk/blob/d68a407f2311975e982ddbc938f3266495a5b7e6/examples/gtk-tree-store.js#L38

binyamin commented 2 years ago

Is this the "normal" way to do it?

That's a fine to do it. Here are two other ways.

// Create an image widget
const image = new Gtk.Image({ file: '/path/to/img' });

// Set the icon for a particular window
// See also `Gtk.Window.setDefaultIconFromFile()`
Gtk.Window.setIconFromFile('/path/to/img'); // See also `Gtk.Window.setDefaultIconFromFile()`

In other language bindings, you might list the path inside a gresources.xml file, but I haven't seen a working example of that with node-gtk.

sarnobat commented 2 years ago

Thanks for the info. I think your Gtk.Image is the most direct way. I couldn't get PixBuf to work.

I'll reopen this if I have followup questions.