![](https://secure.gravatar.com/avatar/9fda7fbd6217f4d84a55e5c5b48a2106.jpg?s=120&d=mm&r=g)
Am 20.05.2006 um 20:16 schrieb Frank Goenninger:
Am 20.05.2006 um 18:24 schrieb Ken Tilton:
Frank Goenninger wrote:
Hi Kenny, hi all:
I do have a text widget which is created using mk-text-widget:
(mk-text-widget :id :receive-window :state 'disabled :md-value (c?n "...") :height 10 :width 80 :borderwidth 2 :relief 'sunken :pady 5))
No matter what I do (even setting :state to 'enabled) I do get anything printed in the text widget.
I actually execute a setf on md-value of the text widget:
(setf (md-value (fm-other :receive-window)) data)
Any idea? Thx!
Hmmm, looks like I did not finish implementing text widgets.
Yep, meanwhile I recognized that an observer is missing in file entry.lisp.
Well, actually I had to do (in file entry.lisp): ;; Method CLEAR: clears a text widget to zero content (defmethod clear ((self text-widget)) (tk-format `(:variable ,self) "~a delete 1.0 end" (^path))) ;; This observer puts text to the widget if md-value has been set ;; Also takes care of edge cases like initialization time and setting ;; strings of length 0... (defobserver .md-value ((self text-widget)) (trc "md-value output" self new-value) (if (or (and (not old-value) (string= new-value "")) (not new-value)) (tk-format `(:variable ,self) "~a delete 1.0 end" (^path)) (if (> (length new-value) 0) (tk-format `(:variable ,self) "~a insert end ~a" (^path) new- value)))) With this and my fileevent stuff I can now say: ;; Model for a simple terminal output window. (defmodel fileevent-test-window (window) () (:default-initargs :kids (c? (the-kids (mk-stack (:packing (c?pack-self)) (mk-label :text "Receive window" :pady 10) (mk-text-widget :id :receive-window ;:state 'disabled :md-value (c-in "") :height 10 :width 80 :borderwidth 2 :relief 'sunken :pady 5)) (mk-fileevent :id :fileevent-test :read-fn 'read-from-pipe :iostream (open "/Users/frgo/tmp/frgo-test" :direction :input)))))) ;; The method read-from-pipe reads data from a pipe generated by ;; mkfifo /Users/frgo/tmp/frgo-test and puts this as the data of a ;; text widget (defmethod read-from-pipe ((self tk-fileevent) &optional (operation :read)) (declare (ignorable operation)) (let ((stream (^iostream))) (let ((data (read-line stream nil nil nil))) (trc "*** READ-FROM-PIPE: data = " data) (when data (setf (md-value (fm-other :receive-window)) data)))) ) ;; Test function that fires up the test case (defun test-fileevent () (trc "----------------------------------------------------------------------- ------") (test-window 'fileevent-test-window) (trc "----------------------------------------------------------------------- ------") ) Now, whenever I do a $ echo "Heya this is a test" > /Users/frgo/tmp/frgo-test the text gets displayed in the window. Of course there's other uses for this: You also can open a socket and send application commands to the application. The read-from-pipe function would then be a little interpreter kicking of actions in the application... For me I put the reading function to listen to a RS232C port that is connected to an AVR-based microcontroller. The controller send status information and voltage and current values from a power supply to be displayed as info by my application... Fileevent to be put to Celtk CVS in a few days ... watch out. Frank