previous next contents | bottom

# Xdialog documentation - FAQ

Xdialog FAQ v1.60, compiled by Thierry Godefroy <xdialog@free.fr>

## FAQ contents:

1. How to recover the output of Xdialog in the Perl script?
2. How to make Xdialog windows to appear at a given position (in absolute coordinates) on the screen ?
3. What are the ways to customize Xdialog windows look for a given script ?
4. How could I make the printer used by Xdialog user-dependant ?
5. Why does the --fill option of Xdialog sometimes fails to make the text fit the boxes ?
6. How to force the use of fixed width fonts in all Xdialog widgets ?
7. How to select hidden files/directories with the file/directory selector ?
8. How to build dynamically a menu using Xdialog ?
9. I just compiled Xdialog but I sometimes get core dumps or segfaults with some menus: what's wrong with it ?
10. Why am I getting Gtk/Gdk/Glib messages mixed up with the results returned by Xdialog ? Can I prevent that from happening?

##
1. How to recover the output of Xdialog in the Perl script?

I found three ways (but there are perhaps more; I'm not a Perl guru !):

a.- Using the "system" command (not the best way IMHO):

Just redirect the Xdialog output into a temp file, then use the "open" command to read the result, put it in a table and use it (here just printing it):

            system('Xdialog --inputbox "Please enter something below:" 0 0 2>/tmp/my_temp_file');
            if ($? == 0) {
                    open(RESULT, "/tmp/my_temp_file");
                    @result=<RESULT>;
                    close(RESULT);
                    print @result;
            }

Finally, destroy the temp file (may be there is a better way to do this...):

    system("rm -f /tmp/my_temp_file");

b.- Using backquotes (just like in "sh": IMHO the best way...):

            $result=`Xdialog --stdout --inputbox "Please enter something below:" 0 0`;
            if ($? == 0) {
                    print $result;
            }

c.- Using "open" and streams (useful if you want the result to be put in a table):

            open(RESULT, 'Xdialog --stdout --inputbox "Please enter something below:" 0 0 |');
            if ($? == 0) {
                    @result=<RESULT>;
                    print @result;
            }
            close(RESULT);

Note the use of --stdout in (b) and (c) so to send the result returned by Xdialog to the proper output stream...

##
2. How to make Xdialog windows to appear at a given position (in absolute coordinates) on the screen ?

There are two ways but the result is not guaranteed as some window managers will simply ignore or override the GTK+ placement requirements and place the windows where they feel like.

Xdialog takes into account the origin coordinates given into a "-geometry"-like parameter; e.g. passing 240x120+150+80 as a size parameter to Xdialog will place its window (which size will be 240x120 pixels) at Xorg=150 and Yorg=80. In this example, you may as well let Xdialog auto-size by passing 0x0+150+80 instead. E.g;:

    Xdialog --title ppp.log --tailbox /var/log/ppp.log 0x0+150+80

b.- Some window manager do allow to place a window with a given title or class name at a given position on the screen. Xdialog therefore provides a way to set its window manager class name through the --wmclass option. E.g.:

    Xdialog --wmclass ppp_log_tailbox --title ppp.log --auto-placement \
            --tailbox /var/log/ppp.log 0 0

Now this Xdialog tailbox is registered with the "ppp_log_tailbox" name. With twm and fvwm(2/95) you will have to edit the .Xdefaults file in your home directory, adding "ppp_log_tailbox*geometry" parameters so to set the Xdialog position and/or size. With sawfish, just move the Xdialog window to the place of your choice, pull down the window manager options menu (clicking on a given button in the Xdialog window title bar or on the title bar itself: this is user configurable and may also depend from your sawfish theme) and choose the "History"/"Remember position" item in the menu; the next time an Xdialog window with a "ppp_log_tailbox" wmclass will be open, it will pop up at the remembered position...

##
3. What are the ways to customize Xdialog windows look for a given script ?

a.- Windows decorations:

Through --wmclass option provided your window manager makes use of the wmclass name of the windows so to decorate them differently. The method is the same as in §3 (just use the Xdialog --wmclass option and RTFM of your window manager; hints: "winoptions" editing for IceWM, window manager option menu use for sawfish, ".Xdefaults" editing for twm/fvwm, etc...).

b.- GTK+ themes:

Xdialog accepts a new --rc-file option. Thanks to this feature Xdialog can be instructed to use a given GTK+ theme (which may therefore be different from the theme currently in use).

c.- User defined icons:

Xdialog accepts the new --icon option that will make a user defined icon to appear on the left of the <text> (for the Xdialog box options using this parameter, the box options without a <text> parameter in their syntax are not taking the --icon option into account).

##
4. How could I make the printer used by Xdialog user-dependant ?

The name of the printer to be used by Xdialog is to be passed after the --print option in the Xdialog command line. Nothing prevents you to make this printer name a variable which will be set via an sh include file. Here is an example of how to do it:

    #!/bin/sh

    # Sample script with per-user costumizable printer name.

    # First set the default printer.
    XDIALOG_PRINTER="lp"

    # Check if the user wants to use its own printer.
    if [ -f ~/.xdialog-printer] ; then
    	. ~/.xdialog-printer
    fi

    Xdialog --print $XDIALOG_PRINTER .../...

Then for each user, the following .xdialog-printer file may be put in its home directory:

    # /home/foo/.xdialog-printer include file for user "foo".

    # Let's use the "bar" printer...
    XDIALOG_PRINTER="bar"

##
5. Why does the --fill option of Xdialog sometimes fails to make the text fit the boxes ?

Because this option must use the GTK+ auto-wrapping mode and alas this only really works when the box auto-sizing feature of GTK+ is used. The work around is therefore to let GTK+ calculate the size of the box by passing a 0x0 (or 0 0) size to Xdialog.

##
6. How to force the use of fixed width fonts in all Xdialog widgets ?

With some scripts written for dialog, some pre-formatted text may appear mis-aligned in Xdialog menus. This is because GTK+ uses proportional fonts while the console tools such as dialog may only use fixed width fonts.

While the --fixed-font intructs Xdialog to use a fixed width font (more exactly a monospacing one) into the text windows of the tailbox, textbox and editbox widgets, the labels and backtitle of Xdialog still use the font defined in the GTK+ theme in force when Xdialog is started. There are two ways around this, by using either the (c)dialog high compatibility mode, or the --rc-file option together with a gtkrc file where the font parameter is set for a monospacing font name. E.g.:

    style 'fixed_font' {
     font = "-*-*-medium-r-normal-*-*-*-*-*-m-70-iso8859-1"
    }
    widget '*' style 'fixed_font'

##
7. How to select hidden files/directories with the file/directory selector ?

In the exact same way as with any software using the GTK+ file selector: type a "." into the text entry field: the hidden files/directories will then be presented into the selector lists, allowing you to select one with the mouse. Also hit CTRL+H to show/hide hidden files...

    Xdialog --fselect "/home/foo/.*" 0 0

##
8. How to build dynamically a menu using Xdialog ?

You may need to build dynamically a menu for some scripts. Although Xdialog does not accept to take its parameters from a file (in which you could put the menu entries), nothing prevents you to build dynamically a sub-script containing a Xdialog command, and then call it from you main script. Take a look to the xlock-wrapper script which uses such a trick.

##
9. I just compiled Xdialog but I sometimes get core dumps or segfaults with some menus: what's wrong with it ?

Probably a bug that needs fixing..

##
10. Why am I getting Gtk/Gdk/Glib messages mixed up with the results returned by Xdialog ? Can I prevent that from happening?

Most probably, you are lacking some fonts for your locale and/or your GTK theme is buggy... You should find out and fix it. This is not a Xdialog bug, please do not report it as such ! For convenience and as a quick hack (to let you the time to fix your system later and yet let you use Xdialog). By setting the XDIALOG_NO_GMSGS environment variable to "TRUE", (or "1"), you may disable all messages sent by GTK/GDK/GLIB. Note, yet, that GNOME may still send such messages (including on stdout)..

previous next contents | top