Advertisement
Guest User

Racket spreadsheet example

a guest
Jul 9th, 2014
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.26 KB | None | 0 0
  1. #lang racket
  2. (require racket/gui/base)
  3. (require (planet williams/table-panel:1:2/table-panel))
  4.  
  5. ;  The top-level frame
  6. (define frame
  7.   (instantiate frame%
  8.     ("Test")))
  9.  
  10. (define scrolling-panel
  11.   (new vertical-panel%
  12.        (parent frame)
  13.        (style '(auto-hscroll auto-vscroll))))
  14.        
  15. (define n-columns 10)
  16. (define n-rows 20)
  17.  
  18. (define table-panel
  19.   (new table-panel%
  20.     (parent scrolling-panel)
  21.     (alignment '(center center))
  22.     (spacing 0)
  23.     (column-stretchability #f)
  24.     (row-stretchability #f)
  25.     (stretchable-width #t)
  26.     (stretchable-height #t)
  27.     (horiz-margin 0)
  28.     (vert-margin 0)
  29.     (dimensions (list (+ 1 n-rows) (+ 1 n-columns)))
  30.     ))
  31.  
  32. (new button%
  33.      (parent table-panel)
  34.      (stretchable-width #t)
  35.      (horiz-margin 0)
  36.      (vert-margin 0)
  37.      (label "/"))
  38.  
  39. (for ((i (in-range n-columns)))
  40.   (new button%
  41.        (parent table-panel)
  42.        (stretchable-width #t)
  43.        (horiz-margin 0)
  44.        (vert-margin 0)
  45.        (label (number->string (+ 1 i)))))
  46.  
  47. (define yellow-color (make-object color% 255 255 0))
  48. (define white-color (make-object color% 255 255 255))
  49.  
  50. (define my-text-field%
  51.   (class text-field%
  52.     (super-new)
  53.     (define/override (on-focus on?)
  54.       (send this set-field-background (if on? yellow-color white-color)))
  55.     (define/override (on-subwindow-char ctl event)
  56.       (define key-code (send event get-key-code))
  57.       (when (equal? key-code 'escape)
  58.         ;; We can not just "unfocus" the text field,
  59.         ;; so we send the focus to the main window instead
  60.         (send frame focus))
  61.       (super on-subwindow-char ctl event))
  62.     ))
  63.  
  64. (for ((j (in-range n-rows)))
  65.   (new button%
  66.        (parent table-panel)
  67.        (horiz-margin 0)
  68.        (vert-margin 0)
  69.        (stretchable-width #t)
  70.        (stretchable-height #t)
  71.        (label (number->string (+ 1 j))))
  72.   (for ((i (in-range n-columns)))
  73.     (new my-text-field%
  74.          (parent table-panel) (label #f)
  75.          (horiz-margin 0)
  76.          (vert-margin 0)
  77.          (callback
  78.           (lambda (ctl event)
  79.             (define type (send event get-event-type))
  80.             (when (equal? type 'text-field-enter)
  81.               (send frame focus))))
  82.          )))
  83.  
  84. (send frame resize 600 400)
  85. (send frame show #t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement