[squeak-dev] Form asSomethingOrOther

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

[squeak-dev] Form asSomethingOrOther

Casey Ransberger
I have a Form (for use as a button) that I would like to serialize in a way that allows me to keep it as text in a method. I would like to do this the simplest way possible, optimizing for speed (not space.) Ideally it would look as much like this as possible:

Foo>>someIcon
    ^ #( ... ) asForm

What's the best way to do this?

--
Ron


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Form asSomethingOrOther

Damien Cassou-3
On Thu, Aug 27, 2009 at 7:22 AM, Ronald Spengler<[hidden email]> wrote:
> Foo>>someIcon
>     ^ #( ... ) asForm
> What's the best way to do this?

ImageReadWriter formFromStream: (ReadStream on: #(171 222 222 243...)
asByteArray)


--
Damien Cassou
http://damiencassou.seasidehosting.st

"Lambdas are relegated to relative obscurity until Java makes them
popular by not having them." James Iry

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Form asSomethingOrOther

Damien Cassou-3
In reply to this post by Casey Ransberger
On Thu, Aug 27, 2009 at 7:22 AM, Ronald Spengler<[hidden email]> wrote:
> Foo>>someIcon
>     ^ #( ... ) asForm
> What's the best way to do this?

To convert the picture to a byte array:

 This code needs a Seaside utility class to install the PNG file as a
ByteArray. Edit the generated code afterwards so that it runs without
Seaside installed (just remove the cache hack) or without the
NewCompiler (change to an array literal and send asByteArray)
        | data code |
        data := FileStream
                fileNamed: 'sqflogo.png'
                do: [:f | f binary contentsOfEntireFile].
        code := SeasidePlatformSupport asMethodReturningByteArray: data
named: #sqfLogoPng.
        SeasidePlatformSupport
                compile: code
                into: DEVImageCreator class
                classified: 'private - generated'


--
Damien Cassou
http://damiencassou.seasidehosting.st

"Lambdas are relegated to relative obscurity until Java makes them
popular by not having them." James Iry

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Form asSomethingOrOther

Randal L. Schwartz
In reply to this post by Casey Ransberger
>>>>> "Ronald" == Ronald Spengler <[hidden email]> writes:

Ronald> I have a Form (for use as a button) that I would like to serialize in
Ronald> a way that allows me to keep it as text in a method. I would like to
Ronald> do this the simplest way possible, optimizing for speed (not space.)
Ronald> Ideally it would look as much like this as possible:
Foo> someIcon
Ronald>     ^ #( ... ) asForm

Ronald> What's the best way to do this?

Maybe "Form class >> #extent:depth:fromArray:offset:" will be of use.

Which is of course what the #storeString returns. :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Form asSomethingOrOther

Colin Putney
In reply to this post by Casey Ransberger

On 26-Aug-09, at 10:22 PM, Ronald Spengler wrote:

> I have a Form (for use as a button) that I would like to serialize  
> in a way that allows me to keep it as text in a method. I would like  
> to do this the simplest way possible, optimizing for speed (not  
> space.) Ideally it would look as much like this as possible:
>
> Foo>>someIcon
>     ^ #( ... ) asForm
>
> What's the best way to do this?

Create your form, then send #storeString to it. It will answer a  
Smalltalk expression that recreates the form. Then just answer that  
expression from your #someIcon method. OmniBrowser has a few examples  
of this in the class OBMorphicIcons.

Colin

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Form asSomethingOrOther

Casey Ransberger
We have a winner!

Thank you, Colin:)

On Wed, Aug 26, 2009 at 11:18 PM, Colin Putney <[hidden email]> wrote:

On 26-Aug-09, at 10:22 PM, Ronald Spengler wrote:

I have a Form (for use as a button) that I would like to serialize in a way that allows me to keep it as text in a method. I would like to do this the simplest way possible, optimizing for speed (not space.) Ideally it would look as much like this as possible:

Foo>>someIcon
   ^ #( ... ) asForm

What's the best way to do this?

Create your form, then send #storeString to it. It will answer a Smalltalk expression that recreates the form. Then just answer that expression from your #someIcon method. OmniBrowser has a few examples of this in the class OBMorphicIcons.

Colin




--
Ron


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Form asSomethingOrOther

Casey Ransberger
Holy cow! This method is on Object. I can do this with anything that inherits from Object?

On Wed, Aug 26, 2009 at 11:26 PM, Ronald Spengler <[hidden email]> wrote:
We have a winner!

Thank you, Colin:)


On Wed, Aug 26, 2009 at 11:18 PM, Colin Putney <[hidden email]> wrote:

On 26-Aug-09, at 10:22 PM, Ronald Spengler wrote:

I have a Form (for use as a button) that I would like to serialize in a way that allows me to keep it as text in a method. I would like to do this the simplest way possible, optimizing for speed (not space.) Ideally it would look as much like this as possible:

Foo>>someIcon
   ^ #( ... ) asForm

What's the best way to do this?

Create your form, then send #storeString to it. It will answer a Smalltalk expression that recreates the form. Then just answer that expression from your #someIcon method. OmniBrowser has a few examples of this in the class OBMorphicIcons.

Colin




--
Ron



--
Ron


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Form asSomethingOrOther

Randal L. Schwartz
>>>>> "Ronald" == Ronald Spengler <[hidden email]> writes:

Ronald> Holy cow! This method is on Object. I can do this with anything that
Ronald> inherits from Object?

Welcome to Smalltalk.  First time here? :)

Obviously, there are some objects it doesn't work so well on,
but in general, yeah.

Of course, if you already have a stream, use #storeOn: instead.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Form asSomethingOrOther

Randal L. Schwartz
>>>>> "Randal" == Randal L Schwartz <[hidden email]> writes:

