Advertisement
StivenGonzalez

Prueba GUI

Apr 8th, 2021
2,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 13.51 KB | None | 0 0
  1. #lang racket
  2. (require racket/gui)
  3.  
  4. ;Ventana
  5. (define ventana (new frame% [label "Ventana "]))
  6.  
  7. ;Objetos de la ventana principal
  8. (define texto (new message%
  9.                    [parent ventana]
  10.                    [label "Objeto 'tab-panel%':"]
  11.                    ))
  12.  
  13. ;Definicion de opciones
  14. (define opciones (list "Botones" "Casillas de verificacion" "Opciones multiple"
  15.                        "Listas" "Cuadros de texto" "Otros" "Pyafin"))
  16. (define tab (new tab-panel%
  17.                  [parent ventana]
  18.                  [choices opciones]
  19.                  [callback
  20.                   (lambda(t c) ; una instancia de 'tab-panel% y de 'control-event%'
  21.                     (let* ([ix (send tab get-selection)]
  22.                            [ix-str (number->string ix)]
  23.                            [nombre-ficha(send tab get-item-label ix)])
  24.                            (send mensaje set-label (string-append "Se selecciono la ficha
  25. "ix-str" con nombres '" nombre-ficha "'"))
  26.                       (send tab delete-child (first(send tab get-children)))
  27.                       (send tab add-child (list-ref lista-paneles ix))
  28.                       )
  29.                     )
  30.                   ]
  31.                  )
  32.   )
  33.  
  34. ;Definicion de mensaje
  35. (define mensaje (new message%
  36.                      [parent ventana]
  37.                      [label "Aqui se mostrara los eventos del objecto"]
  38.                      [auto-resize #t]
  39.                      )
  40.   )
  41.  
  42. ;=========================== >>> Objectos paneles <<<======================;
  43. (define panel0 (new vertical-panel% [parent tab]))
  44. (define panel1 (new vertical-panel% [parent tab][style '(deleted)]))
  45. (define panel2 (new vertical-panel% [parent tab][style '(deleted)]))
  46. (define panel3 (new vertical-panel% [parent tab][style '(deleted)]))
  47. (define panel4 (new vertical-panel% [parent tab][style '(deleted)]))
  48. (define panel5 (new vertical-panel% [parent tab][style '(deleted)]))
  49. (define panel6 (new vertical-panel% [parent tab][style '(deleted)]))
  50.  
  51. (define lista-paneles (list panel0 panel1 panel2 panel3 panel4 panel5
  52.                             panel6))
  53. ;;Panel 0 - Botones
  54. ;--------------------------------------
  55. (define panel-botones (new horizontal-pane% [parent panel0]))
  56. (define(funcion-boton b c)
  57.   (send mensaje set-label (string-append "Click en el boton'" (send b get-label)"'"))
  58.   )
  59. (define boton1 (new button%
  60.                     [parent panel-botones]
  61.                     [label "aqui"]
  62.                     [callback funcion-boton]))
  63. (define panel-botones2 (new vertical-pane%[parent panel-botones]))
  64.  
  65. (define boton2 (new button%
  66.                     [parent panel-botones2]
  67.                     [label "alla"]
  68.                     [callback funcion-boton]))
  69.  
  70. (define boton3 (new button%
  71.                     [parent panel-botones2]
  72.                     [label "otro"]
  73.                     [callback funcion-boton]))
  74.  
  75. (define boton4 (new button%
  76.                     [parent panel-botones2]
  77.                     [label "y otro"]
  78.                     [callback funcion-boton]))
  79.  
  80. ;Panel 1 -Casillas de verificacion
  81. (define (funcion-chequeo c e) ;una instancia 'check-box% y de un 'control-event%
  82.   (send mensaje set-label
  83.         (string-append "Se"
  84.                        (if(send c get-value) "selecciono" "deselecciono")
  85.                        " la casilla '"(send c get-label)"'"))
  86.   )
  87. (define chequeo1 (new check-box%
  88.                       [label "Chequeame"]
  89.                       [parent panel1]
  90.                       [value #f]
  91.                       [callback funcion-chequeo]))
  92. (define chequeo2 (new check-box%
  93.                       [label "Este es otro 'check-box%'"]
  94.                       [parent panel1]
  95.                       [value #t]
  96.                       [callback funcion-chequeo]
  97.                       )
  98.   )
  99. (define chequeo3 (new check-box%
  100.                       [label "Este no responde ningun evento,\ntiene tres
  101. lineas\ny por defecto no esta marcado"]
  102.                       [parent panel1]
  103.                       )
  104.   )
  105.  
  106. ;;Panel 2-----------------------------------> Opciones multiple
  107.  
  108. (define (funcion-opcion-multiple r c)
  109.   (send mensaje set-label
  110.         (string-append "Se marco la opcion"
  111.                        (number->string (send r get-selection))
  112.                        "con texto' "
  113.                        (send r get-item-label (send r get-selection))
  114.                        "' del grupo '"
  115.                        (let([t(send r get-label)])
  116.                          (if t t "<sin-texto>"))
  117.                        "'"
  118.                        )
  119.         )
  120.   )
  121. (send panel2 set-orientation #t)
  122. (define panel-radio1(new radio-box%
  123.                          [label "Verticales"]
  124.                          [parent panel2]
  125.                          [choices(list "Opcion 1" "Opcon 2")]
  126.                          [callback funcion-opcion-multiple]
  127.                          )
  128.   )
  129. (define panel-radio2 (new radio-box%
  130.                           [label "Horizontales"]
  131.                           [parent panel2]
  132.                           [choices (list "Opcion1" "Opcion2")]
  133.                           [callback funcion-opcion-multiple]
  134.                           [style(list 'horizontal)]
  135.                           [selection 1]
  136.                           )
  137.   )
  138. (define panel-radio3 (new radio-box%
  139.                           [label "Horizontales con la etiqueta arriba"]
  140.                           [parent panel2]
  141.                           [choices (list "Opcion 1" "Opcion 2")]
  142.                           [callback funcion-opcion-multiple]
  143.                           [style(list 'horizontal 'vertical-label)]
  144.                           )
  145.   )
  146. (define panel-radio4(new radio-box%
  147.                          [label "Verticales con la etiqueta arriba"]
  148.                          [parent panel2]
  149.                          [choices (list "Opcion 1" "Opcion 2")]
  150.                          [callback funcion-opcion-multiple]
  151.                          [style(list 'vertical 'vertical-label)]
  152.                          ))
  153. (define panel-radio5(new radio-box%
  154.                          [label #f]
  155.                          [parent panel2]
  156.                          [choices(list "Sin etiqueta" "Solo estan los 'radio-box%'")]
  157.                          [callback funcion-opcion-multiple]
  158.                          )
  159.   )
  160.  
  161.  
  162. ;;------------->Paneles 3 -Listas
  163. (define(funcion-lista r c) ;instancia
  164.   (send mensaje set-label
  165.         (string-append "Se marco la opcion"
  166.                        (number->string (send r get-selection))
  167.                        "con texto '"
  168.                        (send r get-string-selection)
  169.                        "' de la lista'"
  170.                        (let([t (send r get-label)])
  171.                          (if t t "<sin-texto>"))
  172.                        "'"
  173.                        )
  174.         )
  175.   )
  176. (define panel-lista1 (new horizontal-pane%[parent panel3]))
  177. (define eleccion1 (new choice%
  178.                        [label "Primera lista"]
  179.                        [choices (list "Opcion 1" "Opcion 2" "etc.")]
  180.                        [parent panel-lista1]
  181.                        [callback funcion-lista]
  182.                        [selection 2])
  183.   )
  184.  
  185. (define eleccion2 (new choice%
  186.                        [label "Segunda lista"]
  187.                        [choices (list "Opcion 1" "Opcion 2" "etc.")]
  188.                        [parent panel-lista1]
  189.                        [callback funcion-lista]
  190.                        )
  191.   )
  192.  
  193. (define eleccion3 (new choice%
  194.                        [label #f]
  195.                        [choices (list "Opcion 1" "Opcion 2" "etc.")]
  196.                        [parent panel-lista1]
  197.                        [callback funcion-lista]
  198.                        )
  199.   )
  200.  
  201. (define panel-lista2 (new horizontal-pane%
  202.                           [parent panel3]))
  203. (define lista1 (new list-box%
  204.                     [label "Primera lista"]
  205.                     [choices (list "Opcion 1" "Opcion 2" "etc.")]
  206.                     [parent panel-lista2]
  207.                     [callback funcion-lista]
  208.                     [selection 2]
  209.                     )
  210.   )
  211. (define lista2 (new list-box%
  212.                     [label "Segunda lista"]
  213.                     [choices (list "Opcion 1" "Opcion 2" "etc.")]
  214.                     [parent panel-lista2]
  215.                     [callback funcion-lista]
  216.                     [style(list 'multiple 'vertical-label)]
  217.                     )
  218.   )
  219. (define lista3 (new list-box%
  220.                     [label #f]
  221.                     [choices (list "Opcion 1 " "Opcion 2" "etc.")]
  222.                     [parent panel-lista2]
  223.                     [callback funcion-lista]
  224.                     [style(list 'extended 'vertical-label)]
  225.                     )
  226.   )
  227. ;ver adicionalmente, los metodos 'get-selections y 'is-selected?
  228.  
  229. ;Panel 4 ---------------> Cuadros de texto
  230. (define (funcion-texto t c)
  231.   (send mensaje set-label(string-append "Texto: <<"(send t get-value)
  232.                                         ">>"))
  233.   )
  234. (define texto1 (new text-field%
  235.                     [label "Etiqueta"]
  236.                     [parent panel4]
  237.                     [init-value "Escriba algo"]
  238.                     [callback funcion-texto]
  239.                     ))
  240. (define texto2 (new text-field%
  241.                     [label "Etiqueta"]
  242.                     [parent panel4]
  243.                     [init-value "etiqueta arriba"]
  244.                     [style[list 'vertical-label 'single]]
  245.                     [callback funcion-texto]
  246.                     )
  247.   )
  248. (define texto3 (new text-field%
  249.                     [label #f]
  250.                     [parent panel4]
  251.                     [init-value "Etiqueta arriba"]
  252.                     [style(list 'vertical-label 'single)]
  253.                     [callback funcion-texto]
  254.                     )
  255.   )
  256. (define combo1 (new combo-field%
  257.                     [label "Combo 1"]
  258.                     [parent panel4]
  259.                     [choices(list "Opcion 1" "Opcion 2" "etc.")]
  260.                     [init-value "por defecto"]
  261.                     [callback(lambda (c e)
  262.                                (send mensaje set-label
  263.                                      (string-append "Evento del 'combo-field%'"
  264.                                                     (send c get-label)
  265.                                                     )))]
  266.                     )
  267.   )
  268. (define combo2 (new combo-field%
  269.                     [label "Agrega opciones al precionar Enter: "]
  270.                     [parent panel4]
  271.                     ;[choices(list "Opcion 1" "Opcion 2" "etc.")]
  272.                     [choices null]
  273.                     [callback
  274.                      (lambda (c e)
  275.                        (when (eqv? (send e get-event-type)'text-field-enter)
  276.                          (begin
  277.                            (send c append (send c get-value))
  278.                            (send mensaje set-label
  279.                                  (string-append "Texto agregado: '"
  280.                                                 (send c get-value)
  281.                                                 "'"))
  282.                            )
  283.                          )
  284.                        )
  285.                      ]
  286.                     )
  287.   )
  288.  
  289. ;define panel 5 - Otros --------------------------------
  290.  
  291. (define msg-otros (new message%
  292.                        [label "Slider: "]
  293.                        [parent panel5]
  294.                        )
  295.   )
  296. (define (evento-slider s e)
  297.   (send mensaje set-label
  298.         (string-append "Valor del slider '"
  299.                        (send s get-label)
  300.                        "': "
  301.                        (number->string (send s get-value))))
  302.   (if (object=? s slider1)
  303.       (send gauge2 set-value (send s get-value))
  304.       (send gauge2 set-value (send s get-value))
  305.       )
  306.   )
  307. (define slider1 ( new slider%
  308.                       [label "Valor1: "]
  309.                       [parent panel5]
  310.                       [min-value 0]
  311.                       [max-value 100]
  312.                       [init-value 30]
  313.                       [callback evento-slider]
  314.                       )
  315.   )
  316. (define slider2 (new slider%
  317.                      [label "Valor2: "]
  318.                      [parent panel5]
  319.                      [min-value 0]
  320.                      [max-value 100]
  321.                      [style (list 'vertical 'plain)]
  322.                      [callback evento-slider]
  323.                      )
  324.   )
  325. (define msg-otros2(new message%
  326.                        [label "Gauge: "]
  327.                        [parent panel5]))
  328.  
  329. (define gauge2(new gauge%
  330.                    [label "Gauge 2:"]
  331.                    [parent panel5]
  332.                    [style '(vertical)]
  333.                    [range 100]
  334.                    ))
  335. (send gauge2 set-value (send slider2 get-value))
  336. ;;Panel 6 ---------------------------------------------->
  337.  
  338. (define canvas-hijo%
  339.   (class canvas%
  340.     (define/override (on-event evento)
  341.       (send mensaje set-label
  342.       (string-append "Evento de raton en el canvas: ("
  343.                      (number->string (send evento get-x))
  344.                      ","
  345.                      (number->string (send evento get-y))
  346.                      ")"
  347.                      )
  348.       )
  349.       )
  350.     (define/override (on-char evento)
  351.       (send mensaje set-label
  352.             (string-append "Evento de teclado en el canvas: "
  353.                            (let([t(send evento get-key-code)])
  354.                              (if(char? t)(string t)(symbol->string t))
  355.                              )
  356.                            )))
  357.     (super-new)
  358.     )
  359.   )
  360. (define c (new canvas-hijo%
  361.                [parent panel6]
  362.                )
  363.   )
  364. (send ventana show #t)
  365.  
  366.  
  367.  
  368.                    
  369.  
  370.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement