Changeset 25578 in project


Ignore:
Timestamp:
11/26/11 17:25:54 (9 years ago)
Author:
juergen
Message:

iup-tutor: file-dialog added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/iup-tutor

    r25575 r25578  
    4444In C attribute names as well as attribute values are strings, in Scheme
    4545the former are keywords, the latter might be symbols or numbers as well. All
    46 attributes can be get and set. Getting is done by the attribute
     46attributes can be get and set. Getting is done (in Scheme) by the attribute
    4747function, setting by the attribute-set! procedure or a generalized set!,
    4848i.e. either by
     
    5050(attribute-set! widget name: val) or (set! (attribute widget name:) val)
    5151
    52 whichever you prefer. The same applies to callbacks.
     52whichever you prefer. The same applies to callbacks, which are get and
     53set by callback and callback-set! respectively.
    5354
    5455In Scheme's Iup callbacks are usually functions of one argument, self
    5556most of the time, which return a symbol, for example 'close, to close a
    56 dialog, or 'default, to keep it open. In C, of course, the return
    57 values are #define'd integers.
     57dialog, or 'default, to keep it open. In C, on the other hand, the
     58return values are #define'd integers.
    5859
    5960=== Hello World
     
    9293is done, when inporting iup. Note also, that the Chicken names are much
    9394friendlier than the C ones: Chicken's module system makes Iup prefixes
    94 superfluous, they can be added, if needed.
     95superfluous, they can be added, if needed, with appropriate import
     96clauses.
    9597
    9698Now a version which shows, how to use attributes and callbacks, again in
     
    125127 
    126128  lbl=IupLabel("Hello,world!");
     129
    127130  vb=IupVbox(lbl, btn);
    128131  IupSetAttribute(vb, "GAP", "10");
     
    139142  IupMainLoop();
    140143
     144  // Clean up
    141145  IupDestroy(dlg);
    142146  IupClose();
     
    147151
    148152==== hello11.scm
     153
     154Here is a translation to Scheme ...
    149155
    150156<enscript highlight="Scheme">
     
    178184
    179185Note, how the upper-case C-names of attributes change to lower-case
    180 Chicken-keywords (by the way, Chicken-keywords can be eiter written with
     186Chicken-keywords (by the way, Chicken-keywords can be either written with
    181187a trailing colon or a leading hash-colon, but I prefere the former,
    182188which looks nicer).
    183189
    184190Note also, that attribute values can be numbers or symbols as well.
    185 And last, but not least, note the tooltips and the ampersand in the
    186 button's title. The latter makes the Alt+underlined-character execute
    187 the callback.
     191And last, but not least, note the tips: predicate, which defines
     192tooltips, and the ampersand in the button's title, which defines a
     193shortcut, Alt+underlined-character, to execute the callback.
    188194
    189195==== hello12.scm
     196
     197... and here a condensed version.
    190198
    191199<enscript highlight="Scheme">
     
    219227
    220228The condensed version above can be almost literally transformed into a
    221 .led resource file, which can be either loaded into a C program or a
     229LED resource file, which can be either loaded into a C program or a
    222230Scheme program. Those resources are interpreted at runtime, so that even
    223231in a compiled program the resource can be changed afterwards, provided
     
    232240</enscript>
    233241
    234 where the attributes' names and values are written without enclosing "",
    235 but interpreted as strings.
     242where the attributes' names and values are written without enclosing
     243quotes, but interpreted as strings.
    236244
    237245Here is an example and its use in Chicken.
     
    455463attribute set.
    456464
     465==== filedlg.scm
     466
     467Now we use two predefined dialogs, file-dialag and message-dialog. You
     468should note, that they are mapped to gtk-dialogs!
     469
     470<enscript highlight="Scheme">
     471
     472(use iup)
     473
     474(define (popup dlg . args)
     475  (apply show dlg #:modal #t args))
     476
     477(define dlg (file-dialog title: "File save"
     478                         dialogtype: 'SAVE
     479                         filter: "*.led"
     480                         filterinfo: "Iup resource file"))
     481
     482(popup dlg x: 'center y: 'center)
     483
     484(let ((status (attribute dlg status:)))
     485  (cond
     486    ((string=? status "1")
     487     (popup
     488       (message-dialog value: (string-append  "New File: "
     489                                              (attribute dlg value:)))))
     490    ((string=? status "0")
     491     (popup
     492       (message-dialog value: (string-append  "File already exists: "
     493                                              (attribute dlg value:)))))
     494    ((string=? status "-1")
     495     (popup
     496       (message-dialog value: "File-dialog: Operation Canceled")))))
     497
     498(destroy! dlg)
     499(exit 0)
     500
     501</enscript>
     502
     503Note, that the status: attribute of the file-dialog is a string!
     504
     505=== Concluding remark
     506
     507All these examples show, that Iup is really easy to use ...
     508
    457509== Author
    458510
Note: See TracChangeset for help on using the changeset viewer.