ZDNet UK


Skip to Main Content

ZDNet.co.uk - Winner of Best Business Website 2007
  1. Home
  2. News
  3. Blogs
  4. Reviews
  5. Jobs
  6. Resources
  7. Community
  8. My ZDNet

 

ZDNet UK RSS Feeds


Application development Toolkit

Mandrake Drak tools made easy

Stew Benedict Builder.com

Published: 17 Oct 2002 11:49 BST

  • Email
  • Trackback
  • Clip Link
  • Print friendly
  • Post Comment

As Linux has become more popular, distributors have tried to put a more friendly face on the underlying complexity of the operating system. Most vendors offer configuration tools that guide users through the process of editing config files so they don't have to do it by hand.

An interesting feature of the Mandrake configuration tools (also known as drak tools) is that many of them can be used in either console mode or in X (the Linux GUI). One of the most useful drak tools is libDrakx, which is the Mandrake add-on to perl-GTK. Part of the drakxtools-newt package, libDrakx offers some custom commands and behaves correctly in console or X. It includes both the core set of Mandrake's configuration tools and the includes you need to build a new tool. I will walk you through how you can use libDrakx to create your own user interfaces.

Overview of libDrakx
A standard Mandrake install includes drakxtools-newt, which offers a good portion of the underlying code needed to create the dual interface. A number of common routines used by the Mandrake developers come from perl-MDK-Common. The X GUI functionality is provided by perl-GTK, while the console display is handled by libnewt. If you've been involved with Linux for any length of time and remember the old Slackware dialog-based installer, you'll find that the newt interface is similar. The Mandrake installer uses this same toolset to offer both a GUI and text-based installer.

A simple example
Let's start with something basic. The application in Listing A displays a prompt and an OK button, which closes the program. As you can see in Figure A and Figure B, the user is presented with essentially the same interface, whether at the console or using the GUI.

Figure A

Figure B

Looks simple enough. But how does this work? Let's walk through the code, line by line.

  • Line 1: This is a standard Perl script header.
  • Line 3: We tell Perl to add /usr/lib/libDrakx to the library path.
  • Line 5: interactive pulls in the core of the drak toolkit. We'll cover this in more detail later.
  • Line 6: Again, this is standard Perl; strict just enforces strict variable, reference, and subroutine rules when your code is passed to the Perl interpreter.
  • Line 8: We're creating a new user interface.
  • Line 10: ask_warn is a simple message with an OK button. The first argument is the window title, and the second is the displayed message. The "_(" format is not required, but MandrakeSoft uses it to facilitate integrating language translation files so the text is displayed in the user's native language based on the system locale configuration.
  • Line 12: This just closes out the UI.

The $DISPLAY variable in the user's environment determines the graphics mode. If you were to execute the above code while in X, with DISPLAY=:0, you would see the GUI version. If you unset the DISPLAY variable (unset DISPLAY), you would see the text-based version. The decision on how to proceed takes place in /usr/lib/libDrakx/interactive.pm, as shown in Listing B.

Next

Previous

1 2


  • Email
  • Trackback
  • Clip Link
  • Print friendlyPrint with Konica

Did you find this article useful?
37 out of 61 people found this useful


Full Talkback thread

0 comments

Company/Topic Alerts

Create a new alert from the list below:











Discussions

Telic Telic

MacLinux

Friday 10 October 2008, 10:34 PM

5 comments
1000215420 1000215420

Punishment & Deterrent

Friday 10 October 2008, 9:37 PM

4 comments
1000215420 1000215420

Punishment & Deterrent

Friday 10 October 2008, 9:36 PM

4 comments

Featured Talkback

In association with Intel
The fact is: Software developers today are really designers and not coders. The reason that business anlaysts exist today to model solutions is because they understand the value of designing software before writing it. All too often developers create code that has little value because they do not understand that business classes interact with other classes within the confines of a working model or pattern.

By: 1000165269

Read full story:
Making sense of agile modelling