Accessing Morphs as objects
Ned Konz
ned at bike-nomad.com
Tue Jun 4 21:25:53 UTC 2002
On Tuesday 04 June 2002 12:03 pm, Geza Lakner MD wrote:
> May be it sound trivial - and my apologies if the problem is RTFM
> ;-) - but how can I access morphs programmatically?
Mostly by writing a program that does so. There's not too much
connection between the world of direct manipulation and the world of
written Smalltalk.
One useful connection, though, is the menu option on the Workspaces
that's named something like "create text references to dropped
morphs". If you select this and drop (almost) any Morph on the
Workspace, you'll get a new binding for that Morph. You can then use
its new name in that Workspace.
> If I make a "new morph..." by the menu, let's say a Playfield,
> embed a Textmorph in it via the menu, where can I find these two
> objects in the System Browser hierarchy?
You can't find those objects, since the Browser just displays a
class-centric view. You can find their classes, and those would be
PasteUpMorph and TextMorph, respectively.
> Even if these on-screen
> objects are merely prototypes and no instances, how can I derive a
> _usable_ new class from them? I know about the "make subclass"
> menu, but making a subclass from the playfield, does NOT include
> the embedded other morphs, even the visually altered attributes
> (color, border etc.) are NOT incorporated in the freshly made
> subclass, does it seems quite unuseful for me.
You could save the constructed Morphs as prototypes, using the
drop-on-Workspace trick and saving references to these objects
somewhere globally or in another object. Then when you need one, you
could just use #dup to get one. I do this in my Connectors package
with the NCMakerButtons: they hold onto copies of Morphs that are
dropped on them as prototypes, and duplicate those prototypes to make
new Morphs.
Or you could write something that examines the new composite Morph you
wrote and writes out the text of a initialization method. There is
some vestigial support for this, as #storeString. The problem is that
it doesn't work particularly well, and will get tripped up on
internal references (including references to owners, etc.). And it
hasn't been updated in a long time.
Morph new storeString =>
'(Morph basicNew instVarAt: 1 put: 0 at 0 corner: 50 at 40; instVarAt: 2
put: nil; instVarAt: 3 put: #(); instVarAt: 4 put: nil; instVarAt: 5
put: (Color r: 0.0 g: 0.0 b: 1.0); instVarAt: 6 put: nil; yourself)'
I've started to write one of these a few times, but never quite
finished.
> Where can I find sound documentation on the programmatic connection
> of visually created/edited morphs and those place in the system
> object hierarchy?
Visually created Morphs are just instances of pre-existing Morph
classes, until you choose to make a new subclass. (though scripting
them can make new Player subclasses)
> My other problem is that what is the use of the tiles dragged out
> of the morph viewer window?
These are for use with the tile scripting (eToy) system. Depending on
what you drag out, they might become a script (if they're a full
expression), or a noun phrase for use in another script. You can drop
tiles into the right places in scripts.
> I can not drop them onto a textual
> script window (they stay afloat)
I'm not sure what you mean by a "textual script window" here, but
there is no connection between the world of tiles and the world of
Smalltalk except for the ability to view and edit tile scripts as
source text. However, once you do this you may not be able to go back
to tiles.
There is no interaction that I know of between the regular Smalltalk
browsers and other tools and the tile scripting system.
- I expected that if I drop a
> message onto a window something happens: dropiing on a morph,
> executes it;
Sorry, none of the above happens. If you want more "live" Morphs, try
looking at the MathMorphs package. Using this, most objects have a
Morphic representation.
> dropping on a script, converts into textual commands
> and appends them to the existing script.
Well, you can drop tiles onto a tile script. That's all.
> There is much to grasp in this Morphic architecture, and a
> Squeak-newbie feels lost without clear cut documentation of these
> novel features.
Don't confuse the tile scripting with Morphic. The tile scripting /
eToy system is an application built on top of Morphic.
--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
More information about the Squeak-dev
mailing list
|