Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
MVC: one window one button
Last updated at 3:15 pm UTC on 14 January 2006
Mail List Question:
How do you create a simple MVC application window containing a button? I could not find a Window class in Squeak and the View class's information is quite cryptic to the uninitiated.

The simplest one window and one button that I know:

 | topView aButton |
 topView := StandardSystemView new
	 label: 'Launch Pad'.
 aButton := Button newOff onAction: [Smalltalk beep]. 
            "dummy launching action"

 topView addSubView: (PluggableButtonView new
	 label: 'Beep' asParagraph;
	 insideColor: Color gray;
	 model: aButton; borderWidth: 1) 
         viewport: (0@0 corner: 1@1).
 topView controller open.
- Mark Guzdial

When using PluggableButtonView in the way described above the instance created might miss its actionSelector.
The source code could be changed to:

[...]
topView 
  addSubView: ((PluggableButtonView on: aButton)
                  label: 'Beep' asParagraph;
                  insideColor: Color gray;
                  borderWidth: 1) 
  viewport: (0@0 corner: 1@1).
[...]

Thus the PluggabbleButtonView will be set to #switch by the instance creation method #on: and the button's onAction-Block will be evaluated whenever the button is pressed – Harald Liedtke

I tried the above snippet and I got a walkback window on the use of Button. Any suggestions? – MVC: one window one button

In a stock 3.0 image, both snippits work fine- but with a weird side effect. The window is around 500@400 when it opens, but the buttons occupies around a 4@4 space around the center of the window.– Aaron Reichow

To fix the button size in 3.2 image, the source code could be changed to:
topView
  addSubView:
    ((PluggableButtonView on: aButton)
      label: 'Beep' asParagraph;
      insideColor: Color gray;
      borderWidth: 1)
  window: (0.0@0.0 corner: 1.0@1.0)
  viewport: (0.0@0.0 corner: 1.0@1.0).