Hari's Corner

Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and then

Go - how to use glade files as resources

Filed under: Tutorials and HOWTOs by Hari
Posted on Wed, Oct 24, 2018 at 22:40 IST (last updated: Wed, Oct 24, 2018 @ 22:57 IST)

Of late I've been learning the Go programming and I am building a small Resume builder using it. I decided to use GTK for the project and used Glade to design the interface. However, if you want to "cook" the .glade file into the project as a resource and not keep it as a separate file, here are the steps to be followed. It's not blindingly obvious, but reasonably straightforward.

Though there are a number of ways to get static resources into a Go project, I chose go-bindata.

Here are the steps:

Enjoy! Here's the code snippet which shows how to load from resource (where the original resource file is resumebuilder.glade inside the resources folder). This approach can be used for any other kind of resource as well.

    ui, err := gtk.BuilderNew()
    if err !=nil {
        fmt.Println(err.Error())
        os.Exit(1)
    }
    asset, err2 := Asset("resources/resumebuilder.glade")
    if err2 !=nil {
        fmt.Println(err2.Error())
        os.Exit(1)
    }
    ui.AddFromString(string(asset))
 

No comments yet

Leave a comment »

There are no comments for this article yet.

Leave a comment

First-time comments on this blog are moderated.
Your name*
Email ID*
(wont' be published)
Website
Your comments*
(No HTML allowed)
:-) :-D :biggrin: :-P ;-) 8-) :-( :mad: |-| :oops: :-/ :-| :roll:
bold italic quote code
Code* captcha Enter the code you see in the image
* required fields