Changeset 25597 in project
- Timestamp:
- 11/28/11 15:36:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wiki/iup-tutor
r25582 r25597 503 503 Note, that the status: attribute of the file-dialog is a string! 504 504 505 ==== multiline.scm 506 507 Now, we'll show how widgets within a dialog can communicate whith each 508 other. The trick is, that Iup can reference widgets by name, or, to be 509 more precise, by string name. You have seen this in the LED example 510 above: In LED a widget is named by a string and constructed by the LED 511 interpreter. To use it in Scheme, you reference the widget proper 512 from its name via handle-ref. This can be done without LED as well. But 513 then you must give the widget a string name via handle-name-set! or the 514 generalized version (set! (handle-name widget) name). 515 516 The following dialog contains two textboxes, one of them multiline, a 517 dropdown listbox and some buttons, allowing to get or set the multiline 518 predicates. Please take note, how handle-ref and handle-name is used. 519 520 <enscript highlight="Scheme"> 521 522 (use iup) 523 524 (define (message title value) 525 (show (message-dialog title: title value: value) #:modal? #t)) 526 527 (define (set-attribute keyword) 528 (let ( 529 (msg (sprintf "Attribute ~A set with value ~A" 530 (keyword->string keyword) (attribute line value:))) 531 (multi (handle-ref "multi")) 532 (line (handle-ref "line")) 533 ) 534 (attribute-set! multi keyword (attribute line value:)) 535 (message "Set attribute" msg) 536 'default)) 537 538 (define (get-attribute keyword) 539 (let ( 540 (msg (sprintf "Attribute ~A get with value ~A" 541 (keyword->string keyword) (attribute line value:))) 542 (multi (handle-ref "multi")) 543 (line (handle-ref "line")) 544 ) 545 (attribute-set! line value: (attribute multi keyword)) 546 (message "Get attribute" msg) 547 'default)) 548 549 (define btn-append 550 (button title: '&Append 551 action: (lambda (self) 552 (let ((lb (handle-ref "lb"))) 553 (if (eqv? (string->number (attribute lb value:)) 1) 554 (set-attribute append:) 555 (get-attribute append:)) 556 'default)))) 557 558 (define btn-insert 559 (button title: '&Insert 560 action: (lambda (self) 561 (let ((lb (handle-ref "lb"))) 562 (if (eqv? (string->number (attribute lb value:)) 1) 563 (set-attribute insert:) 564 (get-attribute insert:)) 565 'default)))) 566 567 (define btn-border 568 (button title: '&Border 569 action: (lambda (self) 570 (let ((lb (handle-ref "lb"))) 571 (if (eqv? (string->number (attribute lb value:)) 1) 572 (set-attribute border:) 573 (get-attribute border:)) 574 'default)))) 575 576 (define btn-caret 577 (button title: '&Caret 578 action: (lambda (self) 579 (let ((lb (handle-ref "lb"))) 580 (if (eqv? (string->number (attribute lb value:)) 1) 581 (set-attribute caret:) 582 (get-attribute caret:)) 583 'default)))) 584 585 (define btn-readonly 586 (button title: '&Readonly 587 action: (lambda (self) 588 (let ((lb (handle-ref "lb"))) 589 (if (eqv? (string->number (attribute lb value:)) 1) 590 (set-attribute readonly:) 591 (get-attribute readonly:)) 592 'default)))) 593 594 (define btn-selection 595 (button title: '&Selection 596 action: (lambda (self) 597 (let ((lb (handle-ref "lb"))) 598 (if (eqv? (string->number (attribute lb value:)) 1) 599 (set-attribute selection:) 600 (get-attribute selection:)) 601 'default)))) 602 603 (define btn-selectedtextbox 604 (button title: 'Selected&textbox 605 action: (lambda (self) 606 (let ((lb (handle-ref "lb"))) 607 (if (eqv? (string->number (attribute lb value:)) 1) 608 (set-attribute selectedbox:) 609 (get-attribute selectedbox:)) 610 'default)))) 611 612 (define btn-nc 613 (button title: '&Nc 614 action: (lambda (self) 615 (let ((lb (handle-ref "lb"))) 616 (if (eqv? (string->number (attribute lb value:)) 1) 617 (set-attribute nc:) 618 (get-attribute nc:)) 619 'default)))) 620 621 (define btn-value 622 (button title: '&Value 623 action: (lambda (self) 624 (let ((lb (handle-ref "lb"))) 625 (if (not (attribute lb value:)) 626 (set! (attribute lb value:) 1)) 627 (if (eqv? (string->number (attribute lb value:)) 1) 628 (set-attribute value:) 629 (get-attribute value:)) 630 'default)))) 631 632 (define lb (listbox #:1 'set #:2 'get value: 1 dropdown: #t)) 633 (define multi (textbox expand: #t multiline: #t)) 634 (define line (textbox expand: 'horizontal)) 635 636 637 (set! (handle-name lb) "lb") 638 (set! (handle-name multi) "multi") 639 (set! (handle-name line) "line") 640 641 (define dlg 642 (dialog (vbox multi 643 (hbox lb 644 line) 645 (hbox btn-append btn-insert btn-border btn-caret 646 btn-readonly btn-selection) 647 (hbox btn-selectedtextbox btn-nc btn-value)) 648 title: "Multiline example" 649 size: 'HALFxQUARTER)) 650 651 (show dlg x: 'center y: 'center) 652 (main-loop) 653 (destroy! dlg) 654 (exit 0) 655 656 </enscript> 657 658 There is one caveat in the listbox: The lines must be denoted with 659 prefixed keyword notation, 1: will not work, for example! 660 505 661 === Concluding remark 506 662
Note: See TracChangeset
for help on using the changeset viewer.