[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Question about Presentations
Date: Fri, 12 Oct 90 14:50:08+0900
From: kddlab!harl.hitachi.co.jp!mklein@uunet.uu.net
I am trying to "present" an object to a screen with a label different
from the usual printed representation of the object. When I mouse-select
the label during an "accept" call, I want to have accept return the
presented object.
I tried the following simple function:
(defun present-as (object label &key (stream *standard-output*))
"Presents object to stream with given label"
(dw:with-output-as-presentation (:single-box t
:type (type-of object)
:stream stream
:object object)
(format stream "~a" label)))
When I present a structure instance, typing (accept 'sys:expression) and
clicking on the screen representation returns the original instance.
However, when I present an instance of flavor "frame" (a flavor I define
in my code), I get the following curious behaviour:
(1) using (accept 'frame) and clicking returns the original instance
(2) using (accept 'sys:expression) and clicking returns the label!
I want to use (accept 'sys:expression) because I have several different
kinds of presented objects that I want all to be mouse-selectable.
I imagine this is a failure in my understanding of presentations rather
than a bug. Could someone suggest how I can achieve the behaviour I desire?
Thanks very much,
Mark Klein
Hitachi Ltd.
Advanced Research Lab
Hatoyama, Saitama 350
Japan
Konban wa, Kurain-san.
The problem is your use of (FORMAT STREAM "~A" LABEL), if label
is not a string, creates a presentation, because FORMAT calls
WRITE in that case. This presentation will be a SYMBOL presentation,
and since SYMBOL is a subtype of EXPRESSION, it will satisfy your
call to ACCEPT. (When multiple presentations could apply, the system
always chooses the innermost).
Here are a couple ways to do what you want:
(defun present-as (object label &key (stream *standard-output*))
"Presents object to stream with given label"
(dw:with-output-as-presentation (:single-box t
:type (type-of object)
:stream stream
:object object)
(format stream "~a" (string label))))
Or more efficiently:
(defun present-as (object label &key (stream *standard-output*))
"Presents object to stream with given label"
(dw:with-output-as-presentation (:single-box t
:type (type-of object)
:stream stream
:object object)
(write-string (string label) stream)))