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.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- SUSE LLC's SUSE Manager
- My +1 Sword of Productivity
- Non-Linux FOSS: Caffeine!
- Managing Linux Using Puppet
- Tech Tip: Really Simple HTTP Server with Python
- Parsing an RSS News Feed with a Bash Script
- Google's SwiftShader Released
- SuperTuxKart 0.9.2 Released
- Doing for User Space What We Did for Kernel Space
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide