GNU TeXmacsUser manualReferenceAboutEnglish
Forms

As explained in “Dialogs and composite widgets” the available widgets can be used to compose dialog windows which perform one simple task. But sometimes one needs to read complex input from the user and forms provide one mechanism to do this. They allow you to define multiple named fields of several types, whose values are stored in a hash table. The contents of this hash can be retrieved when the user clicks a button using the functions form-fields and form-values.

In the following example you can see that the syntax is pretty much the same as for regular widgets, but you must prefix the keywords with form- :

Scheme]

(tm-widget (form3 cmd)

(resize "500px" "500px"

(padded

(form "Test"

(aligned

(item (text "Input:")

(form-input "fieldname1" "string" '("one") "1w"))

(item === ===)

(item (text "Enum:")

(form-enum "fieldname2" '("one" "two" "three") "two" "1w"))

(item === ===)

(item (text "Choice:")

(form-choice "fieldname3" '("one" "two" "three") "one"))

(item === ===)

(item (text "Choices:")

(form-choices "fieldname4"

'("one" "two" "three")

'("one" "two"))))

(bottom-buttons

("Cancel" (cmd "cancel")) >>

("Ok"

(display* (form-fields) " -> " (form-values) "\n")

(cmd "ok")))))))

Scheme]

(dialogue-window form3 (lambda (x) (display* x "\n")) "Test of form3")

The available form fields are (form-input field type proposals width), (form-enum field vals val width), (form-choice field vals val), (form-choices field vals selected) and (form-toggle field on?). They take the same arguments as input, enum, choice, choices and toggle, except that the command is replaced by the name of the field. Other widgets can be freely mixed with the fields inside a form.

Inside the form, (form-fields) returns the list of field names, (form-values) the list of their current values, (form-ref field) the value of one field and (form-set field value) changes it. The values are stored in a global table under the name of the form and of the field; when the form is built, each field is initialized with its default value (the first proposal, resp. the selected value), except for toggles, whose value is only set when they are clicked. These macros are defined in

gui-markup.scm

.

Permission is granted to copy, distribute and/or modify this˙document under the terms of the GNU Free Documentation License, Version 1.1 or˙any later version published by the Free Software Foundation; with no Invariant˙Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of˙the license is included in the section entitled "GNU Free Documentation License".