### pharo-users@lists.pharo.org

Any question about pharo is welcome

### Spec2 - Morph query & move window to another position

HS
Haroldo Stenger
Sun, Jun 16, 2024 10:08 PM

hi all there , I'm playing around with this example from the nice Spec book,
which I try to get right for spec2. That's all right. I modify the example
for having two counters, one bound to the class of the Surveys and then one
for each survey. That was a good learning experience. Then I added a button
to spawn further a Survey which participates of the class-bound count of
votes. That's all right too. Then I started to write a method that given a
Rectangle, and a number n, gives an array of n Points that are in the
enclosed circle of the rectangle, more or less. Waht I want to achieve es
that for each added Survey, its Spec2 - Morph window gets positioned in one
of these points, but before rendering it, re position all the already
existing Spec2 - Morphs Survey windows in the rest of the points of the
array (being n the total number of Surveys after adding one). I'm facing
two challenges: (a) getting the list of current positions of Spec2 - Morph
Surveys already existing. (b) moving a Spec2 - Morph window to another
position. I'm pretty stuck trying to make my way for this two goals, so any
kind help will be really welcome. Yo can import the files into a Pharo12
image with the File manager, then Changelist Browser and selecting all the
lines and "file in".

thanks in advance !
Haroldo

hi all there , I'm playing around with this example from the nice Spec book, which I try to get right for spec2. That's all right. I modify the example for having two counters, one bound to the class of the Surveys and then one for each survey. That was a good learning experience. Then I added a button to spawn further a Survey which participates of the class-bound count of votes. That's all right too. Then I started to write a method that given a Rectangle, and a number n, gives an array of n Points that are in the enclosed circle of the rectangle, more or less. Waht I want to achieve es that for each added Survey, its Spec2 - Morph window gets positioned in one of these points, but before rendering it, re position all the already existing Spec2 - Morphs Survey windows in the rest of the points of the array (being n the total number of Surveys after adding one). I'm facing two challenges: (a) getting the list of current positions of Spec2 - Morph Surveys already existing. (b) moving a Spec2 - Morph window to another position. I'm pretty stuck trying to make my way for this two goals, so any kind help will be really welcome. Yo can import the files into a Pharo12 image with the File manager, then Changelist Browser and selecting all the lines and "file in". thanks in advance ! Haroldo
HS
Haroldo Stenger
Mon, Jun 17, 2024 12:04 AM

thanks to Hernán Morales Durand , he pointed that
*CustomerSatisfactionPresenter being a subclass of *SpPresenter , answers
the message
SpPresenter window
which renders a
SpWindowPresenter object
and
SpWindowPresenter window
renders a SpWindow object, which answers the message
SpWindow bounds
and
SpWindowPresenter moveTo: x@y
moves the window to the point.
any other suggestions are welcome too
best regards
Haroldo

El dom, 16 jun 2024 a la(s) 7:08 p.m., Haroldo Stenger (
haroldo.stenger@gmail.com) escribió:

hi all there , I'm playing around with this example from the nice Spec
book, which I try to get right for spec2. That's all right. I modify the
example for having two counters, one bound to the class of the Surveys
and then one for each survey. That was a good learning experience. Then I
added a button to spawn further a Survey which participates of the class-bound
count of votes. That's all right too. Then I started to write a method
that given a Rectangle, and a number n, gives an array of n Points that
are in the enclosed circle of the rectangle, more or less. Waht I want to
achieve es that for each added Survey, its Spec2 - Morph window gets
positioned in one of these points, but before rendering it, re position
all the already existing Spec2 - Morphs Survey windows in the rest of the
points of the array (being n the total number of Surveys after adding one).
I'm facing two challenges: (a) getting the list of current positions of
Spec2 - Morph Surveys already existing. (b) moving a Spec2 - Morph window
to another position. I'm pretty stuck trying to make my way for this two
goals, so any kind help will be really welcome. Yo can import the files
into a Pharo12 image with the File manager, then Changelist Browser and
selecting all the lines and "file in".

thanks in advance !
Haroldo

