UI with Spec, how to get mouse events ?

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

UI with Spec, how to get mouse events ?

Daniel BLANC
Hi all,

I'm building a Spec UI with an ImageModel and a LabelModel. The image is a map, and the label should display the mouse coordinates when the mouse cursor is on the map. 

I'm a newcomer to Pharo and Smalltalk, I've searched in the pharo image, and looked into events, on:send:to: message, but I don't know how to properly use them with Spec.

For testing purpose I've tried just to get a mouse click with this:

MyStuff >> initializeWidgets
map := self newImage.
mousePos := self newLabel.
map on: #click send: #mouseClicked to: self

But that doesn't work. Any idea how I can do this ?

Thanks,
Daniel
Reply | Threaded
Open this post in threaded view
|

Re: UI with Spec, how to get mouse events ?

Nicolai Hess-3-2


2017-03-21 20:21 GMT+01:00 Daniel BLANC <[hidden email]>:
Hi all,

I'm building a Spec UI with an ImageModel and a LabelModel. The image is a map, and the label should display the mouse coordinates when the mouse cursor is on the map. 

I'm a newcomer to Pharo and Smalltalk, I've searched in the pharo image, and looked into events, on:send:to: message, but I don't know how to properly use them with Spec.

For testing purpose I've tried just to get a mouse click with this:

MyStuff >> initializeWidgets
map := self newImage.
mousePos := self newLabel.
map on: #click send: #mouseClicked to: self

But that doesn't work. Any idea how I can do this ?

Thanks,
Daniel

Hi Daniel,

I am afraid, mouse move events aren't catched by the image, and therfore you can not use the image model to listen for the mouse position changes.
The above code for mouse click events does not work, because the click event is only send to the widget (a ImageMorph) but not to the model.

But the model registers itself for the click event when the widget is build. If a click even is send on the image morph, the model calls #value on its action property, just set
an apropiate block as action for your ImageModel

an example:

im := ImageModel new.
im image: PolymorphSystemSettings pharoLogoForm.
im action:[ActiveHand inspect].
im openWithSpec.

clicking on the image will open an inspector with the active hand.



 

Reply | Threaded
Open this post in threaded view
|

Re: UI with Spec, how to get mouse events ?

Daniel BLANC
Hi Nicolai,

Thanks for the explanation. It gave me the idea to search for the senders of #action, and I found the MorphicImageAdapter. It looks like I won't be able to get the mouse position from within the action block of the image model. I'll try to achieve this another way, may be with Morphic.

Daniel

On Tue, Mar 21, 2017 at 11:19 PM Nicolai Hess <[hidden email]> wrote:
2017-03-21 20:21 GMT+01:00 Daniel BLANC <[hidden email]>:
Hi all,

I'm building a Spec UI with an ImageModel and a LabelModel. The image is a map, and the label should display the mouse coordinates when the mouse cursor is on the map. 

I'm a newcomer to Pharo and Smalltalk, I've searched in the pharo image, and looked into events, on:send:to: message, but I don't know how to properly use them with Spec.

For testing purpose I've tried just to get a mouse click with this:

MyStuff >> initializeWidgets
map := self newImage.
mousePos := self newLabel.
map on: #click send: #mouseClicked to: self

But that doesn't work. Any idea how I can do this ?

Thanks,
Daniel

Hi Daniel,

I am afraid, mouse move events aren't catched by the image, and therfore you can not use the image model to listen for the mouse position changes.
The above code for mouse click events does not work, because the click event is only send to the widget (a ImageMorph) but not to the model.

But the model registers itself for the click event when the widget is build. If a click even is send on the image morph, the model calls #value on its action property, just set
an apropiate block as action for your ImageModel

an example:

im := ImageModel new.
im image: PolymorphSystemSettings pharoLogoForm.
im action:[ActiveHand inspect].
im openWithSpec.

clicking on the image will open an inspector with the active hand.