2006-09-11 17:00:50 +00:00
|
|
|
;; -*- mode: scheme -*-
|
|
|
|
;;
|
|
|
|
;; x a u e n e u a x - nqdataflow
|
|
|
|
;;
|
|
|
|
;; copyright (C) 2004 FoAM vzw
|
2006-09-14 16:38:47 +00:00
|
|
|
;; You are granted the rights to distribute and use this software
|
|
|
|
;; under the terms of the GNU Lesser General Public License as
|
|
|
|
;; published by the Free Software Foundation; either version 2.1 of
|
|
|
|
;; the License, or (at your option] any later version. The LGPL is
|
|
|
|
;; distributed with this code (see: LICENCE) and available online
|
|
|
|
;; at http://www.gnu.org/copyleft/lesser.html
|
2006-09-11 17:00:50 +00:00
|
|
|
|
|
|
|
;; authors
|
|
|
|
;; - nik gaffney <nik@fo.am>
|
|
|
|
|
|
|
|
;; requirements
|
|
|
|
;; - uses qfwfq for layout and slipulation
|
|
|
|
|
|
|
|
;; commentary
|
|
|
|
;; a simple dataflow like visual wrapper to the underlying scheme,
|
|
|
|
;; using an evaluation model which is not quite dataflow, yet not
|
|
|
|
;; quite scheme -> nqdataflow
|
|
|
|
;;
|
|
|
|
;; keyboard controls
|
2006-09-14 16:38:47 +00:00
|
|
|
;; C-n - adds new node, connected to a selected node
|
|
|
|
;; C-c - conencts 2 selected nodes
|
|
|
|
;; C-d - disconnects selected node
|
2006-09-11 17:00:50 +00:00
|
|
|
;; delete - deletes node
|
|
|
|
;; enter - evaluates current node
|
|
|
|
|
|
|
|
;; to do
|
|
|
|
;; - deal with evaluation order display
|
2006-09-14 16:38:47 +00:00
|
|
|
;; - check directions of node connection with 'C-c'
|
2006-09-11 17:00:50 +00:00
|
|
|
;; - multiple connections -> clarify
|
|
|
|
;; - deal with circularity
|
|
|
|
|
|
|
|
;; changes
|
|
|
|
;; 2006-09-11
|
|
|
|
;; - scraped into coherence from various sources
|
|
|
|
|
2006-09-14 16:38:47 +00:00
|
|
|
(require "graph.scm"
|
2006-09-11 17:00:50 +00:00
|
|
|
"qfwfq.scm")
|
|
|
|
|
|
|
|
(define xauen-pasteboard%
|
|
|
|
(class graph-pasteboard%
|
|
|
|
;; should probably figure out how keymaps work,.
|
|
|
|
(define/override (on-char event)
|
|
|
|
(temp-keymap event)
|
|
|
|
(super on-char event))
|
|
|
|
(super-new)))
|
|
|
|
|
|
|
|
;; setup frame and windows..
|
|
|
|
(define f (new frame% [label " } x a u e n e u a x { "]))
|
|
|
|
|
2006-10-30 09:11:19 +00:00
|
|
|
(define mb (instantiate menu-bar% (f)))
|
|
|
|
(define edit-menu (instantiate menu% ("Edit" mb)))
|
|
|
|
(define font-menu (instantiate menu% ("Font" mb)))
|
|
|
|
(append-editor-operation-menu-items edit-menu)
|
|
|
|
(append-editor-font-menu-items font-menu)
|
|
|
|
|
2006-09-11 17:00:50 +00:00
|
|
|
(define p (new xauen-pasteboard%))
|
|
|
|
(define ec (new editor-canvas% (parent f)))
|
|
|
|
|
|
|
|
(send ec min-client-width 450)
|
|
|
|
(send ec min-client-height 450)
|
|
|
|
|
|
|
|
(send ec set-editor p)
|
|
|
|
(define dc (send ec get-dc))
|
|
|
|
|
2006-09-14 16:38:47 +00:00
|
|
|
;; text input callback - spit and polish
|
2006-09-11 17:00:50 +00:00
|
|
|
;; beware hardcoded node & pasteboard & lack of error checking
|
|
|
|
(define (parse-text-input tf event)
|
|
|
|
(if (eqv? (send event get-event-type) 'text-field-enter)
|
|
|
|
(let ([input (read-from-string (send tf get-value))]
|
|
|
|
[node n1]
|
|
|
|
[pasteboard p])
|
|
|
|
(draw-parse-tree input 1 1 node pasteboard)
|
|
|
|
(eval-tree node)
|
|
|
|
;(set-node-text node (eval input))
|
|
|
|
(wobble-tree n1 p))))
|
|
|
|
|
|
|
|
;; textmode input,. .
|
|
|
|
(define input (new text-field%
|
|
|
|
[label "inslkon >"] [parent f] [callback parse-text-input]
|
|
|
|
[init-value "(* 3 4 5 (* 7 8 9))"]))
|
|
|
|
|
|
|
|
;; keyboard overloading..,
|
|
|
|
(define (temp-keymap event)
|
|
|
|
(let* ([target p] ;; should get dynamically pasteboard..,
|
|
|
|
[key (send event get-key-code)]
|
|
|
|
[selected-snip (send target find-next-selected-snip #f)]
|
|
|
|
[Gx (send event get-x)]
|
|
|
|
[Gy (send event get-y)])
|
|
|
|
(let-values ([(x y) (send target editor-location-to-dc-location Gx Gy)])
|
2006-09-14 16:38:47 +00:00
|
|
|
(debug 3 "key[de]maping->key: ~a ~%" key)
|
2006-09-11 17:00:50 +00:00
|
|
|
(debug 1 "selected-snip: ~a ~%" selected-snip)
|
2006-09-14 16:38:47 +00:00
|
|
|
(if (send event get-control-down)
|
2006-09-11 17:00:50 +00:00
|
|
|
(case key
|
2006-09-14 16:38:47 +00:00
|
|
|
[(#\n) ;; C-n fr 'new'
|
2006-09-11 17:00:50 +00:00
|
|
|
(debug 1 "add: ~a" key)
|
2006-10-30 09:11:19 +00:00
|
|
|
(let ([node (make-node-snip)])
|
2006-09-11 17:00:50 +00:00
|
|
|
(send target insert node)
|
|
|
|
(if selected-snip
|
2006-09-14 16:38:47 +00:00
|
|
|
(begin (add-links node selected-snip)
|
|
|
|
;; re.colour the tree, first [grand]child should do...
|
|
|
|
(colour-tree (car (send selected-snip get-children)) p)))
|
|
|
|
(send target move-to node x y)
|
2006-09-11 17:00:50 +00:00
|
|
|
)]
|
2006-09-14 16:38:47 +00:00
|
|
|
[(#\c) ;; C-c fr 'connect'
|
2006-09-11 17:00:50 +00:00
|
|
|
(let ([next (send target find-next-selected-snip selected-snip)])
|
|
|
|
(debug 1 "next-snip: ~a ~%" next)
|
|
|
|
(add-links selected-snip next))]
|
2006-09-14 16:38:47 +00:00
|
|
|
[(#\d) ;; C-d fr 'disconnect'
|
2006-09-11 17:00:50 +00:00
|
|
|
(let ([next (send target find-next-selected-snip selected-snip)])
|
|
|
|
(send selected-snip remove-child next)
|
|
|
|
(send selected-snip remove-parent next)
|
|
|
|
(send next remove-parent selected-snip)
|
2006-09-14 16:38:47 +00:00
|
|
|
(send next remove-child selected-snip))]
|
|
|
|
[(#\z) ;; C-z re.colour
|
|
|
|
(colour-tree selected-snip p)]
|
|
|
|
)))))
|
2006-09-11 17:00:50 +00:00
|
|
|
|
|
|
|
;; basic nodewrenching
|
|
|
|
(define n1 (new output-snip%))
|
|
|
|
(send p insert n1)
|
|
|
|
(send p move-to n1 15 15)
|
|
|
|
|
2006-10-30 09:11:19 +00:00
|
|
|
;; test a recursive node
|
|
|
|
;(define r1 (new recursive-snip%))
|
|
|
|
;(send p insert r1)
|
|
|
|
;(define n2 (new output-snip%))
|
|
|
|
;(send r1 insert n1)
|
|
|
|
|
|
|
|
|
2006-09-11 17:00:50 +00:00
|
|
|
(send f show #t)
|
|
|
|
|
|
|
|
|