How can my Morph reflect changes in the object it displays?

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

How can my Morph reflect changes in the object it displays?

MartinW
I asked the same question on Stackoverflow (http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmorph-to-a-variable-so-that-the-morph-reflects-chan) but as i do not know how much the audiences overlap i hope you do not mind if i repeat it here:

How to bind a LabelMorph/TextMorph to a variable so that the Morph reflects changes of the variable?

- I have an object with a variable containing a String.
- I have a window containing a LabelMorph/TextMorph (or some other Morph that displays Text?).
How do i bind the LabelMorph/TextMorph to the variable, so that the label updates when the String in the variable changes?

- classic Smalltalk-80 dependent/change/update mechanism?
- Pharo Announcement framework?
- something different??
How would i do this? Which Morph should i use?

Martin.
Reply | Threaded
Open this post in threaded view
|

Re: How can my Morph reflect changes in the object it displays?

Benjamin Van Ryseghem (Pharo)
For this kind of situation, my solution is to use a valueHolder

instead of storing your string directly in an inst var, store it into the value holder

initialize
string := '' asValueHolder

string: aString
string contents: aString

string
^ string contents

And then what you can do in your initialise is 

string whenChangedDo: [:newValue | self label contents: newValue ]

Something like this should work ^^


The other solution (which is baaad, but can still be seen) is to have a step method refreshing the Morph.
But this is really not efficient

Hope it helps,
Ben

On Mar 21, 2013, at 11:24 AM, MartinW <[hidden email]> wrote:

I asked the same question on Stackoverflow
(http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmorph-to-a-variable-so-that-the-morph-reflects-chan)
but as i do not know how much the audiences overlap i hope you do not mind
if i repeat it here:

How to bind a LabelMorph/TextMorph to a variable so that the Morph reflects
changes of the variable?

- I have an object with a variable containing a String.
- I have a window containing a LabelMorph/TextMorph (or some other Morph
that displays Text?).
How do i bind the LabelMorph/TextMorph to the variable, so that the label
updates when the String in the variable changes?

- classic Smalltalk-80 dependent/change/update mechanism?
- Pharo Announcement framework?
- something different??
How would i do this? Which Morph should i use?

Martin.



--
View this message in context: http://forum.world.st/How-can-my-Morph-reflect-changes-in-the-object-it-displays-tp4677629.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: How can my Morph reflect changes in the object it displays?

Sven Van Caekenberghe-2
Ben,

But then how does this work ?

| point |
point := 1@2.
point inspect.
[ 5 seconds asDelay wait.
  point setX: 10 setY: 20 ] fork.

You can see the inspector change its printString, without ValueHolders>>contents: being involved, just a direct instance variable assignment.

Sven

On 21 Mar 2013, at 11:41, Benjamin <[hidden email]> wrote:

> For this kind of situation, my solution is to use a valueHolder
>
> instead of storing your string directly in an inst var, store it into the value holder
>
> initialize
> string := '' asValueHolder
>
> string: aString
> string contents: aString
>
> string
> ^ string contents
>
> And then what you can do in your initialise is
>
> string whenChangedDo: [:newValue | self label contents: newValue ]
>
> Something like this should work ^^
>
>
> The other solution (which is baaad, but can still be seen) is to have a step method refreshing the Morph.
> But this is really not efficient
>
> Hope it helps,
> Ben
>
> On Mar 21, 2013, at 11:24 AM, MartinW <[hidden email]> wrote:
>
>> I asked the same question on Stackoverflow
>> (http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmorph-to-a-variable-so-that-the-morph-reflects-chan)
>> but as i do not know how much the audiences overlap i hope you do not mind
>> if i repeat it here:
>>
>> How to bind a LabelMorph/TextMorph to a variable so that the Morph reflects
>> changes of the variable?
>>
>> - I have an object with a variable containing a String.
>> - I have a window containing a LabelMorph/TextMorph (or some other Morph
>> that displays Text?).
>> How do i bind the LabelMorph/TextMorph to the variable, so that the label
>> updates when the String in the variable changes?
>>
>> - classic Smalltalk-80 dependent/change/update mechanism?
>> - Pharo Announcement framework?
>> - something different??
>> How would i do this? Which Morph should i use?
>>
>> Martin.
>>
>>
>>
>> --
>> View this message in context: http://forum.world.st/How-can-my-Morph-reflect-changes-in-the-object-it-displays-tp4677629.html
>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: How can my Morph reflect changes in the object it displays?

Benjamin Van Ryseghem (Pharo)
Yes, endless loop with step as far as I remember

stepAt: millisecondClockValue in: aWindow
| newText |

(CodeHolder smartUpdating and: [(millisecondClockValue - self timeOfLastListUpdate) > 8000]) "Not more often than once every 8 seconds"
ifTrue:
[self updateListsAndCodeIn: aWindow.
timeOfLastListUpdate := millisecondClockValue].

newText := self contentsIsString
ifTrue: [self selection]
ifFalse: ["keep it short to reduce time to compute it"
self selectionPrintString ].
newText = contents ifFalse:
[contents := newText.
self changed: #contents]

stepTimeIn: aSystemWindow
^ (selectionUpdateTime ifNil: [0]) * 10 max: 1000

Tadaaa :)
The old Browser was doing the same, and a lot of Morphs are doing this :s

Ben

On Mar 21, 2013, at 12:00 PM, Sven Van Caekenberghe <[hidden email]> wrote:

Ben,

But then how does this work ?

| point |
point := 1@2.
point inspect.
[ 5 seconds asDelay wait.
 point setX: 10 setY: 20 ] fork.

You can see the inspector change its printString, without ValueHolders>>contents: being involved, just a direct instance variable assignment.

Sven

On 21 Mar 2013, at 11:41, Benjamin <[hidden email]> wrote:

For this kind of situation, my solution is to use a valueHolder

instead of storing your string directly in an inst var, store it into the value holder

initialize
string := '' asValueHolder

string: aString
string contents: aString

string
^ string contents

And then what you can do in your initialise is

string whenChangedDo: [:newValue | self label contents: newValue ]

Something like this should work ^^


The other solution (which is baaad, but can still be seen) is to have a step method refreshing the Morph.
But this is really not efficient

Hope it helps,
Ben

On Mar 21, 2013, at 11:24 AM, MartinW <[hidden email]> wrote:

I asked the same question on Stackoverflow
(http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmorph-to-a-variable-so-that-the-morph-reflects-chan)
but as i do not know how much the audiences overlap i hope you do not mind
if i repeat it here:

How to bind a LabelMorph/TextMorph to a variable so that the Morph reflects
changes of the variable?

- I have an object with a variable containing a String.
- I have a window containing a LabelMorph/TextMorph (or some other Morph
that displays Text?).
How do i bind the LabelMorph/TextMorph to the variable, so that the label
updates when the String in the variable changes?

- classic Smalltalk-80 dependent/change/update mechanism?
- Pharo Announcement framework?
- something different??
How would i do this? Which Morph should i use?

Martin.



--
View this message in context: http://forum.world.st/How-can-my-Morph-reflect-changes-in-the-object-it-displays-tp4677629.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.





Reply | Threaded
Open this post in threaded view
|

Re: How can my Morph reflect changes in the object it displays?

Stephan Eggermont-3
In reply to this post by MartinW
Martin Walk asked:
>How to bind a LabelMorph/TextMorph to a variable so that the Morph reflects
>changes of the variable?

That is a very low-level question. Do you just want to know, or do you want to use it?
When building UI's in Pharo, the first question should probably be: can I get away
with building it in Glamour. That is a high-level UI toolkit specialized in creating
browsers. If you can, it is much less work.

Stephan Eggermont
Reply | Threaded
Open this post in threaded view
|

Re: How can my Morph reflect changes in the object it displays?

Sven Van Caekenberghe-2
In reply to this post by Benjamin Van Ryseghem (Pharo)

On 21 Mar 2013, at 12:08, Benjamin <[hidden email]> wrote:

> Yes, endless loop with step as far as I remember
>
> stepAt: millisecondClockValue in: aWindow
> | newText |
>
> (CodeHolder smartUpdating and: [(millisecondClockValue - self timeOfLastListUpdate) > 8000]) "Not more often than once every 8 seconds"
> ifTrue:
> [self updateListsAndCodeIn: aWindow.
> timeOfLastListUpdate := millisecondClockValue].
>
> newText := self contentsIsString
> ifTrue: [self selection]
> ifFalse: ["keep it short to reduce time to compute it"
> self selectionPrintString ].
> newText = contents ifFalse:
> [contents := newText.
> self changed: #contents]
>
> stepTimeIn: aSystemWindow
> ^ (selectionUpdateTime ifNil: [0]) * 10 max: 1000
>
> Tadaaa :)
> The old Browser was doing the same, and a lot of Morphs are doing this :s

Yeah ;-)

Now, from the user/developer standpoint it is of course nice to have an IDE that is as close as possible to a live objects environment. For browsers, announcement are a solution. For inspectors or debuggers showing arbitrary instance variables of objects, the question of how to implement that behaviour seems like an open question.  