thanks to Hernán Morales Durand , he pointed that *CustomerSatisfactionPresenter being a subclass of **SpPresenter* , answers the message *SpPresenter* window which renders a *SpWindowPresenter* object and *SpWindowPresenter* window renders a *SpWindow* object, which answers the message *SpWindow* bounds and *SpWindowPresenter* moveTo: x@y moves the window to the point. any other suggestions are welcome too best regards Haroldo El dom, 16 jun 2024 a la(s) 7:08 p.m., Haroldo Stenger ( haroldo.stenger@gmail.com) escribió: > hi all there , I'm playing around with this example from the nice Spec > book, which I try to get right for spec2. That's all right. I modify the > example for having two counters, one bound to the class of the Surveys > and then one for each survey. That was a good learning experience. Then I > added a button to spawn further a Survey which participates of the class-bound > count of votes. That's all right too. Then I started to write a method > that given a Rectangle, and a number n, gives an array of n Points that > are in the enclosed circle of the rectangle, more or less. Waht I want to > achieve es that for each added Survey, its Spec2 - Morph window gets > positioned in one of these points, but before rendering it, re position > all the already existing Spec2 - Morphs Survey windows in the rest of the > points of the array (being n the total number of Surveys after adding one). > I'm facing two challenges: (a) getting the list of current positions of > Spec2 - Morph Surveys already existing. (b) moving a Spec2 - Morph window > to another position. I'm pretty stuck trying to make my way for this two > goals, so any kind help will be really welcome. Yo can import the files > into a Pharo12 image with the File manager, then Changelist Browser and > selecting all the lines and "file in". > > thanks in advance ! > Haroldo > >
EL
Esteban Lorenzano
Mon, Jun 17, 2024 5:39 AM

I do not understand.

you need to position points/morphs in a canvas ?

In that case you need a) a canvas and b) the points.

This cannot (and should not) be achieved with different widgets (spec)
but with just one : a morph there acts as a canvas.

So, instead of going to the window of the presenter (which,, by the way,
may or may not exist) I would just add a morph, e.g. :

(this example is just a script, in real life you would do things
differently)

presenter := SpPresenter new.
presenter layout: (SpBoxLayout newVertical
add: (morphPresenter := presenter newMorph);
yourself).

morph := Morph new color: Color white.
morphPresenter morph: morph.
morph color: Color white.
1 to: 10 do: [ :index |
| pointMorph |
pointMorph := Morph new
color: Color random;
extent: 10@10;
yourself.
pointMorph position: 300 atRandom @ 200 atRandom.
morph addMorph: pointMorph ].

presenter open.

this will give you something like this:

getting the real size of a window is not really provided by the api
except for its initial status (after that, you can suscribe to the
resize event if you want to know the new size), but you shouldn't needed
that  (and getting the SpWindow which is a morph is not the way to go,
since this is not portable).

Spec is a framework to make and place widgets, as soon as you need
something that is not a widget, you need to go to a lower level than it
(hence, rendering a morph).

Esteban

On 17/06/2024 00:08, Haroldo Stenger wrote:

hi all there , I'm playing around with this example from the nice Spec
book, which I try to get right for spec2. That's all right. I modify
the example for having two counters, one bound to the class of the
Surveys and then one for each survey. That was a good learning
experience. Then I added a button to spawn further a Survey which
participates of the class-bound count of votes. That's all right too.
Then I started to write a method that given a Rectangle, and a number
n, gives an array of n Points that are in the enclosed circle of the
rectangle, more or less. Waht I want to achieve es that for each added
Survey, its Spec2 - Morph window gets positioned in one of these
points, but before rendering it, re position all the already existing
Spec2 - Morphs Survey windows in the rest of the points of the array
(being n the total number of Surveys after adding one). I'm facing two
challenges: (a) getting the list of current positions of Spec2 - Morph
Surveys already existing. (b) moving a Spec2 - Morph window to another
position. I'm pretty stuck trying to make my way for this two goals,
so any kind help will be really welcome. Yo can import the files into
a Pharo12 image with the File manager, then Changelist Browser and
selecting all the lines and "file in".

thanks in advance !
Haroldo

HS
Haroldo Stenger
Tue, Jun 18, 2024 9:35 PM

hi Esteban
I'm very sorry for the delay, and very grateful for your help.

