Perl applets extend a platform-independent desktop panel
Games for Speculators
![© cornelius, Fotolia © cornelius, Fotolia](/var/linux_magazin/storage/images/linux-magazine.com/issues/2009/101/games-for-speculators/fo_3379238_stadion_cornelius.png/427265-1-eng-US/fo_3379238_stadion_cornelius.png_medium.png)
© cornelius, Fotolia
One panel has a neat collection of applets and another has spectacular looks – but a combination of the two is rare. Now help draws nigh for the desktop: PerlPanel is extensible with do-it-yourself widgets.
Regardless of whether you use Gnome or KDE, every desktop offers panels. They dock at the bottom or top of your screen, giving a home to menus and icons for launching programs, showing active applications in taskbars, or helping you switch between virtual desktops. The aim of the PerlPanel project is to use Perl to provide a platform-independent panel. At the same time, PerlPanel aims to let users add their own applets, simply by hashing up a couple of scripts.
Trial Run
On Ubuntu, you can install PerlPanel and the Perl modules on which it depends by typing sudo apt-get install perlpanel at the command line. To take it for a trial run, type /usr/bin/perlpanel. Figure 1 shows the panel GUI at the bottom of the desktop.
If the space at the bottom of the screen is already occupied by another panel, you can move it to the right or left border, or just ditch it if you feel brave enough to burn some bridges behind you.
"Ticker" Widget
If you would like to keep track of share prices, a standard application might not be the best option for you as share price ticker windows tend to hide other applications. Instead, a panel applet might be the ideal choice for the budding investor as it lets you keep a constant eye on the latest share price developments, no matter which application you are currently working with. To allow this to happen, the applet checks the share prices you are interested in by querying Yahoo Finance every 5 minutes and displays the results on screen (the ticker symbols to watch are stored in a local configuration file, ~/.ticker-rc, in your home directory). The applet ignores comment and empty lines in the configuration file and expects a ticker symbol in every line. Figure 1 shows the applet display for selected prices in the panel on the desktop.
The getquote script in Listing 1 queries the Yahoo server to reel in share prices; it expects a list of share symbols on the command line, and outputs the latest share prices line by line. The applet code proper is shown in Listing 2, Ticker.pm. The applet simply parses the configuration file, calls the getquote script at five minute intervals, and refreshes the display in the PerlPanel with the returned values. If an impatient user clicks the applet instead, it assumes they can't wait until the next update; in this case, the applet rushes off to ask the Yahoo server and updates the panel display straight away.
Listing 1
getquote
Get Those Quotes!
The share symbols passed in to getquote at the command line are stored in the @ARGV array in typical Perl style. The getcustomquote function in the Finance::YahooQuote module retrieves the share prices from the Yahoo server, specifying that it is only interested in the fields Symbol (the share name symbol specified at the command line), and Last Trade (Price Only). Without this restriction, Yahoo would return a whole bunch of data the applet doesn't need at every getquote call, so it's better to say up front what you need and what you don't.
If a transmission error occurs, a single value with an error message is returned; if the query is successful, Yahoo returns an array whose entries are pointers to arrays with the symbol and last trade values. Line 18 checks if the returned results really are two-column entries and bails out immediately if not. Line 5 sets a timeout of 60 seconds; if a network error occurs, this will prevent the script from waiting for ever. Share prices that reach the script are sent to its standard output by the for loop in Line 23. and formatted as Symbol Last-Trade on every line of output.
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.