How can my Morph reflect changes in the object it displays?
I asked the same question on Stackoverflow (http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmor...) 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-disp... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
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 <wm@fastmail.fm> wrote:
I asked the same question on Stackoverflow (http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmor...) 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-disp... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
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 <benjamin.vanryseghem.pharo@gmail.com> 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 <wm@fastmail.fm> wrote:
I asked the same question on Stackoverflow (http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmor...) 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-disp... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
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 <sven@stfx.eu> 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 <benjamin.vanryseghem.pharo@gmail.com> 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 <wm@fastmail.fm> wrote:
I asked the same question on Stackoverflow (http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmor...) 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-disp... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
On 21 Mar 2013, at 12:08, Benjamin <benjamin.vanryseghem.pharo@gmail.com> 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 <sven@stfx.eu> 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 <benjamin.vanryseghem.pharo@gmail.com> 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 <wm@fastmail.fm> wrote:
I asked the same question on Stackoverflow (http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmor...) 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-disp... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
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 <sven@stfx.eu> wrote:
On 21 Mar 2013, at 12:08, Benjamin <benjamin.vanryseghem.pharo@gmail.com> 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 <sven@stfx.eu> 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 <benjamin.vanryseghem.pharo@gmail.com> 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 <wm@fastmail.fm> wrote:
I asked the same question on Stackoverflow (http://stackoverflow.com/questions/15534305/how-to-bind-a-labelmorph-textmor...) 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-disp... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
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-disp... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Yes you can :) (thanks to value holders ^^) Ben On Mar 21, 2013, at 1:58 PM, MartinW <wm@fastmail.fm> 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-disp... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
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 <benjamin.vanryseghem.pharo@gmail.com>:
Yes you can :) (thanks to value holders ^^)
Ben
On Mar 21, 2013, at 1:58 PM, MartinW <wm@fastmail.fm> 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-disp... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
participants (4)
-
Benjamin -
MartinW -
phil@highoctane.be -
Sven Van Caekenberghe