Search code examples
smalltalkpharoerase

How to clear a cluttered workspace in Pharo?


In the Pharo MOOC there is a proposed challenge (section 2.15.2) that consists in taking a email address and getting the associated gravatar image, as a Morph object. I was able to do it, by running the following code in the playground:

| url email |
email := 'stephane.ducasse@inria.fr'.
url := 'http://www.gravatar.com/avatar/', (MD5 hashMessage: email) hex asString , '.jpg'.
(ZnEasy getJpeg: url) asMorph openInHand.

Now the problem is, I could not figure out how to properly clean my workspace of all the objects downloaded:

enter image description here

As you can see, now I have the image from the url (from a previous botched attempt where I did url asMorph openInHand without getting the jpg with ZnEasy first), and several lighthouse images (as every time I open the inspector a new one is generated).

I say properly clean because you can just exit Pharo without saving, and then open it again to have a clean workspace, but this is probably not ideal.

So far I tried to inspect the created objects, seeing they are instances of ImageMorph. Then in the associated methods I searched something including "erase", "del", "delete" or "clear", but could not find anything similar. These were the available methods for ImageMorph:

{ImageMorph>>#prepareForRotating. 
ImageMorph>>#grabFromScreen. 
ImageMorph>>#forwardDirection:. 
ImageMorph>>#adoptPaneColor:. 
ImageMorph>>#drawOnAthensCanvas:. 
ImageMorph>>#extent:. 
ImageMorph>>#setOptimalResizing. 
ImageMorph>>#form:. 
ImageMorph>>#shouldFlex. 
ImageMorph>>#forwardDirection. 
ImageMorph>>#resize:. 
ImageMorph>>#areasRemainingToFill:. 
ImageMorph>>#heading. 
ImageMorph>>#imageExport. 
ImageMorph>>#defaultImage. 
ImageMorph>>#rotationDegrees. 
ImageMorph>>#borderStyle:. 
ImageMorph>>#opacityString. 
ImageMorph>>#setDirectionFrom:. 
ImageMorph>>#rotationDegrees:. 
ImageMorph>>#borderWidth:. 
ImageMorph>>#isOpaque. 
ImageMorph>>#image:. 
ImageMorph>>#readFromFile. 
ImageMorph>>#drawOn:. 
ImageMorph>>#basicExtent:. 
ImageMorph>>#form. 
ImageMorph>>#withSnapshotBorder. 
ImageMorph>>#wantsRecolorHandle. 
ImageMorph>>#changeOpacity. 
ImageMorph>>#initialize. 
ImageMorph>>#addCustomMenuItems:hand:. 
ImageMorph>>#isOpaque:. 
ImageMorph>>#releaseCachedState. 
ImageMorph>>#color:}

I also tried to execute garbageCollect, and just click the images and press Delete.


Solution

  • After opening them in the hand, you have positioned them in the world. If you inspect the world, you'll see there are a number of ImageMorphs. You want to exclude the Pharo logo. If you inspect that, its extension tells you the logo is locked.

    World submorphs select: [ :m | 
        m class = ImageMorph and: [ 
        m isLocked not ] ] 
    thenDo: [ :m | m delete ]