Book Image

Hands-On GUI Application Development in Go

By : Andrew Williams
Book Image

Hands-On GUI Application Development in Go

By: Andrew Williams

Overview of this book

Go is often compared to C++ when it comes to low-level programming and implementations that require faster processing, such as Graphical User Interfaces (GUIs). In fact, many claim that Go is superior to C++ in terms of its concurrency and ease of use. Most graphical application toolkits, though, are still written using C or C++, and so they don't enjoy the benefits of using a modern programming language such as Go. This guide to programming GUIs with Go 1.11 explores the various toolkits available, including UI, Walk, Shiny, and Fyne. The book compares the vision behind each project to help you pick the right approach for your project. Each framework is described in detail, outlining how you can build performant applications that users will love. To aid you further in creating applications using these emerging technologies, you'll be able to easily refer to code samples and screenshots featured in the book. In addition to toolkit-specific discussions, you'll cover more complex topics, such as how to structure growing graphical applications, and how cross-platform applications can integrate with each desktop operating system to create a seamless user experience. By delving into techniques and best practices for organizing and scaling Go-based graphical applications, you'll also glimpse Go's impressive concurrency system. In the concluding chapters, you'll discover how to distribute to the main desktop marketplaces and distribution channels. By the end of this book, you'll be a confident GUI developer who can use the Go language to boost the performance of your applications.
Table of Contents (25 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Comparison of GUI Toolkits
Index

Signals and namespaces


GTK+ is an event-driven toolkit; that means that nothing happens unless an event is emitted and a callback is registered to receive it. The events in GTK+ are implemented through signals, and registering a callback for a signal is called connecting. Signals include most events involved in the GUI behavior and communication, including button click events or the window life cycle.

Signals

Did you notice that, in our hello world example, the Quit button would exit the application, but that closing the window did not? That's because we didn't connect any callback to the window destroy signal. We can fix this by adding the following lines to handle this case:

window.Connect("destroy", func() {
   gtk.MainQuit()
})

This code connects the provided anonymous function to the destroy signal ofwindow. When the signal is emitted, the function is called and the application will now exit correctly. As the gtk.MainQuit() function takes 0 parameters, we could write the same more concisely...