QobiScheme UI
This egg is a port of the QobiScheme UI to Chicken. examples/define-application-example.scm provides an example of a UI. One minor incompatibility with QobiScheme is that abort is renamed to abort-gui to avoid a name clash with Chicken.
Commandline
- (define-command (function-name {arguments}) {expression}+)
define-command is slightly incompatible with QobiScheme's implementation. It expects arguments to be passed to it directly rather than through a list and it does not require the program name. It also fixes a bug where repeated arguments were provided in the wrong order.
{arguments} ::= {keyword}* {required}* {optional}* [{rest}] {rest} ::= (rest {defaulted-argument}) {optional} ::= (optional {defaulted-argument}) {required} ::= (required {defaulted-argument}) {keyword} ::= (any-number {defaulted-keyword}*) | (at-most-one {defaulted-keyword}*) | (at-least-one {defaulted-keyword}+) | (exactly-one {defaulted-keyword}+) {defaulted-keyword} ::= ({name} {supplied?} {defaulted-argument}*) {defaulted-argument} ::= ({variable} {doc} {type} {default}) {type} ::= integer-argument | real-argument | string-argument
{name} and {doc} are strings. {doc} is only used for documentation. There can't be a {name} "usage" or "help". -usage and -help are created automatically. All of the {variable}s and {supplied?}s must be distinct. All of the {name}s must be distinct.
Note that any-number, at-least-one, rest, and required allow nondefaulted-keywords. This is to keep backward compatibility with QobiScheme but this version encourages using {defaulted-argument}s everywhere for simplicity.
You can define new {type}s as:
(lambda (string) (if (ok? string) (string->value string) (usage {doc})))
An example that should make everything clear:
(define-command (main (exactly-one ("file" file? (file "file" string-argument "")) ("other-file" other-file? (arg1 "pathname" string-argument "") (arg2 "version" real-argument 0))) (at-most-one ("flag" flag?)) (any-number ("more" more? (more "more" string-argument ""))) (at-least-one ("alt" alt? (alt-arg "arg" string-argument ""))) (required (needed "needed" string-argument "")) (optional (maybe "maybe" string-argument "")) (optional (another-maybe "another-maybe" string-argument "")) (rest (everything "everything" string-argument))) (pp (list file? file other-file? arg1 arg2 flag? more? more alt? alt-arg needed maybe another-maybe everything))(newline))
(apply main command-line-arguments)
Without arguments, with incorrect arguments, with -usage, or -help this will print:
usage: csi [-file file|-other-file pathname version] [-flag] [-more more]* [-alt arg]+ needed [maybe [another-maybe [everything]*]]
Graphical UI
- (define-application display-pane-width display-pane-height transcript-lines button-rows button-columns pre-initialize-procedure post-initialize-procedure finalize-procedure redraw-procedure listener-procedure)
The GUI is composed of different regions: at the top we have buttons in the button pane, the main content of the application is displayed below in the display pane, below that are the transcript pane and echo pane which are used to output and input text, and at the bottom we have the status pane on the left and message pane on the right. Each pane is an X window embedded in the main X window of the application.
The display-pane-width and display-pane-height are in pixel units. When width is #f other arguments will determine the width of the application. The other panes automatically adjust their sizes. transcript-lines defines the number of lines in the transcript pane, can be #f. button-rows and button-columns set the size of the button grid in the button pane. Buttons will be automatically sized to take up the appropriate amount of space.
All the following procedures take no arguments. pre-initialize-procedure code to run before the application is ready. This is typically where you define UI elements. post-initialize-procedure code to run right after the UI is ready. finalize-procedure runs after the UI exists. redraw-procedure runs as needed to redraw the UI. listener-procedure runs when return is pressed in the transcript pane.
(use qobischeme-ui) (define-application main #f 480 5 2 6 (lambda () (define-button 0 0 "Help" #f help-command) (define-button 5 0 "Quit" #f quit-gui) (define-radio-buttons *object* (lambda () #f) (1 0 line-segment "Line") (2 0 ellipse "Ellipse")) (define-toggle-button 0 1 "Flag" *flag?* (lambda () (say (format #f "Flag=~s" *flag?*)))) (define-cycle-button 1 1 *mode* (lambda () (say (format #f "Mode=~s" *mode*))) (a "A") (b "B") (c "C")) (define-integer-range-buttons 2 1 3 1 *k* 0 9 (lambda () (format #f "-K ~s" *k*)) (lambda () (format #f "+K ~s" *k*)) (lambda () (say (format #f "K=~s" *k*)))) (define-key (list (control #\x) (control #\c)) "Quit" quit-gui) (define-key (control #\h) "Help" help-command)) (lambda () #f) (lambda () #f) (lambda () #f)) (main '())
- (define-display-pane-application display-pane-width display-pane-height pre-initialize-procedure post-initialize-procedure finalize-procedure redraw-procedure)
High-level UI
- (xremove-expose-events)
- (say string)
- (status string)
- (message string)
- (redraw-buttons)
- (redraw-display-pane)
- (redraw-transcript-pane)
- (redraw-echo-pane)
- (redraw-status-pane)
- (redraw-message-pane)
- (define-button-specific-region button state-mask state x y width height method)
- (define-button column row name bold?-procedure method)
- (define-sized-button x y size offset text-procedure bold?-procedure method)
- (define-toggle-button column row name variable method)
- (define-radio-buttons variable method (column row symbol string)+)
- (define-cycle-button column row variable method (symblol text)+)
- (define-integer-range-buttons column1 row1 column2 row2 variable min max name1 name2 method)
- (define-spinner-buttons row column name f-up f-down f-print)
- (quit-gui)
- (abort-gui)
- (pnm->pixmap pnm)
- (free-pixmap pixmap)
- (draw-pixmap pixmap x y)
- (draw-clickable-pixmap-from-pnm pixmap pnm x y scale handler)
- (define-key character documentation command)
- (control character)
- (meta character)
- (define-region x y width height method)
- (tracking-pointer twice? press? tracker)
- (define-structure tree-node width height offset text bold? procedure daughters)
- (tree->tree-node tree)
- (draw-tree-node tree-node x y)
- (tree-height tree)
- (draw-tree tree x y)
- (define-structure alist-node width height offset keys values)
- (alist->alist-node alist)
- (draw-alist-node alist-node x y)
- (alist-height alist)
- (draw-alist alist x y)
- (help-command)
- (help-scroll-up-line-command)
- (help-scroll-down-line-command)
- (help-scroll-up-page-command)
- (help-scroll-down-page-command)
- (help-scroll-beginning-command)
- (help-scroll-end-command)
- (draw-ellipse display drawable gc ellipse)
- (draw-clickable-strings-with-scroll-bar first-line set-first-line! left middle right strings xmin xmax ymin ymax)
- (draw-clickable-strings-with-optional-scroll-bar first-line set-first-line! left middle right strings xmin xmax ymin ymax font font-gc-f)
Low-level UI
- (set-background-task-enabler! procedure)
- (set-background-task-disabler! procedure)
- (pause)
- (set-pause! p)
- (process-events)
- (set-window-method! window event-type method)
- (send window event-type . &rest)
Misc
- (define stalin? #f)
- (char-alphanumeric? char)
- (beginning-of-word? string position)
- (end-of-word? string position)
- (string-backward-word string position)
- (string-kill-word string position)
- (string-forward-word string position)
- (string-backward-kill-word string position)
- (string-insert-character character)
- (string-beginning-of-line string position)
- (string-backward-char string position)
- (string-delete-char string position)
- (string-end-of-line string position)
- (string-forward-char string position)
- (string-kill-line string position)
- (string-backward-delete-char string position)
- (define *frame-rate* 30.0)
- (pnm-movie->pixmaps pnm-movie)
- (draw-pixmaps pixmaps x y)
- (free-pixmaps pixmaps)
- (echo-pane-command editor)
- (echo-pane-insert-character-command character)
- (echo-pane-beginning-of-line-command)
- (echo-pane-backward-char-command)
- (echo-pane-delete-char-command)
- (echo-pane-end-of-line-command)
- (echo-pane-forward-char-command)
- (echo-pane-kill-line-command)
- (echo-pane-backward-delete-char-command)
- (echo-pane-backward-word-command)
- (echo-pane-kill-word-command)
- (echo-pane-command string-kill-word)
- (echo-pane-forward-word-command)
- (echo-pane-backward-kill-word-command)
- (abort?)
- (character->pretty-name character)
- (prefix-string prefix)
- (region-handler x y button state)
- (define-structure region button state-mask state x y width height method)
- (allocate-color-cube! reds greens blues)
- (abort-command)
- (kill-application)
- (set-kill-application! procedure)
License
Written by Jeffrey Mark Siskind and part of QobiScheme.
Maintainer: Andrei Barbu, andrei@0xab.com
Copyright 1993-1995 University of Toronto. All rights reserved. Copyright 1996 Technion. All rights reserved. Copyright 1996 and 1997 University of Vermont. All rights reserved. Copyright 1997-2001 NEC Research Institute, Inc. All rights reserved. Copyright 2002-2013 Purdue University. All rights reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses.