Re: Beginners Digest, Vol 123, Issue 4

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

Re: Beginners Digest, Vol 123, Issue 4

Tim Cuthbertson
Tim,

> One of the articles on Morphic says you can create composite morphs either programatically,
> using addMorph, or using drag and drop from the Objects menu of the morphic World. I have
> done the latter, because it is easier to design my layout that way. Once that has been done,
> how do I address the submorph from a browser? If I inspect my button submorph, for example
>, all it will tell me about it is "a ScriptableButton<Button>(1364754)". I have no idea how to
> access that object in order to do anything with it. This is the crux of my questions.

This is, in my opinion, the most significant limitation of Morphic for
interactive GUI creation. In the original Morphic in Self the way to
handle this was to simply search through all your submorphs for the one
you were interested in, usually by comparing the morphType string. In
Squeak we can add properties to Morphs very easily so that would be one
way to tag it. Something like:

| stopButton |
stopButton := nil.
self submorphsDo: [ :m | (m hasProperty: #stopButton) ifTrue: [
                               stopButton := m ] ].
stopButton ifNotNilDo: [ :b | b ... ].

Code like this will work even if there are no stopButtons at all and if
you add more than one the code will just use the last one and ignore the
others.

After creating the button you have to get its halo and use the red
button (menu) with the debug->inspect morph option to set the
#stopButton property.

An alternative to using specially created properties is to depend on the
morph's name. In your case it is "a ScriptableButton<Button>(1364754)"..
So:

self subMorphsDo: [ :m | (m name includesSubString: 'Button') ifTrue:
...

should work for you as long as there is only one button.

-- Jecel

Thank you, Jecel, for trying to help me solve my problem. However, my plan is to have multiple sibling morphs for both the buttons and the texts.

So, I am diving in to trying to use addMorph: programatically to add submorphs to my display. This allows me to hold a reference to each submorph in named variables, through which I should then be able to specify state changes and act on events to and from my submorphs.

Maybe my mindset is just too old fashioned. Back in the 90's, I programmed MVC applications in VisualWorks. I thought Morphic was supposed to be much easier to use than MVC, but so far, I have not been able to figure out how to control my objects in Morphic.

Tim Cuthbertson


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Beginners Digest, Vol 123, Issue 4

Hannes Hirzel
Assuming you have named your instances of TextMorph and embedded them
in the PasteUpMorph so that they are in the 'submorphs' collection of
the PasteUpMorph

you may access them by name from the PasteUpMorph with


   self submorphs detect: [:m | m externalName = 't1']

(access to morph named 't1').

This is a moderate effort and allows you to construct the GUI through
direct manipulation.

Please note as well that in a recent trunk image the halo menu list of
a SimpleButtonMorph has a 'set target' menu entry which allows you to
set to any target by pointing at it.

--Hannes


On 2/22/17, Tim Cuthbertson <[hidden email]> wrote:

> Tim,
>
>> One of the articles on Morphic says you can create composite morphs
> either programatically,
>> using addMorph, or using drag and drop from the Objects menu of the
> morphic World. I have
>> done the latter, because it is easier to design my layout that way. Once
> that has been done,
>> how do I address the submorph from a browser? If I inspect my button
> submorph, for example
>>, all it will tell me about it is "a ScriptableButton<Button>(1364754)". I
> have no idea how to
>> access that object in order to do anything with it. This is the crux of
> my questions.
>
> This is, in my opinion, the most significant limitation of Morphic for
> interactive GUI creation. In the original Morphic in Self the way to
> handle this was to simply search through all your submorphs for the one
> you were interested in, usually by comparing the morphType string. In
> Squeak we can add properties to Morphs very easily so that would be one
> way to tag it. Something like:
>
> | stopButton |
> stopButton := nil.
> self submorphsDo: [ :m | (m hasProperty: #stopButton) ifTrue: [
>                                stopButton := m ] ].
> stopButton ifNotNilDo: [ :b | b ... ].
>
> Code like this will work even if there are no stopButtons at all and if
> you add more than one the code will just use the last one and ignore the
> others.
>
> After creating the button you have to get its halo and use the red
> button (menu) with the debug->inspect morph option to set the
> #stopButton property.
>
> An alternative to using specially created properties is to depend on the
> morph's name. In your case it is "a ScriptableButton<Button>(1364754)"..
> So:
>
> self subMorphsDo: [ :m | (m name includesSubString: 'Button') ifTrue:
> ...
>
> should work for you as long as there is only one button.
>
> -- Jecel
>
> Thank you, Jecel, for trying to help me solve my problem. However, my plan
> is to have multiple sibling morphs for both the buttons and the texts.
>
> So, I am diving in to trying to use addMorph: programatically to add
> submorphs to my display. This allows me to hold a reference to each
> submorph in named variables, through which I should then be able to specify
> state changes and act on events to and from my submorphs.
>
> Maybe my mindset is just too old fashioned. Back in the 90's, I programmed
> MVC applications in VisualWorks. I thought Morphic was supposed to be much
> easier to use than MVC, but so far, I have not been able to figure out how
> to control my objects in Morphic.
>
> Tim Cuthbertson
>

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

selecting_a_submorph_by_name_2017-02-23.png (78K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

submorphs (was: Beginners Digest, Vol 123, Issue 4)

Jecel Assumpcao Jr
In reply to this post by Tim Cuthbertson
Tim,

> Thank you, Jecel, for trying to help me solve my problem. However, my plan is
> to have multiple sibling morphs for both the buttons and the texts.

Code like this can get you a list of all buttons:

| buttons |
buttons := submorphs select: [ :m | m name includesSubString: 'Button')
].

You can do the same thing to get a list of text fields, but the order of
texts and buttons might not match. The order depends on when submorphs
are added and removed and not on they physical position.

> So, I am diving in to trying to use addMorph: programatically to add submorphs
> to my display. This allows me to hold a reference to each submorph in named
> variables, through which I should then be able to specify state changes and act
> on events to and from my submorphs.

Nearly all code you will find in Squeak uses this style. And note that
if your main morph isn't temporary, you can still manually reorganize
the submorphs even if they were created programatically. It might be
tricky to have them stay the way you want as the main morph gets
changed.

> Maybe my mindset is just too old fashioned. Back in the 90's, I programmed MVC
> applications in VisualWorks. I thought Morphic was supposed to be much easier
> to use than MVC, but so far, I have not been able to figure out how to control my
> objects in Morphic.

When Morphic was introduced in Squeak, we already had a bunch of MVC
applications that we wanted to keep using without having to
significantly rewrite them.  So the reasonably simple Morphic from Self
became a much more complicated framework.

The layout concept in the original Morphic was borrowed from TeX. The
idea is that by having nested boxes with three simple alternatives
(fixed, shrink-wrap and stretch) in each dimension (horizontal and
vertical) you could use direct manipulation to build most interesting
GUI elements. The most significant exception is tables since you can
only align on rows or on columns but not on both with nested boxes.

MVC, on the other hand, used pieces of code in a simple constraint
system to define layouts. So Squeak Morphic ended up with a combination
of both. And with a fix to the table problem. The unfortunate result is
that it isn't always easy to figure out why the submorphs are positioned
as they are.

Back to your problem: suppose you want a bunch of pairs of buttons and
text fields, one under the other. You could do something like:

| col row button text fields |
col := AlignmentMorph newColumn.
fields Dictionary new.
1 to: 7 do: [ :i |
        row := AlignmentMorph newRow.
        col addMorph: row.
        button := PluggableButtonMorph new.
        text := TextFieldMorph new.
        row addMorph: button.
        row addMorph: text.
        fields at: button put: text.
        ].

There is probably a "self changed" missing somewhere in there. And it
might be a good idea to put a stretching morph between the button and
the text if you want the align the first to the left and the text to the
right. With the table layout the 7 row morphs shown here are probably
not needed. But I hope this gives you the basic idea.

-- Jecel
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Beginners Digest, Vol 123, Issue 4

Tobias Pape
In reply to this post by Hannes Hirzel

On 23.02.2017, at 00:34, H. Hirzel <[hidden email]> wrote:

> Assuming you have named your instances of TextMorph and embedded them
> in the PasteUpMorph so that they are in the 'submorphs' collection of
> the PasteUpMorph
>
> you may access them by name from the PasteUpMorph with
>
>
>   self submorphs detect: [:m | m externalName = 't1']

self submorphNamed: 't1'

>
> (access to morph named 't1').
>
> This is a moderate effort and allows you to construct the GUI through
> direct manipulation.
>
> Please note as well that in a recent trunk image the halo menu list of
> a SimpleButtonMorph has a 'set target' menu entry which allows you to
> set to any target by pointing at it.
>
> --Hannes
>
>
> On 2/22/17, Tim Cuthbertson <[hidden email]> wrote:
>> Tim,
>>
>>> One of the articles on Morphic says you can create composite morphs
>> either programatically,
>>> using addMorph, or using drag and drop from the Objects menu of the
>> morphic World. I have
>>> done the latter, because it is easier to design my layout that way. Once
>> that has been done,
>>> how do I address the submorph from a browser? If I inspect my button
>> submorph, for example
>>> , all it will tell me about it is "a ScriptableButton<Button>(1364754)". I
>> have no idea how to
>>> access that object in order to do anything with it. This is the crux of
>> my questions.
>>
>> This is, in my opinion, the most significant limitation of Morphic for
>> interactive GUI creation. In the original Morphic in Self the way to
>> handle this was to simply search through all your submorphs for the one
>> you were interested in, usually by comparing the morphType string. In
>> Squeak we can add properties to Morphs very easily so that would be one
>> way to tag it. Something like:
>>
>> | stopButton |
>> stopButton := nil.
>> self submorphsDo: [ :m | (m hasProperty: #stopButton) ifTrue: [
>>                               stopButton := m ] ].
>> stopButton ifNotNilDo: [ :b | b ... ].
>>
>> Code like this will work even if there are no stopButtons at all and if
>> you add more than one the code will just use the last one and ignore the
>> others.
>>
>> After creating the button you have to get its halo and use the red
>> button (menu) with the debug->inspect morph option to set the
>> #stopButton property.
>>
>> An alternative to using specially created properties is to depend on the
>> morph's name. In your case it is "a ScriptableButton<Button>(1364754)"..
>> So:
>>
>> self subMorphsDo: [ :m | (m name includesSubString: 'Button') ifTrue:
>> ...
>>
>> should work for you as long as there is only one button.
>>
>> -- Jecel
>>
>> Thank you, Jecel, for trying to help me solve my problem. However, my plan
>> is to have multiple sibling morphs for both the buttons and the texts.
>>
>> So, I am diving in to trying to use addMorph: programatically to add
>> submorphs to my display. This allows me to hold a reference to each
>> submorph in named variables, through which I should then be able to specify
>> state changes and act on events to and from my submorphs.
>>
>> Maybe my mindset is just too old fashioned. Back in the 90's, I programmed
>> MVC applications in VisualWorks. I thought Morphic was supposed to be much
>> easier to use than MVC, but so far, I have not been able to figure out how
>> to control my objects in Morphic.
>>
>> Tim Cuthbertson
>>
> <selecting_a_submorph_by_name_2017-02-23.png>_______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Beginners Digest, Vol 123, Issue 4

Hannes Hirzel
On 2/23/17, Tobias Pape <[hidden email]> wrote:

>
> On 23.02.2017, at 00:34, H. Hirzel <[hidden email]> wrote:
>
>> Assuming you have named your instances of TextMorph and embedded them
>> in the PasteUpMorph so that they are in the 'submorphs' collection of
>> the PasteUpMorph
>>
>> you may access them by name from the PasteUpMorph with
>>
>>
>>   self submorphs detect: [:m | m externalName = 't1']
>
> self submorphNamed: 't1'

Thanks, Tobias

And accessing it as a sibling morph (i.e. from another morph embedded
in the PasteUpMorph as well)  would then be

     self owner submorphNamed: 't1'


>>
>> (access to morph named 't1').
>>
>> This is a moderate effort and allows you to construct the GUI through
>> direct manipulation.
>>
>> Please note as well that in a recent trunk image the halo menu list of
>> a SimpleButtonMorph has a 'set target' menu entry which allows you to
>> set to any target by pointing at it.
>>
>> --Hannes
>>
>>
>> On 2/22/17, Tim Cuthbertson <[hidden email]> wrote:
>>> Tim,
>>>
>>>> One of the articles on Morphic says you can create composite morphs
>>> either programatically,
>>>> using addMorph, or using drag and drop from the Objects menu of the
>>> morphic World. I have
>>>> done the latter, because it is easier to design my layout that way. Once
>>> that has been done,
>>>> how do I address the submorph from a browser? If I inspect my button
>>> submorph, for example
>>>> , all it will tell me about it is "a ScriptableButton<Button>(1364754)".
>>>> I
>>> have no idea how to
>>>> access that object in order to do anything with it. This is the crux of
>>> my questions.
>>>
>>> This is, in my opinion, the most significant limitation of Morphic for
>>> interactive GUI creation. In the original Morphic in Self the way to
>>> handle this was to simply search through all your submorphs for the one
>>> you were interested in, usually by comparing the morphType string. In
>>> Squeak we can add properties to Morphs very easily so that would be one
>>> way to tag it. Something like:
>>>
>>> | stopButton |
>>> stopButton := nil.
>>> self submorphsDo: [ :m | (m hasProperty: #stopButton) ifTrue: [
>>>                               stopButton := m ] ].
>>> stopButton ifNotNilDo: [ :b | b ... ].
>>>
>>> Code like this will work even if there are no stopButtons at all and if
>>> you add more than one the code will just use the last one and ignore the
>>> others.
>>>
>>> After creating the button you have to get its halo and use the red
>>> button (menu) with the debug->inspect morph option to set the
>>> #stopButton property.
>>>
>>> An alternative to using specially created properties is to depend on the
>>> morph's name. In your case it is "a ScriptableButton<Button>(1364754)"..
>>> So:
>>>
>>> self subMorphsDo: [ :m | (m name includesSubString: 'Button') ifTrue:
>>> ...
>>>
>>> should work for you as long as there is only one button.
>>>
>>> -- Jecel
>>>
>>> Thank you, Jecel, for trying to help me solve my problem. However, my
>>> plan
>>> is to have multiple sibling morphs for both the buttons and the texts.
>>>
>>> So, I am diving in to trying to use addMorph: programatically to add
>>> submorphs to my display. This allows me to hold a reference to each
>>> submorph in named variables, through which I should then be able to
>>> specify
>>> state changes and act on events to and from my submorphs.
>>>
>>> Maybe my mindset is just too old fashioned. Back in the 90's, I
>>> programmed
>>> MVC applications in VisualWorks. I thought Morphic was supposed to be
>>> much
>>> easier to use than MVC, but so far, I have not been able to figure out
>>> how
>>> to control my objects in Morphic.
>>>
>>> Tim Cuthbertson
>>>
>> <selecting_a_submorph_by_name_2017-02-23.png>_______________________________________________
>> Beginners mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners