Xforms Marries Perl
As you have seen in various recent issues of Linux Journal, the Xforms library allows you to add a powerful GUI to your C or C++ programs using a simple, intuitive API. The functionality and elegance of Xforms GUI is comparable to Motif's, yet the Xforms libraries are free if used non-commercially. Thanks to Martin Bartlett (email@example.com), the Xforms' GUI can be used from Perl scripts to run complicated graphical applications or to provide a simple “please wait while loading” status bar so the user doesn't get bored waiting (see Figure 1). This article will discuss how to install Xforms4Perl (version 0.5) and how to write a simple address book program with it.
In order to install Xforms4Perl, first you must have installed the following:
Perl version 5.003 (or higher), compiled to load libraries dynamically.
XForms Library, version 0.86 or 0.88, which can be found at http://bragg.phys.uwm.edu/xforms.
Next you need to obtain the source code for Xforms4Perl, which you can do from either the author's primary site, ftp://ftp.demon.co.uk/pub/perl/perl/, or any of the CPAN mirror sites under the directory /authors/Martin_Bartlett/. You can also get an RPM from ftp://ftp.redhat.com/pub/contrib or CPAN, and skip the next few sections.
Once you have Xforms4Perl downloaded, unpack it into a convenient directory (i.e., /usr/local/src) using tar zxvf Xforms4Perl-0.8.4tgz. This command creates the subdirectory Xforms4Perl-0.8.4.
Xforms allows for the support of OpenGL, and if you want to access it from Xforms4Perl, or if you need to modify some default paths or library locations, you will need to edit the Makefile.PL files located in the subdirectories X11/XEvent, X11/XFontStruct and X11/Xforms.
Then enter the X11 subdirectory and do the following:
Type perl Makefile.PL.
Type make install (as root).
Copy fd2Perl to a directory that is in your PATH.
Once installation is complete, you can then start writing Perl code which uses Xforms. You might also check out some of the demos that come with PerlXForms, such as the author's XFtool which is similar to the Microsoft Office Toolbar. The rest of this article assumes you have an existing fundamental understanding of Xforms and Perl, although both are so easy to use you can probably pick them up from looking at a few examples.
In order to help explain how to use the Xforms4Perl Library, I will use as an example the development of a simple phone book application from start to finish. The best place to start is with the fdesign application that comes with the Xforms library. It allows you to build the components of your application visually. Rather than trying to figure out if your button should be 33 by 55 pixels or 30 by 50 pixels, you just draw it how you want it, and fdesign deals with all the numbers and details. In order to make things even easier, fdesign is able to output Perl code (thanks to the fd2Perl script mentioned above). We invoke fdesign as fdesign -perl, and create a new form called “list” (see Figure 2).
First, we add an object called browser where the phone book name entries get indexed. Under the attributes section, we specify that we want this to be a HOLD_BROWSER, which allows a selection from the browser to remain highlighted after selection. Then we give it an obvious name, such as browser, and set up a callback function. This function will be executed when some action takes place in the browser—using callback functions is fairly standard in programming GUIs. We randomly pick the name browser_clicked for the callback function.
We now add five text input fields, all with the same callback function, named data_change. These fields will display the personal information from the phone book entries and are also the locations where the user can make data modifications. These fields are labeled and given the following names in the attributes section:
Next, we add four buttons. A pull-down menu could have been used here, but four buttons shouldn't clutter the interface and will be easier to access than a menu. The buttons are labeled “Quit!”, “Clear”, “Update” and “Delete Entry”. The purpose of the Quit button should be obvious. The Clear button is used to clear the text input fields, the Update button is used to save or update whatever is in the text input fields, and the Delete Entry button is used to remove the selected entry from the browser listing. These buttons each have a callback, as listed below.
Finally, we can add a title such as “PhoneBook” or anything else to improve the appearance, which is quite simple to do using fdesign—you just place it and you're done. I also thought it might be nice to give some of the buttons a shadow effect, which is done from the respective button's attributes menu.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- The Italian Army Switches to LibreOffice
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Linux Mint 18
- Oracle vs. Google: Round 2
- The FBI and the Mozilla Foundation Lock Horns over Known Security Hole
- Devuan Beta Release
- Varnish Software's Varnish Massive Storage Engine
- Privacy and the New Math
- Ben Rady's Serverless Single Page Apps (The Pragmatic Programmers)
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide