The following was posted in reply to a question on comp.lang.smalltalk; I thought I'd send it to the Squeak mailing list for those new folks who don't browse that newsgroup.
"Andre M. (Mike) Maloney" wrote:
Hi all,
I'm just starting to learn smalltalk and am using Squak (2.4c).
Welcome to Smalltalk and Squeak! You'll find a lot of things here to explore and have fun with.
I'm trying to build a simple counter and need some help. The counter will have three buttons and a display. The displayed value will start at one and the buttons will increment the displayed value by one, decrement the displayed value by one, and reset the displayed value to zero. I've found the ValueHolder, button, and PluggableButtonController classes, but how do I put the buttons and ValueHolder into a parent frame (window?, view?)?
Squeak has two different interface models: the older MVC (Model, View, Control), and the newer Morphic. The classes you found are part of MVC. You can use these to build an MVC interface, but it is a little more complicated than Morphic.
If you want to try your example using Morphic, do the following:
1) make sure you are in the Morphic interface. If your menus are white with a blue frame around them, you are. Otherwise, select "open..." then "project (morphic)" from the main display menu, then enter the project by clicking on it.
2) Open up a Browser and have a look at the SameGame class; we're going to borrow heavily from it, here.
3) Open up a Workspace and type in the following:
---- cut here ---- "this is going to be the box containing our panel" frame := AlignmentMorph new orientation: #vertical.
"create a 4-digit LED display to contain the count" display := LedMorph new digits: 4; extent: (4*10@15).
"we want our buttons arranged in a horizontal row" controls := AlignmentMorph new orientation: #horizontal.
"add a quit button" controls addMorph: (SimpleButtonMorph new target: frame; label: 'quit'; actionSelector: #delete).
"add an increment button" controls addMorph: (SimpleButtonMorph new target: display; label: 'inc'; actionSelector: #increment).
"add a decrement button" controls addMorph: (SimpleButtonMorph new target: display; label: 'dec'; actionSelector: #decrement).
"add a clear button" controls addMorph: (SimpleButtonMorph new target: display; label: 'clear'; actionSelector: #clear).
"add the controls and display to our panel" frame addMorph: controls. frame addMorph: display.
"start playing with it!" frame openInWorld
--- cut here ---
We're not quite ready to run it yet. We don't have anything to handle the increment/decrement logic. To make this easy, we'll just add it to the existing LedMorph class, which we are using for the display.
In the browser, find the LedMorph class, go to the "accessing" category, and find the "value:" method. We'll just tweak this a few times to add the new methods "increment", "decrement", and "clear".
First, select the bold method header (value: aNumber) and change it to increment. Then replace the line "value := aNumber." with "value := value + 1.". Then accept your change (hit command-s or select "accept" from the menu in the lower pane. Now do the same thing for "decrement" and "clear" (doing the right thing with value).
Now we're ready to give it a try. Select everything you typed in the Workspace and doIt (command-d or select doit from the menu). You should now have a light green panel with buttons and an LED display.
-- Tim Olson
On Thu, 12 Aug 1999 09:30:23 -0400, you wrote:
[snip]
Squeak has two different interface models: the older MVC (Model, View, Control), and the newer Morphic. The classes you found are part of MVC. You can use these to build an MVC interface, but it is a little more complicated than Morphic.
If you want to try your example using Morphic, do the following:
[much snippage]
Thanks for the reply, Tim. I'll be playing with your code when I get home from work.
This brings up a question about learning Smalltalk via Squeak. Should I start with MVC, (since that is documented in the classic texts) or just dive into the Morphic world?
Also, are there other major divergences from the older texts?
Thanks again, Mike -- "Skate hard. Play by the rules. Make every day a great for hockey" - Badger Bob
In my 2.5 image, as freshly opened, when looking at Object -> at: , instead of seeing
at: index "Primitive, etc.
as appears in my 2.4 image, I instead see
ive
....as if the
at: index "Primit
part got chopped off. Object -> at: put: is similar.
e
is the only thing that shows up at the beginning (as if everything up to the e in Primitive got chopped off). I'm about 3 days into Squeak and very new to SM, etc. Am I missing something obvious?
-mp
It looks like you have the classic unwanted file conversion on download or decompression problem. Turn off all file conversion "features" in Stuffit Expander (even if you are on a Mac) before unpacking the .sit file. If you downloaded the individual files, make sure you did it in *binary* mode (preferably with an FTP client). Most browsers will give you problems with these files if they are not compressed.
The .changes or .sources files (which are just large text files using CR end-of-line formatting) are probably getting their end of line formatting messed with (and who knows what else) -- since the .image file maintains offsets into these files to retrieve the source when browsing, anything that messes with their formatting will throw the browsing off.
-- Dwight
Mark Polishook wrote:
In my 2.5 image, as freshly opened, when looking at Object -> at: , instead of seeing
at: index "Primitive, etc.
as appears in my 2.4 image, I instead see
ive
...as if the
at: index "Primit
part got chopped off. Object -> at: put: is similar.
e
is the only thing that shows up at the beginning (as if everything up to the e in Primitive got chopped off). I'm about 3 days into Squeak and very new to SM, etc. Am I missing something obvious?
-mp
Thanks for the responses to my question. I downloaded a fresh source and 2.5 with an ftp client in bin mode and everything now loads just fine.
mp
At 1:49 PM -0700 8/12/99, Mark Polishook wrote:
Thanks for the responses to my question. I downloaded a fresh source and 2.5 with an ftp client in bin mode and everything now loads just fine.
For Mac downloading, I have become pretty fond of Monica because it uses X-modem-style protocol and can resume where it left of if an ftp session is interrupted.
It also downloads binaries very nicely.
This is really handy for large downloads (over 1 MB).
Jeff
--************************************************** Jeff Szuhay mailto:jeffs@pstnet.com Lead Macintosh Engineer voice: 412/271-5040 x227 Psychology Software Tools http://www.pstnet.com/
This brings up a question about learning Smalltalk via Squeak. Should I start with MVC, (since that is documented in the classic texts) or just dive into the Morphic world?
Heck, learn 'em both! I'd actually start with learning and playing with non-interface code, first, to get the real flavor of Smalltalk coding, then pick up Morphic and/or MVC.
Also, are there other major divergences from the older texts?
In the non-interface areas Squeak seems to be pretty much the same as documented in the older texts. MVC is probably slightly different, and Morphic is new.
MVC has some interesting ideas re: separating the view, controller, and model for improved pluggability & reuse, but I personally think Morphic is much easier to learn.
-- tim
[Great Morphic example snipped]
Thanx Tim! This example really got me hooked into Morphic. Now, I would like to know:
* If it is possible to construct the counter (one LedMorph, two SimpleButtomMorphs) without writing a single line of code, assuming that LedMorph already has "increment" and "decrement" menthods? I thought it was possible to do such a thing by creating the Led and buttoms from the "World>>new morph..." menu, and then sort of embed them to some AlignmentMorphs. But I couldn't figure a way out to do it.
* Since I can store a morph to a file, how can I load a morph from file and give it a name?
Thanx!
Hsin-Hao Yu (Squeak newbie)
Being someone that is a purest at heart when it comes to separating business logic, i.e. the model, from its interface, i.e. a view and controller, here is an alternative to Tim's example. It's a little more work, but it keeps the LedMorph more of an "interface" object by making it pluggable. The counter object is a model object, and the counting application is a cooridnator object in that it creates the counter and pluggable led morph objects and connects them up.
It's not the best code in the world, but it gets the point across.
Mark
[Great Morphic example snipped]
Thanx Tim! This example really got me hooked into Morphic. Now, I would like to know:
If it is possible to construct the counter (one LedMorph, two SimpleButtomMorphs) without writing a single line of code, assuming that LedMorph already has "increment" and "decrement" menthods? I thought it was possible to do such a thing by creating the Led and buttoms from the "World>>new morph..." menu, and then sort of embed them to some AlignmentMorphs. But I couldn't figure a way out to do it.
Since I can store a morph to a file, how can I load a morph from file and give it a name?
Thanx!
Hsin-Hao Yu (Squeak newbie)
Attachment converted: Anon:Counting.st (TEXT/R*ch) (0001239C)
Dear Mark,
Being someone that is a purest at heart when it comes to separating business logic, i.e. the model, from its interface, i.e. a view and controller, here is an alternative to Tim's example. It's a little more work, but it keeps the LedMorph more of an "interface" object by making it pluggable.
What does "pluggable" mean? And what does "dependent" mean? In your CounterApplication, you create a "Pluggable" led display, then you put the model in a variable of the display (counter) and then you make the display a dependent of the the model.
What is it? How can an object be a "dependent" of one of its sub-objects?
Thanks Adriano
The counter object is a model object, and the counting application is a cooridnator object in that it creates the counter and pluggable led morph objects and connects them up.
It's not the best code in the world, but it gets the point across.
Spencer Yu wrote:
- If it is possible to construct the counter (one LedMorph, two SimpleButtomMorphs) without writing a single line of code, assuming that LedMorph already has "increment" and "decrement" menthods? I thought it was possible to do such a thing by creating the Led and buttoms from the "World>>new morph..." menu, and then sort of embed them to some AlignmentMorphs. But I couldn't figure a way out to do it.
1) Get an alignment morph, from "new morph..."
2) Grow the alignment morph by right-clicking (or command-clicking on Mac) to get the halo, then resize with the yellow handle.
3) get an LedMorph and some SimpleButtonMorphs on the desktop.
4) right-click on a button (or cmd-click on Mac) to bring up the halos, and click the red handle to bring up a menu. change the button's label and selector (increment, decrement, etc).
5) [this is the step that doesn't work for me anymore...] you should be able to pick up a button morph with the black halo handle, and move it on top of the LedMorph. When you look at the button's menu, it should have a new entry that allows you to set the button's target. However, it's not working for me anymore under 2.5 (running with a 2.4VM under LinuxPPC).
6) pick up & drop the LedMorph and buttons onto the alignment morph, and choose "embed..." from their menus.
-- tim
squeak-dev@lists.squeakfoundation.org