Graphical Applications Using MetaCard
Backtracking a little, before you can write a script, you need to create an object to attach the script to. MetaCard applications are composed of one or more stacks, each of which has one or more cards. The metaphor (inherited from HyperCard) is of a stack of index cards, but you can also think of it as being pages in a book, slides in a presentation or the frames in a movie or video. The stacks are stored as binary files similar to the resource files used on the Mac and Windows. But in addition to object descriptions, data such as the state of buttons and the text in fields is also stored in these files.
The objects are created, sized and positioned using MetaCard's IDE (Integrated Development Environment). To start building a new application window, choose “New Stack” from the File menu (the first card is created automatically with the stack). Then choose tools from the tool bar and draw the fields and buttons you need. See Figure 1 for a screen snapshot of the MetaCard top application.
After creating the stack and the controls in it, you can add scripts to the stack, cards and/or controls. Normally each object has its own script, but I've put all of the handlers for the top program in the card script. This means that the mouseUp handler (see Listing 3) is a little unusual, since it gets called through the message-passing hierarchy: messages not handled by an object can be handled by objects higher up in the hierarchy. In this case, a handler in the card script handles messages sent to any of the controls on the card.
Writing one big handler instead of a bunch of small ones usually means you have to figure out which object the message was originally sent to. The target function supplies this information. The target function returns an object that you can get the properties of or send messages to. This mouseUp handler also shows off the MetaCard switch control structure:
The “Kill Process” case is executed when the user clicks on the “Kill Process” button. This section gets the PID of the process from the selected line in field and uses the MetaTalk kill command to kill it.
The “Set Update Interval...” section prompts the user for the new updateinterval value using the ask dialog, verifies that the value is a number and tells the user that it must be if it isn't. The ask and answer dialogs are built into MetaCard and are quick and easy ways to get simple responses from the user. If the new data checks out OK, the handler cancels the current timer and then calls the updatelist handler to restart it.
The “toplist” case will be executed when the user clicks on a line in the main field. This case enables the “Kill Process” button and suppresses updates for 5 seconds, allowing the user time to kill the process before the selection is cleared when the field is next updated.
Listing 4 shows the handlers for the stack-oriented messages, including those sent when the stack opens and closes and is iconified and uniconfied. Remember the goal of having the application go to sleep when it is iconified.
MetaCard doesn't have a constraint-based geometry system, so you must write scripts to handle resizing and repositioning controls when a stack window is resized. The resizeStack message handler that does this geometry management is shown in Listing 2. Using the IDE, I set the stack properties such that the stack is not resizable in width, only in height (since you need to be able to see all fields). So this handler only has to resize the main field vertically and reposition the buttons along the bottom edge of the display. This simple four-statement handler reliably handles the task without triggering the time-consuming trial-and-error phase of development required to get a constraint-based system working correctly.
Running the MetaCard version of top takes about twice as much CPU time as the character-based version (6% vs. 3% on a Pentium 90 running Linux 1.2.13). This is a typical result, since a well-written MetaCard script generally runs 2 to 4 times slower than a comparable C program. Of course, the MetaCard version only took a fraction of time to develop. And because it is so much smaller, it will take far less time and effort to maintain and customize. The character-based top program is written in C and is about 10 times as long. Memory usage for the MetaCard version of top is considerably less than the total of the character-based top program added to the memory needed for the xterm and the extra bash process required to run it.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- RSS Feeds
- What's the tweeting protocol?
- New Products
- Trying to Tame the Tablet
- Dart: a New Web Programming Experience
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.





14 hours 59 min ago
17 hours 31 min ago
18 hours 48 min ago
19 hours 23 min ago
19 hours 46 min ago
1 day 34 min ago
1 day 1 hour ago
1 day 2 hours ago
1 day 4 hours ago
1 day 6 hours ago