SketchMorph power tool: copy as code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SketchMorph power tool: copy as code

Tim Johnson-2
Hi,

Here is a very simple change that allows one to activate the Morph menu -> "copy & paste" -> "copy text" to get textual (code) representation of the SketchMorph's form.  It simply (and rather inappropriately) implements #userString for a SketchMorph.  The resulting string can be pasted into a method or workspace or what-have-you in order to recreate the form.

I don't recommend using this in production, because:  looking at senders of #userString, I suspect this would have a negative impact on BookMorph, StackMorph, and perhaps some other places where #userString is used to access human-readable text in text-oriented Morphs.  So, perhaps this would be more appropriate as an additional item under the "painting" or "export" submenus.  Maybe it could even be generalized for all Morphs rather than just SketchMorphs.  I welcome decision-makers to make decisions about possibly using this code in some similar way, because I think it's useful and fun.

Below are two versions of it.  The second version allows the user to opt-out of using  #colorReduced .

-- snip --

'From Squeak5.2 of 22 January 2019 [latest update: #18231] on 2 March 2019 at 9:06:36 am'!

!SketchMorph methodsFor: 'menus' stamp: 'tcj 3/2/2019 08:58'!
userString
        | s |
        "present textual representation of myself for Morph 'Copy text' menu item"
        s := String new writeStream.
        self form colorReduced storeOn: s.
        ^ s close contents! !

-- snip --

'From Squeak5.2 of 22 January 2019 [latest update: #18231] on 2 March 2019 at 9:03:23 am'!

!SketchMorph methodsFor: 'menus' stamp: 'tcj 3/2/2019 09:02'!
userString
        | s |
        "present textual representation of myself for Morph 'Copy text' menu item"
        s := String new writeStream.
        ( ( self confirm: 'reduce colors?' )
                ifTrue: [ self form colorReduced ]
                ifFalse: [ self form ] ) storeOn: s.
        ^ s close contents! !

-- snip --

Cheers,
Tim J


Reply | Threaded
Open this post in threaded view
|

Re: SketchMorph power tool: copy as code

Eliot Miranda-2
Hi Tim,

On Sat, Mar 2, 2019 at 9:26 AM Tim Johnson <[hidden email]> wrote:
Hi,

Here is a very simple change that allows one to activate the Morph menu -> "copy & paste" -> "copy text" to get textual (code) representation of the SketchMorph's form.  It simply (and rather inappropriately) implements #userString for a SketchMorph.  The resulting string can be pasted into a method or workspace or what-have-you in order to recreate the form.

I don't recommend using this in production, because:  looking at senders of #userString, I suspect this would have a negative impact on BookMorph, StackMorph, and perhaps some other places where #userString is used to access human-readable text in text-oriented Morphs.  So, perhaps this would be more appropriate as an additional item under the "painting" or "export" submenus.  Maybe it could even be generalized for all Morphs rather than just SketchMorphs.  I welcome decision-makers to make decisions about possibly using this code in some similar way, because I think it's useful and fun.

You are that person.  You have as much right and skill to make decisions for Squeak as any of us.  I encourage you to write something that satisfies you and either submit it to the inbox or the trunk, depending on how reliable and/or disruptive you find it too be.  Please don't defer to others who, like you may not feel profoundly confident, and who, like you are busy and consumed with their own projects.  This is a community process.  We can all try and find our authority, to the benefit of all in this community.
 

Below are two versions of it.  The second version allows the user to opt-out of using  #colorReduced .

-- snip --

'From Squeak5.2 of 22 January 2019 [latest update: #18231] on 2 March 2019 at 9:06:36 am'!

!SketchMorph methodsFor: 'menus' stamp: 'tcj 3/2/2019 08:58'!
userString
        | s |
        "present textual representation of myself for Morph 'Copy text' menu item"
        s := String new writeStream.
        self form colorReduced storeOn: s.
        ^ s close contents! !

-- snip --

'From Squeak5.2 of 22 January 2019 [latest update: #18231] on 2 March 2019 at 9:03:23 am'!

!SketchMorph methodsFor: 'menus' stamp: 'tcj 3/2/2019 09:02'!
userString
        | s |
        "present textual representation of myself for Morph 'Copy text' menu item"
        s := String new writeStream.
        ( ( self confirm: 'reduce colors?' )
                ifTrue: [ self form colorReduced ]
                ifFalse: [ self form ] ) storeOn: s.
        ^ s close contents! !

-- snip --

Cheers,
Tim J




--
_,,,^..^,,,_
best, Eliot


Reply | Threaded
Open this post in threaded view
|

Re: SketchMorph power tool: copy as code

Karl Ramberg
In reply to this post by Tim Johnson-2
Hi,
This will be very useful. 

Best,
Karl