Programming with the Gambas Basic IDE
Back to Basic
Gambas is a fast and easy tool for writing graphical desktop applications in Basic.
If you owned a home computer in the 1980s, you are probably familiar with the Basic programming language. Basic survived into the age of the Windows PC; however, the language was never as popular on Linux, which comes with several powerful alternatives. Projects such as HBasic [1] or wxBasic [2] showed much promise but didn't survive for long in the wild. KBasic [3], which was originally designed to provide a Basic environment for KDE, still exists as a commercial program for Linux, Mac OS X, and Windows. RealBasic is another commercial, closed source development environment for Linux, Windows, and the Mac OS.
One free alternative for Basic in Linux, Gambas [4], has continued to gain ground in the past few years and has gathered quite a large developer community. Designed as an integrated development environment, Gambas helps developers write programs with a graphical user interface. It supports the deployment of Gtk+ [5] (the underpinnings for Gnome, and XFCE) and Qt [6] (the basis for KDE). Gambas currently supports Qt 3, but not the more recent Qt 4. The IDE runs on Linux only, and the roadmap does not currently include ports to other operating systems.
The developers place much emphasis on making sure no one sees Gambas as a Microsoft Visual Basic clone, from which it differs in various details. However, if you have previous knowledge of Visual Basic, you should have no difficulty finding your way around Gambas – especially considering the documentation explains the differences between the two languages.
The developers completed Gambas 2.0 early in 2008 after four years of work; development has been rapid since then. In early April, version 2.5.0 introduced enhanced stability and a number of improvements. Gambas now runs natively on 64-bit systems, unlike version 2.0. In this article, I refer to version 2.5.0 throughout (see the box titled "Installation").
Installation
Gambas is available as a source code archive from the project's SourceForge page. The prepackaged binary includes a number of tools, which you can install via the distribution's own package management system [7]. The system requires several libraries and add-on tools. The installation Help file [8] lists the required programs and provides a HOWTO for the installation on Ubuntu, Mandriva, openSUSE, and Debian. It is important to resolve dependencies to avoid compromising the functionality of Gambas.
If your target system fulfills the dependencies, you can start with the ./reconf-all command in the Gambas source code directory. Then, at the command line, type
./configure -C make su -c "make install"
to build and install the program.
First Start-Up
When you launch Gambas, you will see a dialog that lets you open an existing project or create a new one (Figure 1). A list of recently modified projects appears on the right side of the dialog.
If you decide to create a new project, a wizard walks you through the required settings in three steps (Figure 2). The first step is to choose the project type. Gambas lets users develop graphical programs with either the Qt toolkit or Gtk, command-line programs, and CGI applications. If necessary, Gambas will also integrate components for database access or image manipulation.
If you decide on a Graphical application project, Gambas will use either the Qt or Gtk toolkit, depending on your desktop – in other words, it adapts to match your choice of environment. The files, forms, source code, and graphics belonging to a project are stored in a directory named for the project.
After selecting or creating a project, go to the main window to write program code (see Figure 3). At the left margin of the window is a panel that displays the files, source code, forms, icons, and other graphics and classes belonging to the project. The documents are stored in a tree structure. Double-clicking an element opens it in the workspace at the center of the program window. By selecting View | Project, you can display the sidebar.
Below the workspace, you will see the Console, where the debugger runs and where you can manage breakpoints. At the top right side of the program window, you will see the Properties window, where you can configure the properties of the selected interface objective.
Below this is a Toolbox with controls for designing graphical interfaces.
The Gambas source code editor has all the functionality you would expect from this kind of program: Syntax highlighting is helpful, as are functions for hiding and displaying code blocks, and auto-completion is available. This means you can click to hide a whole program section. Just as with other editors, the software lets you tile the window horizontally or vertically.
The form editor has the usual controls, which you can position precisely on the desktop thanks to a grid. A menu editor facilitates menu design. Selecting Menu editor… in the drop-down menu for a form, or pressing Ctrl+E, launches the editor (Figure 4). The editor allows programmers a way to manipulate, move, or nest menu structure elements. Keyboard shortcuts are also easily defined.
Widgets
Depending on your choice of toolkit, the toolbox will offer you a number of different widgets. The usual suspects, such as text boxes, labels, selection boxes, and buttons, are predefined, as are image and video boxes for displaying corresponding content. Date and time selection dialogs, color pickers, and directory, file, and font managers complete the toolbox.
An HTML output control lets programmers create a miniature browser for HTML-based Help texts in next to no time (Figure 5). Gambas includes a sample program on which you can base your own projects.
Mastering Databases
Gambas supports access to various databases and database servers. The IDE offers controls for connecting to MySQL and PostgreSQL. Support is available for file-based SQLite, SQLite2, and SQLite3 databases, as well as for ODBC access. To facilitate database access, Gambas includes a Database Manager, which lets users manage connections to various servers and data repositories. To open the manager, select Tools | Database Manager (Figure 6) in the menu.
The wizard prompts you to enter the administrator password for the server before going on to contact the host. Databases are listed in a tree structure on the left of the manager window. The program helps you set up and modify tables, SQL queries, and database users.
After establishing the database connection, access to the database itself is simple: Gambas gives you several database access controls, which you can simply drop into a form. The widgets are available in the toolbox's Data tab.
The DataBrowser lets you scroll inside a database table. The elements also let users add and delete records. To do so, it displays a toolbox with buttons for navigating the data, creating records, and deleting records.
The DataView element adds the ability to create tables from the data, whereas the DataCombo element provides a combobox that lets users select a record from a table on the basis of a single field. Gambas has a very intuitive approach to widget deployment, a fact that really takes the pain out of database-enabled applications.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.