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

Preface

Since the 1.0 release of the Go programming language in 2012, developers have enjoyed the increased productivity brought by the easy-to-read, quick-to-learn, cross-platform design of Go. Web apps and system utilities around the world are being built with Go to rapidly deliver reliable performance. Learning the language is easy, due to its centralized documentation and great programming environment support. Creating Graphical User Interfaces (GUIs) with Go, however, is still very new and there is not yet a standardized UI toolkit.

This definitive guide to programming GUIs with Go explores the most popular GUI packages available. It compares the vision behind each toolkit to help you pick the right approach for your project. Each toolkit is described in detail, outlining how to build beautiful, performant applications that users will love. Code samples and screenshots will aid any level of Go developer to create applications using these emerging technologies.

Who this book is for

This book is written for Go developers who are interested in building native graphical applications for desktop computers and beyond. Some knowledge of building Go applications (command line based or web apps) is assumed, but not essential. The first section of this book looks at the history of the GUI, its importance to the evolution of modern personal computers, and how it can pose additional challenges to software developers.

Developers of GUI applications that are interested in trying Go may also find this book useful. Section 2, Toolkits Using Existing Widgets and Section 3, Modern Graphical Toolkits, explore the various frameworks available to the Go language and demonstrate how applications can be rapidly developed from basic principles.

Additionally, an experienced Go developer may find the final section useful. The chapters of section 4, Growing and Distributing Your Application covers how to design and build complex graphical interfaces that fit user expectations. It looks at the different approaches possible to support multiple operating system standards and how to integrate the GUI well with network resources and cloud services. The final chapters cover best practices in GUI applications with Go, and look at how to package and distribute your software through the various distribution channels available.

 

What this book covers

Section 1: Graphical User Interface Development

Chapter 1, The Benefits of Native Graphical Applications, contains a re-introduction to the GUI and its role in the modern software ecosystem. It discusses the benefits of coding a native GUI for a responsive user experience and platform integration. By the end of the chapter, you will be comfortable deciding which of your projects would benefit from a native graphical interface.

Chapter 2, Graphical User Interface Challenges, shows how GUIs present various challenges to the designer and developer beyond that of a web app or systems application. This chapter will explore the details of the most common challenges, including look and feel, performance, platform integration, and distribution. On completion of this chapter, you will be familiar with the additional complications of building a graphical desktop application, and know what to consider when designing a GUI.

Chapter 3, Go to the Rescue!, shows how the design of the Go language is well suited to solving the challenges described in the previous chapter. It will demonstrate how the Go language, despite not having a standard user interface API, has all the required constructs to ease development of graphical applications. At the end of this chapter, you will be ready to progress to the detailed toolkit API descriptions that follow in Section 2, Toolkits Using Existing GUIs.

Section 2: Toolkits Using Existing GUIs

Chapter 4, Walk - Building Graphical Windows Applications, discusses Walk, which is a Windows Application Library Kit for the Go programming language. This chapter covers  API design, common usage patterns, and how to use the library as part of a multi-platform strategy. You will learn how to build a simple Windows application using the Walk toolkit through examples and illustrations.

Chapter 5, andlabs UI – Cross-Platform Native UIs, explores Andlabs UI, which is a popular GUI toolkit that uses the existing graphical technologies on each of the platforms it supports. This chapter discusses the benefits of such an approach and shows how the API is designed. You will learn how to build a simple application using the andlabs UI toolkit through examples and illustrations.

 

Chapter 6Go-GTK – Multiple Platforms with GTK, here, Go-GTK examines the Go language bindings for GTK+, a multi-platform toolkit for creating GUIs. GTK+ supports many platforms and comes preinstalled on many environments. In this chapter, we look at the details of the GTK+ toolkit, the platforms it supports, and how to make use of it in your application. You will learn how to build a simple application using the Go-GTK API through examples and illustrations.

