Changeset 25578 in project
- Timestamp:
- 11/26/11 17:25:54 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wiki/iup-tutor
r25575 r25578 44 44 In C attribute names as well as attribute values are strings, in Scheme 45 45 the 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 attribute46 attributes can be get and set. Getting is done (in Scheme) by the attribute 47 47 function, setting by the attribute-set! procedure or a generalized set!, 48 48 i.e. either by … … 50 50 (attribute-set! widget name: val) or (set! (attribute widget name:) val) 51 51 52 whichever you prefer. The same applies to callbacks. 52 whichever you prefer. The same applies to callbacks, which are get and 53 set by callback and callback-set! respectively. 53 54 54 55 In Scheme's Iup callbacks are usually functions of one argument, self 55 56 most of the time, which return a symbol, for example 'close, to close a 56 dialog, or 'default, to keep it open. In C, o f course, the return57 values are #define'd integers.57 dialog, or 'default, to keep it open. In C, on the other hand, the 58 return values are #define'd integers. 58 59 59 60 === Hello World … … 92 93 is done, when inporting iup. Note also, that the Chicken names are much 93 94 friendlier than the C ones: Chicken's module system makes Iup prefixes 94 superfluous, they can be added, if needed. 95 superfluous, they can be added, if needed, with appropriate import 96 clauses. 95 97 96 98 Now a version which shows, how to use attributes and callbacks, again in … … 125 127 126 128 lbl=IupLabel("Hello,world!"); 129 127 130 vb=IupVbox(lbl, btn); 128 131 IupSetAttribute(vb, "GAP", "10"); … … 139 142 IupMainLoop(); 140 143 144 // Clean up 141 145 IupDestroy(dlg); 142 146 IupClose(); … … 147 151 148 152 ==== hello11.scm 153 154 Here is a translation to Scheme ... 149 155 150 156 <enscript highlight="Scheme"> … … 178 184 179 185 Note, how the upper-case C-names of attributes change to lower-case 180 Chicken-keywords (by the way, Chicken-keywords can be eit er written with186 Chicken-keywords (by the way, Chicken-keywords can be either written with 181 187 a trailing colon or a leading hash-colon, but I prefere the former, 182 188 which looks nicer). 183 189 184 190 Note also, that attribute values can be numbers or symbols as well. 185 And last, but not least, note the t ooltips and the ampersand in the186 button's title. The latter makes the Alt+underlined-character execute 187 the callback.191 And last, but not least, note the tips: predicate, which defines 192 tooltips, and the ampersand in the button's title, which defines a 193 shortcut, Alt+underlined-character, to execute the callback. 188 194 189 195 ==== hello12.scm 196 197 ... and here a condensed version. 190 198 191 199 <enscript highlight="Scheme"> … … 219 227 220 228 The condensed version above can be almost literally transformed into a 221 .ledresource file, which can be either loaded into a C program or a229 LED resource file, which can be either loaded into a C program or a 222 230 Scheme program. Those resources are interpreted at runtime, so that even 223 231 in a compiled program the resource can be changed afterwards, provided … … 232 240 </enscript> 233 241 234 where the attributes' names and values are written without enclosing "",235 but interpreted as strings.242 where the attributes' names and values are written without enclosing 243 quotes, but interpreted as strings. 236 244 237 245 Here is an example and its use in Chicken. … … 455 463 attribute set. 456 464 465 ==== filedlg.scm 466 467 Now we use two predefined dialogs, file-dialag and message-dialog. You 468 should 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 503 Note, that the status: attribute of the file-dialog is a string! 504 505 === Concluding remark 506 507 All these examples show, that Iup is really easy to use ... 508 457 509 == Author 458 510
Note: See TracChangeset
for help on using the changeset viewer.