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.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
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
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| 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 |
Enter to Win an Adafruit Pi Cobbler Breakout 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 Pi Cobbler Breakout 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
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?





3 hours 41 min ago
3 hours 41 min ago
5 hours 41 min ago
14 hours 27 min ago
15 hours 1 min ago
15 hours 59 min ago
16 hours 50 min ago
20 hours 52 min ago
1 day 39 min ago
1 day 47 min ago