Changeset 7500


Ignore:
Timestamp:
Oct 23, 2007, 2:36:43 PM (14 years ago)
Author:
af
Message:

Make the easygui currency converter demo more robust.

  • No longer break on pushing "Convert" if non-numbers are in Amount and Exchange rate, and
  • make the result field non-editable.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/examples/cocoa/easygui/currency-converter.lisp

    r7325 r7500  
    66     :position (point 125 513)
    77     :title "Currency Converter"
    8      :resizable-p t #+not-yet nil
     8     :resizable-p nil
    99     :minimizable-p t))
    1010
     
    1212  (let ((currency-form (make-instance 'form-view
    1313                          :autosize-cells-p t
    14                           :interline-spacing 9d0
     14                          :interline-spacing 9.0
    1515                          :position (point 15 70)                         
    1616                          :size (point 353 90)))
     
    2424    (setf (action convert-button)
    2525          #'(lambda ()
    26               (setf (entry-text currency-form 2)
    27                     (prin1-to-string
    28                      (* (read-from-string (entry-text currency-form 1))
    29                         (read-from-string (entry-text currency-form 0)))))))
    30     (add-entries currency-form
    31                  "Exchange Rate per $1:" "Dollars to Convert:"
    32                  "Amount in other Currency:")
     26              (let ((exchange-rate (read-from-string
     27                                    (entry-text currency-form 1) nil nil))
     28                    (amount (read-from-string (entry-text currency-form 0)
     29                                              nil nil)))
     30                (when (and (numberp exchange-rate) (numberp amount))
     31                  (setf (entry-text currency-form 2)
     32                        (prin1-to-string (* exchange-rate amount)))))))
     33    (setf (editable-p (car (last (add-entries currency-form
     34                                              "Exchange Rate per $1:"
     35                                              "Dollars to Convert:"
     36                                              "Amount in other Currency:"))))
     37          nil)
    3338    (add-subviews cw currency-form line convert-button)
    3439    (window-show cw)))
Note: See TracChangeset for help on using the changeset viewer.