Mandrake Drak tools made easy

Daily Newsletters

Sign up to ZDNet UK's daily newsletter.

ANALYSIS
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.

Post your comment

In order to post a comment you need to be registered and logged in.

You can also log in with Facebook. Log in or create your ZDNet UK account below

  • Login

Will not be displayed with your comment

By signing up for this service, you indicate that you agree to our Terms and Conditions and have read and understood our Privacy Policy. Questions about membership? Find the answers in the Community FAQ

Get ZDNet UK's daily newsletter

Enter your email address to sign up

ZDNet UK Live

GrueMaster

Nice review and very informative. One thing I'd like to add (in reply to whs001's 1st question), the main reason to have the same interface from...

40 minutes ago by GrueMaster on A tale of two distros: Ubuntu and Linux Mint
Frederick Wrigley

I'be been using Mint 12 since the RC came out, and I am far more happy with the Cinnamon, the Mate, and, yes (with extensions), theGnome 3...

1 hour ago by Frederick Wrigley via Facebook on A tale of two distros: Ubuntu and Linux Mint
bdantas

Excellent article. One small correction, though--although a fresh installation of Linux Mint 12 will, indeed, provide the user with a version of...

2 hours ago by bdantas on A tale of two distros: Ubuntu and Linux Mint
Alan Ralph

In related news, the ISPs club together to get the members of the Home Affairs Select Committee (ya goofed on that part, ZDNet UK) copies of "The...

3 hours ago by Alan Ralph via Facebook on MPs urge ISPs to take down terrorist material
Alan Ralph

In related news, the ISPs club together to get the members of the Home Affairs Select Committee (ya goofed on that part, ZDNet UK) copies of "The...

3 hours ago by Alan Ralph via Facebook on MPs urge ISPs to take down terrorist material
Moley

For Gnome 2 die-hards, it is possible to add icons to the bottom panel (or top top panel, if you prefer) which provide the exact Gnome 2...

3 hours ago by Moley on A tale of two distros: Ubuntu and Linux Mint
ramwellian

Your comments would seem pretty naive and immature. Your 'solution' appears to be, "gee, let's all just give in to the hackers and give them...

4 hours ago by ramwellian on Cloud computing security: no more oxymoron?
BugStalker

"Interesting thought ... If you installed Win7 as a dual boot on a machine that previously only had Linux, and it wrecked your Linux installation,...

4 hours ago by BugStalker on Windows 7 Declares War on GRUB
whs001

This is an excellent summary of Ubuntu and Mint and the interface differences between them. Most such articles take a very partisan position for...

4 hours ago by whs001 on A tale of two distros: Ubuntu and Linux Mint
Moley

@ewallace. Not so clear. Anyone can obtain the text, for example from here http://www.ustr.gov/webfm_send/2379. I support ACTA so long as it and...

4 hours ago by Moley on ACTA: Facts, misconceptions and questions
45283

I think WinRT is fantastic. I just wish it was an option for people that didn't want to go through Microsoft's App Store with its attendant...

7 hours ago by 45283 on Why Windows 8 needs architectural hygiene for WOA
Burn-IT

Nine people? £30m? Who's back pocket is that lot going in? And IF they say it is for new buildings, what about all the ones the government has...

9 hours ago by Burn-IT on Police set to launch three £30m e-crime hubs
ewallace

Just to be clear, nobody knows what is in the text of ACTA, here is a photograph of the text of ACTA http://twitpic.com/8h9iju as submitted to the...

9 hours ago by ewallace on ACTA: Facts, misconceptions and questions
fgvrg56

Unfortunately main issue is that ASUS is refusing to accept that they make some mistake on this version of asus Transformer prime. 1 - GPS sensor...

10 hours ago by fgvrg56 on Asus Eee Pad Transformer Prime Wi-Fi & GPS problems?
Ben Woods

@Marcus A fair question. Just talked with Archos which said it was working on an announcement for next week....

11 hours ago by Ben Woods on Archos confirms G9 Ice Cream Sandwich update schedule
Marcus Karlsson

Any update on this, considering the claimed "first week of February"?

12 hours ago by Marcus Karlsson via Facebook on Archos confirms G9 Ice Cream Sandwich update schedule
apexwm

Bill Goodrich : Just as al_langevin pointed out, with Windows Server 2008 there is no Services for Macintosh anymore. It's gone, not available....

20 hours ago by apexwm on Windows Server 2008 drops the ball for Mac compatibility
txtrainguy

Replying to an old topic that I'm currently facing with my CEO (who is on a Mac). Our servers are primarily Windows Servers, office is about...

1 day ago by txtrainguy on Windows Server 2008 drops the ball for Mac compatibility
k0tcs3

Sure, that makes perfect sense. Pay wrong-doers money and thank them for breaching your security and pointing out your flaws, that would surely...

1 day ago by k0tcs3 on US indicts Romanian over NASA climate change hack
Random_Error

I think he's referring specifically to Android apps, as Apple do regulate their App Store, but Google seem to let any old crap onto the Android store!

1 day ago by Random_Error on RIM: BlackBerry will keep 'garbage' apps out of store

Latest in Application Development