I am trying to make a simple user interface in Pharo 3.0. At a certain place I need a color picker, so I thought about using ColorSelectorDialogWindow
.
My problem is that I am not sure how to actually get a color out of it. I have seen that it has a selectedColor
message, but I miss a way to actually catch the event when the user clicks on the ok button.
I have tried on: send: to:
but it does not seem to help and in any case I don't know the event name. I have also seen that on confirmation, the message applyChanges
gets sent to self, so I tried subclassing ColorSelectorDialogWindow
just to add
applyChanges
super applyChanges.
self triggerEvent: 'selectedColor' with: self selectedColor.
but it seems that I cannot catch my own selectedColor
event using on: send: to:
.
What is the right way to hook into the dialog ok, and more generally to send events between components?
There are Announcements, a currently not very well documented part of Pharo. Try this in a workspace:
| colorPicker |
colorPicker := ColorSelectorDialogWindow new.
colorPicker announcer when: ColorChanged do: [ :announcement | UIManager inform: 'Selected color: ' , announcement newColor asString ].
colorPicker open.
This is the example that can be found in the ColorChanged
announcement class comment.
You get the selected color by sending newColor
to the ColorChanged
announcement.