> Ben
>
> On Mar 21, 2013, at 12:00 PM, Sven Van Caekenberghe <[hidden email]> wrote:
>
>> Ben,
>>
>> But then how does this work ?
>>
>> | point |
>> point := 1@2.
>> point inspect.
>> [ 5 seconds asDelay wait.
>>  point setX: 10 setY: 20 ] fork.
>>
>> You can see the inspector change its printString, without ValueHolders>>contents: being involved, just a direct instance variable assignment.
>>
>> Sven
>>
>> On 21 Mar 2013, at 11:41, Benjamin <[hidden email]> wrote:
>>
>>> For this kind of situation, my solution is to use a valueHolder
>>>
>>> instead of storing your string directly in an inst var, store it into the value holder
>>>
>>> initialize
>>> string := '' asValueHolder
>>>
>>> string: aString
>>> string contents: aString
>>>
>>> string
>>> ^ string contents
>>>
>>> And then what you can do in your initialise is
>>>
>>> string whenChangedDo: [:newValue | self label contents: newValue ]
>>>
>>> Something like this should work ^^
>>>
>>>
>>> The other solution (which is baaad, but can still be seen) is to have a step method refreshing the Morph.
>>> But this is really not efficient
>>>
>>> Hope it helps,
>>> Ben
>>>
>>> On Mar 21, 2013, at 11:24 AM, MartinW <[hidden email]> wrote:
>>>
>>>> I asked the same question on Stackoverflow
>>>> (http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmorph-to-a-variable-so-that-the-morph-reflects-chan)
>>>> but as i do not know how much the audiences overlap i hope you do not mind
>>>> if i repeat it here:
>>>>
>>>> How to bind a LabelMorph/TextMorph to a variable so that the Morph reflects
>>>> changes of the variable?
>>>>
>>>> - I have an object with a variable containing a String.
>>>> - I have a window containing a LabelMorph/TextMorph (or some other Morph
>>>> that displays Text?).
>>>> How do i bind the LabelMorph/TextMorph to the variable, so that the label
>>>> updates when the String in the variable changes?
>>>>
>>>> - classic Smalltalk-80 dependent/change/update mechanism?
>>>> - Pharo Announcement framework?
>>>> - something different??
>>>> How would i do this? Which Morph should i use?
>>>>
>>>> Martin.
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context: http://forum.world.st/How-can-my-Morph-reflect-changes-in-the-object-it-displays-tp4677629.html
>>>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>>>
>>>
>>
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: How can my Morph reflect changes in the object it displays?

Benjamin Van Ryseghem (Pharo)
Yes :S

The problem is mutable objects, what can you do then …
For Spec I introduced value holders :) But for the basic one, it work only if you set a new value, not if what is inside the value holder mutates.

I alo introduce value holders for some collections, but for the rest, I still do not know
(maybe JB's handle could cover that ^^)

Ben

On Mar 21, 2013, at 12:46 PM, Sven Van Caekenberghe <[hidden email]> wrote:


On 21 Mar 2013, at 12:08, Benjamin <[hidden email]> wrote:

Yes, endless loop with step as far as I remember

stepAt: millisecondClockValue in: aWindow
| newText |

(CodeHolder smartUpdating and: [(millisecondClockValue - self timeOfLastListUpdate) > 8000]) "Not more often than once every 8 seconds"
ifTrue:
[self updateListsAndCodeIn: aWindow.
timeOfLastListUpdate := millisecondClockValue].

newText := self contentsIsString
ifTrue: [self selection]
ifFalse: ["keep it short to reduce time to compute it"
self selectionPrintString ].
newText = contents ifFalse:
[contents := newText.
self changed: #contents]

stepTimeIn: aSystemWindow
^ (selectionUpdateTime ifNil: [0]) * 10 max: 1000

Tadaaa :)
The old Browser was doing the same, and a lot of Morphs are doing this :s

Yeah ;-)

Now, from the user/developer standpoint it is of course nice to have an IDE that is as close as possible to a live objects environment. For browsers, announcement are a solution. For inspectors or debuggers showing arbitrary instance variables of objects, the question of how to implement that behaviour seems like an open question.  

Ben

On Mar 21, 2013, at 12:00 PM, Sven Van Caekenberghe <[hidden email]> wrote:

Ben,

But then how does this work ?

| point |
point := 1@2.
point inspect.
[ 5 seconds asDelay wait.
point setX: 10 setY: 20 ] fork.

You can see the inspector change its printString, without ValueHolders>>contents: being involved, just a direct instance variable assignment.

Sven

On 21 Mar 2013, at 11:41, Benjamin <[hidden email]> wrote:

For this kind of situation, my solution is to use a valueHolder

instead of storing your string directly in an inst var, store it into the value holder