Chapter 7, Go-Qt – Multiple Platforms with QT,explains that Go-Qt allows you to write Qt-based graphical applications in Go. Qt is a cross-platform application framework that is used for developing applications that can be run on various software and hardware platforms. In this chapter, we look at the details of the Qt framework, the platforms it supports, and how to make use of it in your application. You will learn how to build a simple application using the Go-Qt API through examples and illustrations.

Section 3: Modern Graphical Toolkits

Chapter 8, Shiny – Go's Experimental API, looks at the Shiny project, an experimental GUI library written in pure Go, and is designed to create portable apps that have a consistent look across multiple platforms. This chapter explores how to write portable cross-platform applications with Shiny. You will learn how to build a simple cross-platform graphical application using the Shiny APIs through examples and illustrations.

Chapter 9, nk – Nuklear for Go, explains that Nuklear is a lightweight widget library that focuses purely on the graphical interface (rather than window management and platform integration) to create an easy-to-use API. The graphical interface, originally designed for embedded applications, renders identically across all supported platforms. Its implementation has no dependencies and achieves this by avoiding a standard render context and operating system drivers. You will learn how to set up a render context and use this toolkit to create an example application.

Chapter 10, Fyne – Material Design-Based GUI, explores the Fyne project, designed to be an easy to use UI toolkit and app API written in Go that follows the Material Design principles. It uses OpenGL backend to provide cross-platform graphics that look identical on any supported platform. This chapter explores how to write beautiful applications for multiple platforms with Fyne. You will learn how to build a simple multi-platform graphical application using the Fyne toolkit through examples and illustrations.

 

 

Section 4: Growing and Distributing your Application

Chapter 11, Navigation and Multiple Windows, covers the workflows and growing complexity of expanding a graphical application. As well as planning and presenting a clear navigation and workflow, it also covers how to manage multiple windows, dialogs, and application instances. It also explores the differences between how desktop operating systems consider application life cycles, and how this may impact your application design. After completing this chapter, you will be confident in how to adapt your application design as you expand its functionality.

Chapter 12Concurrency, Networking, and Cloud Services, explains how more advanced aspects of large application programming fit within a graphical Go application. We cover concurrency and networking, looking at how to work with goroutines and long-running threads, remote resources, and how to handle the user impact of unreliable network conditions. Additionally, you will learn how to connect with and utilize cloud services to provide a rich user experience, both online and offline.

Chapter 13, Best Practices in Go GUI Development, illustrates that the Go language comes with a well-understood set of best practices, covering features such as style, documentation, and code structure. In this chapter, you will learn how to apply these to the development of graphical applications, and which additional practices are recommended. You will learn how the toolkits described in the previous chapters agree on topics such as binary packaging and managing platform specific code.

Chapter 14, Distributing your Application, shows how distribution of applications for multiple platforms is a challenge, but it's important that your users have a seamless experience. In this final chapter, you will learn how to package your application and its assets for consistent distribution across the operating systems you target. We will explore the various options for app-store or marketplace deployment, along with how to deliver direct downloads. At the end of this chapter, you should have the knowledge to design, build, and distribute your graphical application using the Go language.

To get the most out of this book

A basic knowledge of the Go language is assumed throughout this book. If you are not yet familiar with its basic concepts, consider running through the online tutorial before you begin reading (tour.golang.org).

 

 

To benefit the most from later chapters, it would be ideal if you have in mind a particular application you are working on or would like to build. Applying the frameworks and tools used in this book to a particular project will aid your understanding of the various concepts. Additionally, this will deliver the benefit of you completing your project and preparing it for distribution.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-GUI-Application-Development-in-Go/. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

html, body, #map {
 height: 100%; 
 margin: 0;
 padding: 0
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

[default]
exten => s,1,Dial(Zap/1|30)
exten => s,2,Voicemail(u100)
exten => s,102,Voicemail(b100)
exten => i,1,Voicemail(s0)

Any command-line input or output is written as follows:

$ mkdir css
$ cd css

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.