One of the nice things about the Swallow (Twitter client) project that Michael and I have been working on is the fact that we decided to make it a Widgetry (Pollock) project. I hadn't really worked in Widgetry before, so it's been a learning experience - especially the lack of a GUI builder :)
Still, it's gone pretty well. Here's one of the things that nicer in Widgetry than it was in Wrapper: keyboard handling. Say you have an input field, and you want to look for a specific character. In Wrapper, you had to install a keyboardHook block on the controller, and then write all the handling code in the block (or in methods called from the block. In Widgetry, we register to get an Announcement:
(self paneAt: #input) inputField
when: KeystrokeAboutToBeProcessed
send: #possibleCREvent:
to: self.
The pane in question is a combo-box, so I first grabbed the input field and then waited for the Announcement (which is an actual object). Here's the handler:
possibleCREvent: announcement
"if the key pressed is a CR, then send the message"
| key |
key := announcement keystroke key.
key = Character cr ifTrue: [self sendStatusNow].
Which seems more straightforward to me than the old keyboard handler setup - for one thing, I don't need to remember whether to return the keyboard event or nil :). Anyhow, it's a nice little project, and a nice experiment.
Technorati Tags:
smalltalk, Widgetry