initialize
string := '' asValueHolder

string: aString
string contents: aString

string
^ string contents

And then what you can do in your initialise is

string whenChangedDo: [:newValue | self label contents: newValue ]

Something like this should work ^^


The other solution (which is baaad, but can still be seen) is to have a step method refreshing the Morph.
But this is really not efficient

Hope it helps,
Ben

On Mar 21, 2013, at 11:24 AM, MartinW <[hidden email]> wrote:

I asked the same question on Stackoverflow
(http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmorph-to-a-variable-so-that-the-morph-reflects-chan)
but as i do not know how much the audiences overlap i hope you do not mind
if i repeat it here:

How to bind a LabelMorph/TextMorph to a variable so that the Morph reflects
changes of the variable?

- I have an object with a variable containing a String.
- I have a window containing a LabelMorph/TextMorph (or some other Morph
that displays Text?).
How do i bind the LabelMorph/TextMorph to the variable, so that the label
updates when the String in the variable changes?

- classic Smalltalk-80 dependent/change/update mechanism?
- Pharo Announcement framework?
- something different??
How would i do this? Which Morph should i use?

Martin.



--
View this message in context: http://forum.world.st/How-can-my-Morph-reflect-changes-in-the-object-it-displays-tp4677629.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.








Reply | Threaded
Open this post in threaded view
|

Re: How can my Morph reflect changes in the object it displays?

MartinW
In reply to this post by Stephan Eggermont-3
Stephan Eggermont wrote
>How to bind a LabelMorph/TextMorph to a variable so that the Morph reflects
>changes of the variable?

That is a very low-level question. Do you just want to know, or do you want to use it?
When building UI's in Pharo, the first question should probably be: can I get away
with building it in Glamour. That is a high-level UI toolkit specialized in creating
browsers. If you can, it is much less work.
I am interested in both questions. I want to just use it - but of course i am interested in knowing different possibilities and how they work and why to prefer one to the other.

I have not looked at Glamour yet - and i am a bit reluctant to add an extra layer, but i will give it a try.

But btw - isn't it a very common problem to keep for example different views on the same object in sync? For example i want to provide a slider and a textfield for a numerical value. (I probably hoped something like Cocoa Bindings would exist.)
Reply | Threaded
Open this post in threaded view
|

Re: How can my Morph reflect changes in the object it displays?

MartinW
In reply to this post by Benjamin Van Ryseghem (Pharo)
Benjamin Van Ryseghem-2 wrote
The problem is mutable objects, what can you do then …
For Spec I introduced value holders :)
I was already wondering what ValueHolders were abould :)
I am looking forward to the Spec Tutorial Video from the Pharo Conference.

Can i already do this with Spec:
Display a Slider and a Textfield for a numerical value and when i change the value via the slider the Textfiled will update and vice versa?
Reply | Threaded
Open this post in threaded view
|

Re: How can my Morph reflect changes in the object it displays?

Benjamin Van Ryseghem (Pharo)
Yes you can :)
(thanks to value holders ^^)

Ben

On Mar 21, 2013, at 1:58 PM, MartinW <[hidden email]> wrote:

Benjamin Van Ryseghem-2 wrote
The problem is mutable objects, what can you do then …
For Spec I introduced value holders :)

I was already wondering what ValueHolders were abould :)
I am looking forward to the Spec Tutorial Video from the Pharo Conference.

Can i already do this with Spec:
Display a Slider and a Textfield for a numerical value and when i change the
value via the slider the Textfiled will update and vice versa?




--
View this message in context: http://forum.world.st/How-can-my-Morph-reflect-changes-in-the-object-it-displays-tp4677629p4677647.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: How can my Morph reflect changes in the object it displays?

philippeback
Currently doing some stuff with step and stepTime.

Are these things supported in some way in Spec?
This is an open question :-)

Phil

2013/3/21 Benjamin <[hidden email]>:

> Yes you can :)
> (thanks to value holders ^^)
>
> Ben
>
> On Mar 21, 2013, at 1:58 PM, MartinW <[hidden email]> wrote:
>
> Benjamin Van Ryseghem-2 wrote
>
> The problem is mutable objects, what can you do then …
> For Spec I introduced value holders :)
>
>
> I was already wondering what ValueHolders were abould :)
> I am looking forward to the Spec Tutorial Video from the Pharo Conference.
>
> Can i already do this with Spec:
> Display a Slider and a Textfield for a numerical value and when i change the
> value via the slider the Textfiled will update and vice versa?
>
>
>
>
> --
> View this message in context:
> http://forum.world.st/How-can-my-Morph-reflect-changes-in-the-object-it-displays-tp4677629p4677647.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>