The jprompts.tcl library is distributed as part of the jstools package. It provides procedures for asking the user for information of various kinds. (Two of the procedures, j:prompt_tcl and j:prompt_unix, actually do something with the information; the others just return it.)
This document describes jprompts.tcl version 4.0/4.0.
In order to use the jprompts.tcl library, it (and any other libraries it depends on) must be in your Tcl auto_path, described in tclvars(n). Information about how to arrange that, and other conventions common to the jstools libraries, is in the Usage section of The jstools Libraries.
Jay Sekora
js@calumet.org
http://shore.net/~js/
Thanks
j:prompt_colour_rgb is an eviscerated version of selcol.tcl by Sam Shen <sls@aero.org>, which also lets you choose HSV values.
The library is copyright © 1992-1995 by Jay Sekora, but may be freely redistributed under the conditions at the top of the file.
j:prompt - prompt the user for information
j:prompt_tcl - prompt for a Tcl command and execute it
j:prompt_unix - prompt for a Unix command and execute it
j:prompt_colour_name - prompt for a colour name
j:prompt_colour_rgb - prompt for a colour RGB value
j:prompt_font - prompt for a font (via xfontsel(1))
j:prompt [options]
-text text (localisable, default Enter a value:)
-default default (default {})
-cancelvalue cancel (default {})
-file bool (default 0)
-title title (localisable, default Prompt)
set new_name [j:prompt \
-text "Enter a new name for $file." -file 1]
if {$new_name != ""} {
exec mv $file $new_name
}
This procedure creates a panel that asks the user to type in some information. The panel will have a message widget displaying text, an entry whose initial contents are default, and two buttons labelled OK and Cancel. Clicking OK (or pressing Return) will return the current contents of the entry; clicking Cancel will return the value of cancel (the null string by default).
If -file 1 is specified, then pressing the Tab key in the entry widget will do filename completion using j:expand_filename in jprefixmatch.tcl. Note that j:fs in jfs.tcl may often be a better choice when you want to ask the user for a filename.
If title is specified, it will be the title of the panel, for use by the window manager.
j:prompt_colour_name [options]
-prompt prompt (localisable, default Choose a colour:)
-title title (localisable, default Colour Name Selector)
This procedure creates a panel that asks the user to choose a colour by name from a listbox. At the top of the panel is a label displaying prompt; to the left is a listbox with colour names taken from the file /usr/lib/X11/rgb.txt (and a scrollbar), in the lower right is an OK button, and on the right is a large patch of the current colour.
Singleclicking on a colour in the listbox changes the colour of the patch, and doubleclicking on a colour name or clicking OK dismisses the panel and causes j:prompt_colour_name to return the selected colour. If the user clicks OK before selecting a colour, bisque will be returned.
If title is specified, it will be the title of the panel, for use by the window manager.
If /usr/lib/X11/rgb.txt doesn't exist, the listbox will contain a short (and arbitrary) hardwired list of colours.
This procedure also works if you call it j:prompt_color_name.
j:prompt_colour_name [options]
-prompt prompt (localisable, default Choose a colour:)
-title title (localisable, default RGB Colour Selector)
This procedure creates a panel that asks the user to choose a colour by adjusting component red, green, and blue values with three sliders. At the top of the panel is a label displaying prompt; to the left are the three sliders, to the right is a patch of the current colour and a small label displaying the current colour in X Windows' hexadecimal notation, and in the bottom right is an OK button. Adjusting the sliders changes the current colour (reflected in the patch on the right), and clicking OK dismisses the panel and causes j:prompt_colour_name to return the current colour.
If title is specified, it will be the title of the panel, for use by the window manager.
This is an eviscerated version of Sam Shen <sls@aero.org>'s selcol.tcl routine, which supports choosing a colour by HSV as well as RGB values.
This procedure also works if you call it j:prompt_color_rgb.
j:prompt_font [options]
-prompt prompt (localisable, default Font:, but currently ignored)
-pattern pattern (default *)
This procedure uses the xfontsel(1X11) application to allow the user to choose a font. It simply invokes `xfontsel -pattern pattern -print', and returns the output of xfontsel. The prompt option is currently ignored.
j:prompt_tcl
This procedure pops up a j:prompt panel asking the user for a Tcl command, and evaluates it (in the current context).
j:prompt_unix
This procedure pops up a j:prompt panel asking the user for a Unix command, and executes it. If the command produces any output, that is displayed in a separate panel, otherwise an alert box informs the user that there was no output.
Any output to standard error while executing the command will cause the tkerror(n) procedure to be invoked; the default tkerror procedure puts up a dialogue box displaying the error message.
It would be nice to be able to use HSV mode to select colours. I don't include that part of Sam's code because I had trouble making it work reliably.
Using xfontsel(1X11) means that the user might not have enough information in front of hir on the screen to figure out what sie's being asked to do.
j:prompt_tcl (and possibly j:prompt_unix) should set up some variables to refer to things like the current window and the current application name. It's hard to do this in a sufficiently general fashion, though.
I want to write a complete fontselection panel in Tk, to replace the use of xfontsel(1X11). That should make font selection a lot more intuitive.