Changeset 29471 in project


Ignore:
Timestamp:
07/30/13 06:26:33 (6 years ago)
Author:
anonymous
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/qobischeme-ui

    r29456 r29471  
    1212Chicken.
    1313
    14 define-command is slightly incompatible with QobiScheme's
     14=== Commandline
     15
     16<procedure>(define-command (function-name {arguments}) {expression}+)</procedure>
     17
     18Define a commandline application. The grammar for arguments and
     19expressions is given below but it might be easier to look at the
     20example instead. ''define-command'' produces error messages which
     21print a usage line and explain why the input is incorrect.
     22
     23''define-command'' is slightly incompatible with QobiScheme's
    1524implementation. It expects arguments to be passed to it directly
    16 rather than through a list and it does not require the program name.
     25rather than through a list and it does not require the program
     26name. It also fixes a bug where repeated arguments were provided in
     27the wrong order.
     28
     29  {arguments} ::= {keyword}* {required}* {optional}* [{rest}]
     30  {rest}     ::= (rest {defaulted-argument})
     31  {optional} ::= (optional {defaulted-argument})
     32  {required} ::= (required {defaulted-argument})
     33  {keyword} ::= (any-number {defaulted-keyword}*)
     34            |   (at-most-one {defaulted-keyword}*)
     35            |   (at-least-one {defaulted-keyword}+)
     36            |   (exactly-one {defaulted-keyword}+)
     37  {defaulted-keyword} ::= ({name} {supplied?} {defaulted-argument}*)
     38  {defaulted-argument} ::= ({variable} {doc} {type} {default})
     39  {type} ::= integer-argument | real-argument | string-argument
     40
     41{name} and {doc} are strings. {doc} is only used for documentation.
     42There can't be a {name} "usage" or "help". ''-usage'' and ''-help''
     43are created automatically. All of the {variable}s and {supplied?}s
     44must be distinct. All of the {name}s must be distinct.
     45
     46Note that ''any-number'', ''at-least-one'', ''rest'', and ''required''
     47allow nondefaulted-keywords. This is to keep backward compatibility
     48with QobiScheme but this version encourages using
     49{defaulted-argument}s everywhere for simplicity.
     50
     51You can define new {type}s as:
     52
     53  (lambda (string) (if (ok? string) (string->value string) (usage {doc})))
     54
     55An example that should make everything clear:
     56
     57  (define-command
     58    (main (exactly-one ("file" file? (file "file" string-argument ""))
     59                       ("other-file" other-file?
     60                          (arg1 "pathname" string-argument "")
     61                          (arg2 "version" real-argument 0)))
     62          (at-most-one ("flag" flag?))
     63          (any-number ("more" more? (more "more" string-argument "")))
     64          (at-least-one ("alt" alt? (alt-arg "arg" string-argument "")))
     65          (required (needed "needed" string-argument ""))
     66          (optional (maybe "maybe" string-argument ""))
     67          (optional (another-maybe "another-maybe" string-argument ""))
     68          (rest (everything "everything" string-argument)))
     69    (pp (list file? file other-file? arg1 arg2 flag? more? more alt? alt-arg needed maybe another-maybe everything))(newline))
     70
     71  (apply main command-line-arguments)
     72
     73Without arguments, with incorrect arguments, with ''-usage'', or ''-help'' this will print:
     74
     75  usage: csi [-file file|-other-file pathname version] [-flag] [-more more]* [-alt arg]+ needed [maybe [another-maybe [everything]*]]
     76
     77=== Graphical UI
     78
     79<macro>(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)</macro>
     80
     81The main way of defining GUI.
     82
     83The GUI is composed of different regions: at the top we have buttons
     84in the button pane, the main content of the application is displayed
     85below in the display pane, below that are the transcript pane and echo
     86pane which are used to output and input text, and at the bottom we
     87have the status pane on the left and message pane on the right. Each
     88pane is an X window embedded in the main X window of the application.
     89
     90The ''display-pane-width'' and ''display-pane-height'' are in pixel
     91units. When width is ''#f'' other arguments will determine the width
     92of the application. The other panes automatically adjust
     93their sizes. ''transcript-lines'' defines the number of lines in the
     94transcript pane, can be ''#f''. ''button-rows'' and ''button-columns''
     95set the size of the button grid in the button pane. Buttons will be
     96automatically sized to take up the appropriate amount of space.
     97
     98All the following procedures take no arguments.
     99''pre-initialize-procedure'' code to run before the application is
     100ready. This is typically where you define UI
     101elements. ''post-initialize-procedure'' code to run right after the UI
     102is ready. ''finalize-procedure'' runs after the UI
     103exists. ''redraw-procedure'' runs as needed to redraw the
     104UI. ''listener-procedure'' runs when return is pressed in the
     105transcript pane.
    17106
    18107  (use qobischeme-ui)
     
    42131  (main '())
    43132
    44 === Commandline
    45 
    46 <procedure>(define-command (function-name {arguments}) {expression}+)</procedure>
    47 
    48 Define a commandline application. The grammar for arguments and
    49 expressions is given below but it might be easier to look at an
    50 example instead.
    51 
    52   {arguments} ::= {keyword}* {required}* {optional}* [{rest}]
    53   {rest}     ::= (rest ({variable} {doc} {type}))
    54   {optional} ::= (optional ({variable} {doc} {type} {default}))
    55   {required} ::= (required ({variable} {doc} {type}))
    56   {keyword} ::= (any-number {nondefaulted-keyword}*)
    57             |   (at-most-one {defaulted-keyword}*)
    58             |   (at-least-one {nondefaulted-keyword}+)
    59            |   (exactly-one {defaulted-keyword}+)
    60   {defaulted-keyword} ::= ({name} {supplied?} {defaulted-argument}*)
    61   {nondefaulted-keyword} ::= ({name} {supplied?} {nondefaulted-argument}*)
    62   {defaulted-argument} ::= ({variable} {doc} {type} {default})
    63   {nondefaulted-argument} ::= ({variable} {doc} {type})
    64   {type} ::= integer-argument | real-argument | string-argument
    65 
    66 {name} and {doc} are strings.
    67 {doc} is only used for documentation.
    68 There can't be a {name} "usage". A -usage is created automatically.
    69 All of the {variable}s and {supplied?}s must be distinct.
    70 All of the {name}s must be distinct.
    71 Can define new {type}s as:
    72 
    73   (lambda (string) (if (ok? string) (string->value string) (usage {doc})))
    74 
    75 === Graphical UI
    76 
    77 <macro>(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)</macro>
    78 
    79 The main way of defining GUI.
    80 
    81 The GUI is composed of different regions: at the top we have buttons
    82 in the button pane, the main content of the application is displayed
    83 below in the display pane, below that are the transcript pane and echo
    84 pane which are used to output and input text, and at the bottom we
    85 have the status pane on the left and message pane on the right. Each
    86 pane is an X window embedded in the main X window of the application.
    87 
    88 The ''display-pane-width'' and ''display-pane-height'' are in pixel
    89 units. When width is ''#f'' other arguments will determine the width
    90 of the application. The other panes automatically adjust
    91 their sizes. ''transcript-lines'' defines the number of lines in the
    92 transcript pane, can be ''#f''. ''button-rows'' and ''button-columns''
    93 set the size of the button grid in the button pane. Buttons will be
    94 automatically sized to take up the appropriate amount of space.
    95 
    96 All the following procedures take no arguments.
    97 ''pre-initialize-procedure'' code to run before the application is
    98 ready. This is typically where you define UI
    99 elements. ''post-initialize-procedure'' code to run right after the UI
    100 is ready. ''finalize-procedure'' runs after the UI
    101 exists. ''redraw-procedure'' runs as needed to redraw the
    102 UI. ''listener-procedure'' runs when return is pressed in the
    103 transcript pane.
    104 
    105133<macro>(define-display-pane-application display-pane-width display-pane-height pre-initialize-procedure post-initialize-procedure finalize-procedure redraw-procedure)</macro>
    106134
Note: See TracChangeset for help on using the changeset viewer.