Accessing Morphs as objects
Richard A. O'Keefe
ok at cs.otago.ac.nz
Wed Jun 5 04:02:16 UTC 2002
Geza Lakner MD <geza67 at freestart.hu> wrote:
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. The System Browser shows *CLASSES*.
You can. Use the browser to find the class you want.
Select the class name (in the class pane of the browser).
Use Option-click to bring up a menu.
The menu starts
browse full (b)
browse hierarchy (h)
and ends with
find method...
more...
Choose the last entry, more... and that will show you the rest of the menu:
unsent methods
unreferenced inst vars
subclass template
----> sample instance
----> inspect instances
----> inspect subinstances
fetch documentation
add all meths to current chgs
more...
For example, when I select the class Morph and ask to
"inspect instances" I get an inspector on an array, with title
"The 297 instances of Morph".
So, from the browser you can *get to* instances, viewing instances using
inspectors and explorers, but you can't *browse* instances.
Even if these on-screen objects are merely
prototypes and no instances,
EVERYTHING in Smalltalk is an instance (of some class).
The on-screen thingies you get from "new morph..." are most certainly
instances of Morphic classes.
how can I derive a _usable_ new class from them?
What's the reason you want a new class?
Here's one method.
Create a new class Wendigone.
Give it a class variable Prototype.
Give it a class method
setPrototype: aMorph
Prototype := aMorph
Give it another class method
new
^Prototype duplicate
Open a workspace.
Set the 'start accepting dropping morph for reference' option.
Type
Wendigone setPrototype:
Drag the morph onto the workspace.
Now you see something like
Wendigone setPrototype: newhandle637
Do-it.
Now you can do
Wendigone new
and you'll get a new veryDeepCopy of the Morph you started with.
More information about the Squeak-dev
mailing list
|