Randal> Of course, if you already have a stream, use #storeOn: instead.

As in:

    YourClass compile:
      (String streamContents: [:stream |
        stream nextPutAll: 'someMethodName'; cr; tab; nextPutAll: '^ '.
        yourForm storeOn: stream
    ]).

There.  Installs #someMethodName in YourClass, which answers yourForm.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Form asSomethingOrOther

Bert Freudenberg
In reply to this post by Colin Putney

On 27.08.2009, at 08:18, Colin Putney wrote:

>
> On 26-Aug-09, at 10:22 PM, Ronald Spengler wrote:
>
>> I have a Form (for use as a button) that I would like to serialize  
>> in a way that allows me to keep it as text in a method. I would  
>> like to do this the simplest way possible, optimizing for speed  
>> (not space.) Ideally it would look as much like this as possible:
>>
>> Foo>>someIcon
>>    ^ #( ... ) asForm
>>
>> What's the best way to do this?
>
> Create your form, then send #storeString to it. It will answer a  
> Smalltalk expression that recreates the form. Then just answer that  
> expression from your #someIcon method. OmniBrowser has a few  
> examples of this in the class OBMorphicIcons.


This is the simplest way, no doubt. If you care for the code size you  
might use something like the stuff below.

In this case, #storeString is 9371 bytes vs. 1580 bytes using a base64-
encoded PNG (that compresses well).

- Bert -

biggerNormal
        "self biggerNormal show"
        "(Base64MimeConverter mimeEncode: ((FileStream readOnlyFileNamed:  
'EtoysCursor.png') binary)) upToEnd"

        ^self constants at: #biggerNormal ifAbsentPut: [
                | form cursor |
                form := (PNGReadWriter on: (Base64MimeConverter mimeDecodeToBytes:
                        'iVBORw0KGgoAAAANSUhEUgAAABsAAAArCAYAAACJrvP4AAAACXBIWXMAAAsTAAALEwEAmpwY
                        AAAEF0lEQVRYCb2XS0hcVxjHj2/
G8ZWMQQbSGO2iRhERwRALBmJNoOOqwUXtYtxOTQJxI8SN
                        CyXJqggVEghusrAuBB8IddUWF64CvnCj+AJrsYKio6JJOPn/j+dc5s6MztyZMR/
857v3PL7f
                        /
c4595w7QmiTUvrN9ZV7wGhfB3jOunpgOoYtPQQm19fXn6DsulY2PJUSi4ARvLm5+SuiE5hS
                         
mAsBXSYzv99vLuXExMRL1H2jlRKoDYbAMhS4uLj4PJUwN4K5TTqEhQPHxsZeayCzTCrDqLC0
                        tLQryTAqjNmFA1OR4YWwaMBk5/
BSWDRgMhnGhEUDJpphXDACqdDXIpEMHcHCF43TDB3Bks0w
                        IVj4kMabYcKwcGA8c
+gIlp2drRaKGc5wYKwMHcFycnIiYOHACzLkhi9SAgsHRsnQOSzaMBJk
                         
FPoejo6OvkJ5iZY67R1lZoJe5kOBKysrzxzBCgoKrCcnpKysTO7v75sjMKafmZl5gX6uNPww
                         
M4EeQXrsEAJDJc7Ozngr8vPzRVVVldjZ2RGrq6uqrLi4WPT394u2tjZxeHj4P8C7qiLkJzMz
                        8zNvc3NzT+jR/
yl9xDBmZWWpTAoLC2V9fb3c29uTXV1dtuwaGxtVRgcHBzuI0QY91vLBUw+0
                        voOnXPyyijBEUWWVlZViampKFBUVCcyDKC8vt9pitYnp6WlmfqO7u/
uOVRHjIiKzjIwM2dDQ
                        oDIKnZCWlhZbdoFAQFUvLCz8Bcb3WrfgqWItFR/
XKrEIWG1trQWam5v7Z3Bw8C2jjoyMyNLS
                        UgvIYeYQ05A5h5HA+GE1NTVWgPn5+b/RubWiosJ/enoaZNDq6moLhjrZ19fHYjk7O/
sO9/eg
                        G1oZ8JTNbJmZJ9Wgn9GyleJQMWhPT48NhnllsTw+Pv4X7WLCuI1YX8TsuLy8/
CfKmrXuwt9t
                        b2//
iXX4LJder9cCut1uOT4+zio5PDz8G9pWaqm4uLaZDaZBXLY2GO4bdnd3PzAowDZYc3Mz
                        i+X29vY82l0K4ypR/
2JOTk7e49qsIuMLUEbdXFpaes6gk5OT0uPxWECeBGtra6ySvb29v6Bt
                         
ve7DfjZTsKOjo99RyvkzEOMtGOpuBoPBbQblQsK9Ejfnzs5OFsuNjY0JlF8IQ11clodWeVgo
                        bxh0YGDABmOmNGxzh2j3EPJqRV2VqLvUFKyjo+NHBuWqxb4nS0pKVFZmGFG
+gihJw8wTerHx
                        /kEgXng6y7a2thYxnAHAHkHfavEcoxyZBcOh+AOHixS+7HwnfT4f/
6nynSQoaZh5MjWcTU1N
                        94aGhtrr6up8qLgPcVFQd7SuwVPmIdN5njk1wmi31a8QHu3VuYVrLhDaf
+dOHGgvE4Gp3RsB
                        cnUQMx+f9P1H7c9PXyHUIcoy01HXX637AibwgHAnFRPGAAAAAElFTkSuQmCC'
                                readStream)) nextImage.
                cursor := CursorWithAlpha extent: form extent depth: 32.
                form displayOn: cursor.
                cursor offset: -2@-1.
                cursor preMultiplyAlpha.
                cursor]