El lun, 17 jun 2024 a la(s) 2:39 a.m., Esteban Lorenzano via Pharo-users (
pharo-users@lists.pharo.org) escribió:

you need to position points/morphs in a canvas ?

in the WorldMorph.

In that case you need a) a canvas and b) the points.

The World Morph I see it as the canvas, the points are the windows
(SpPresenter's) coordinates understood by moveTo:

This cannot (and should not) be achieved with different widgets (spec) but
with just one : a morph there acts as a canvas.

Yes, I try to understand.

So, instead of going to the window of the presenter (which,, by the way,
may or may not exist) I would just add a morph, e.g. :

(this example is just a script, in real life you would do things
differently)

presenter := SpPresenter new.
presenter layout: (SpBoxLayout newVertical
add: (morphPresenter := presenter newMorph);
yourself).

morph := Morph new color: Color white.
morphPresenter morph: morph.
morph color: Color white.
1 to: 10 do: [ :index |
| pointMorph |
pointMorph := Morph new
color: Color random;
extent: 10@10;
yourself.
pointMorph position: 300 atRandom @ 200 atRandom.
morph addMorph: pointMorph ].

presenter open.

got thru the example which is very nice.

getting the real size of a window is not really provided by the api except
for its initial status (after that, you can suscribe to the resize event if
you want to know the new size), but you shouldn't needed that  (and getting
the SpWindow which is a morph is not the way to go, since this is not
portable).

Now I understand what subscriptions are !

Spec is a framework to make and place widgets, as soon as you need
something that is not a widget, you need to go to a lower level than it
(hence, rendering a morph).

Correct. Nontheles, the SpPresenter subclassed objects answer the moveTo:
x@y  and move the window.  Is the window itself considered a widget in this
context? Just asking to learn and orient myself.

I could more or less do what I originally wanted. A methiod of mine goes
thru all opened Survey windows, and reposition themselves in a circle. I
like the result , at least as a "variant" of the default positioning, and
as an excercise of querying and moving.

thanks again and best regards
looking forward meeting you soon in Buenos Aires or wherever.

Haroldo

hi Esteban I'm very sorry for the delay, and very grateful for your help. El lun, 17 jun 2024 a la(s) 2:39 a.m., Esteban Lorenzano via Pharo-users ( pharo-users@lists.pharo.org) escribió: > you need to position points/morphs in a canvas ? > in the WorldMorph. > In that case you need a) a canvas and b) the points. > The World Morph I see it as the canvas, the points are the windows (SpPresenter's) coordinates understood by moveTo: > This cannot (and should not) be achieved with different widgets (spec) but > with just one : a morph there acts as a canvas. > Yes, I try to understand. > So, instead of going to the window of the presenter (which,, by the way, > may or may not exist) I would just add a morph, e.g. : > > (this example is just a script, in real life you would do things > differently) > > presenter := SpPresenter new. > presenter layout: (SpBoxLayout newVertical > add: (morphPresenter := presenter newMorph); > yourself). > > morph := Morph new color: Color white. > morphPresenter morph: morph. > morph color: Color white. > 1 to: 10 do: [ :index | > | pointMorph | > pointMorph := Morph new > color: Color random; > extent: 10@10; > yourself. > pointMorph position: 300 atRandom @ 200 atRandom. > morph addMorph: pointMorph ]. > > presenter open. > got thru the example which is very nice. > getting the real size of a window is not really provided by the api except > for its initial status (after that, you can suscribe to the resize event if > you want to know the new size), but you shouldn't needed that (and getting > the SpWindow which is a morph is not the way to go, since this is not > portable). > Now I understand what subscriptions are ! > Spec is a framework to make and place **widgets**, as soon as you need > something that is not a widget, you need to go to a lower level than it > (hence, rendering a morph). > Correct. Nontheles, the SpPresenter subclassed objects answer the moveTo: x@y and move the window. Is the window itself considered a widget in this context? Just asking to learn and orient myself. I could more or less do what I originally wanted. A methiod of mine goes thru all opened Survey windows, and reposition themselves in a circle. I like the result , at least as a "variant" of the default positioning, and as an excercise of querying and moving. thanks again and best regards looking forward meeting you soon in Buenos Aires or wherever. Haroldo