Adapted to new version of the Science Collection

This commit is contained in:
Jens Axel Søgaard 2013-12-06 18:48:53 +01:00
parent e2154543c5
commit b063d54f6e

View File

@ -18,6 +18,8 @@
;; Editor: Text size. ;; Editor: Text size.
;; Editor: Save and load. ;; Editor: Save and load.
;; Editor: When inserting part copied from MathBox, automatically insert new MathBox. ;; Editor: When inserting part copied from MathBox, automatically insert new MathBox.
;; Editor: Keybindings for λ α β γ δ ε ∆ Λ works in MathBox. Should work outside too.
;; (Partially done. β and bold clashes) More greek letters?
;; Parser: Extend f(x):=expr syntax to 2 or more variables. ;; Parser: Extend f(x):=expr syntax to 2 or more variables.
;; Evaluation: Get syntax-location from math-text% ;; Evaluation: Get syntax-location from math-text%
;; Keymaps: Insertion of greek, and, mathematical characters. ;; Keymaps: Insertion of greek, and, mathematical characters.
@ -32,12 +34,6 @@
;; Snips: Represent equations, integrals etc with small graphs ala Wolfram Alpha. ;; Snips: Represent equations, integrals etc with small graphs ala Wolfram Alpha.
;; Educational: Recognize standard equations and offer step by step solutions. ;; Educational: Recognize standard equations and offer step by step solutions.
;; LIMBO
;; PlotCanvas: Add "copy plot as image". set-clipboard-image is unimplmented :-(
;; (Fixed on OS X)
;; DONE ;; DONE
;; ;;
;; MathBox: Evaluating an expression with an error, removes previous result. ;; MathBox: Evaluating an expression with an error, removes previous result.
@ -57,6 +53,7 @@
;; NSolve: Implemented bisection and Brent. ;; NSolve: Implemented bisection and Brent.
;; Snips: Right-click menu: Evaluation options such output on/off. ;; Snips: Right-click menu: Evaluation options such output on/off.
;; Errors: Errors and warnings can be signaled with user-error and user-warning ;; Errors: Errors and warnings can be signaled with user-error and user-warning
;; PlotCanvas: Add "copy plot as image".
;; IDEAS ;; IDEAS
@ -71,7 +68,7 @@
(prefix-in plot: plot) (prefix-in plot: plot)
"../infix/main.rkt" "../infix/main.rkt"
"../infix/parser.rkt" "../infix/parser.rkt"
(except-in (planet williams/science/math) infinite? nan?) (planet williams/science/math)
"../numeric/root-finding.rkt" "../numeric/root-finding.rkt"
"../utils/clipboard.rkt") "../utils/clipboard.rkt")
@ -94,7 +91,7 @@
(if (exact? x) (exact->inexact x) x)) (if (exact? x) (exact->inexact x) x))
;;; ;;;
;;; ;;; GLOBAL VARIABLES
;;; ;;;
(define all-math-texts '()) (define all-math-texts '())
@ -390,13 +387,6 @@
[callback [callback
(λ (r e) (λ (r e)
(set-clipboard-bitmap (set-clipboard-bitmap
(let* ([bm (send plot-canvas make-bitmap (send plot-canvas get-width) (send plot-canvas get-height))]
[dc (new bitmap-dc% [bitmap bm])])
(draw-plot dc)
bm))
; TODO: Use this when set-clipboard-bitmap is implemented in the racket gui
#;(send the-clipboard set-clipboard-bitmap
(let* ([bm (send plot-canvas make-bitmap (send plot-canvas get-width) (send plot-canvas get-height))] (let* ([bm (send plot-canvas make-bitmap (send plot-canvas get-width) (send plot-canvas get-height))]
[dc (new bitmap-dc% [bitmap bm])]) [dc (new bitmap-dc% [bitmap bm])])
(draw-plot dc) (draw-plot dc)
@ -506,15 +496,26 @@
(list 'src-name 1 0 1 (string-length str))) (list 'src-name 1 0 1 (string-length str)))
(open-input-string str)))))) (open-input-string str))))))
(define (install-math-snip-keymap math-snip) (define (register-greek keymap)
(let ([keymap (send (send math-snip get-editor) get-keymap)])
(define (register name char shortcuts) (define (register name char shortcuts)
(let ([insert-name (string-append "insert-" name)]) (let ([insert-name (string-append "insert-" name)])
(send keymap add-function insert-name (send keymap add-function insert-name
(λ (ed e) (send ed insert char))) (λ (ed e) (send ed insert char)))
(for ([shortcut shortcuts]) (for ([shortcut shortcuts])
(send keymap map-function shortcut insert-name)))) (send keymap map-function shortcut insert-name))))
(register "lambda" #\λ '("d:\\" "c:\\"))
(register "Lambda" #\Λ '("c:L"))
(register "alpha" #\α '("c:a"))
(register "beta" #\β '("c:b")) ; TODO: Taken by bold
(register "gamma" #\γ '("c:g"))
(register "delta" #\δ '("c:d"))
(register "epsilon" #\ε '("c:e"))
(register "rho" #\ρ '("c:r"))
(register "Gamma" #\Γ '("c:G"))
(register "Delta" #\∆ '("c:D")))
(define (install-math-snip-keymap math-snip)
(let ([keymap (send (send math-snip get-editor) get-keymap)])
(send keymap add-function "evaluate-math" (send keymap add-function "evaluate-math"
(λ (ed e) (send ed evaluate))) (λ (ed e) (send ed evaluate)))
@ -539,16 +540,8 @@
(send keymap add-function "newline" (send keymap add-function "newline"
(λ (ed e) (send ed insert #\newline))) (λ (ed e) (send ed insert #\newline)))
(register "lambda" #\λ '("d:\\" "c:\\")) (register-greek keymap)
(register "Lambda" #\Λ '("c:L"))
(register "alpha" #\α '("c:a"))
(register "beta" #\β '("c:b"))
(register "gamma" #\γ '("c:g"))
(register "delta" #\δ '("c:d"))
(register "epsilon" #\ε '("c:e"))
(register "rho" #\ρ '("c:r"))
(register "Gamma" #\Γ '("c:G"))
(register "Delta" #\∆ '("c:D"))
(send keymap map-function "s:enter" "newline") (send keymap map-function "s:enter" "newline")
(send keymap map-function "enter" "evaluate-math") (send keymap map-function "enter" "evaluate-math")
@ -562,6 +555,7 @@
;;; ;;;
(define keymap (send text-editor get-keymap)) (define keymap (send text-editor get-keymap))
(register-greek keymap)
;(add-editor-keymap-functions keymap) ;(add-editor-keymap-functions keymap)
;(add-text-keymap-functions keymap) ;(add-text-keymap-functions keymap)