appropriate list...YES!

Sam Adams ssadams at us.ibm.com
Mon Feb 11 04:06:36 UTC 2002


On Mon, 11 Feb 2002, **Leigh** wrote:
> O.K...well here is a question.
>
> How can I get two forms to post simultaneously?  I've got one that
> is a jpeg that I'm trying to use as wallpaper; I'm bringing it in
> using 'fromFileNamed' and using the 'setAsBackground' method.  It shows
> up great.  Then I create a separate form using a generic Form command
> (method?) and although it gets posted as well, and displays the
> results of the sim I've created, as soon as the sim finishes execution
> the jpeg form retakes precedence and covers up the sim form.   This is
> a simple MVC project so far; do I have to get into morphic to get
> multiple displays?


Sounds like you are setting the background OK, but when you "post the
second form" as you put it, it gets erased quickly in favor of the
background.  If I have this right then you need to put the second Form
instance in an MVC window and open it on the desktop instead of simply
displaying it on the Display (background).

Try this:

FormView open: Form fromUser named: 'My Form'

When you "do it", this will prompt you to describe a rectangular area of
the display by pressing the left mouse down with the cursor at the upper
left corner of the desired area and dragging the cursor to the lower right
corner then releasing the left mouse button.  This "Form fromUser" method
let you create a new instance of a Form that is basically a copy of part of
the display.  This new Form instance is then passed as an argument to the
open:named: method in the class FormView, whose sole job in life is the
persistent display of Forms on the MVC desktop.

If you change the above code to use the form your "sim" generates, it will
merrily open an MVC window on the display with your form in it, and it will
not disappear when the background is redrawn when the display is refreshed.
You code would look something like this:

resultsForm := Form extent: 200 at 200.  "whatever the size of Form you want"

... your sim code that draws on the form in the variable "resultsForm"...

FormView open: resultsForm named: 'Leigh''s Sim Results'

That should do it!

As for being a newbie, WELCOME to Squeak!
BTW, even though I have used MVC for many years, I don't try to remember
all the ways to do things like the trick above.  I did remember that there
was a class named "FormView", so I searched in the Browser and found the
class and a class method open:named: which had a handy snippet of demo code
in the method comment (method shown below):

open: aForm named: aString
      "FormView open: ((Form extent: 100 at 100) borderWidth: 1) named:
'Squeak' "
      "Open a window whose model is aForm and whose label is aString."
      | topView aView |
      topView _ StandardSystemView new.
      topView model: aForm.
      topView label: aString.
      topView minimumSize: 80 at 80.
      aView _ FormView new.
      aView model: aForm.
      aView window: (aForm boundingBox expandBy: 2).
      aView borderWidthLeft: 2 right: 2 top: 2 bottom: 2.
      topView addSubView: aView.
      topView controller open


Not only did the demo code work with a "doit", but the method code shows a
nicely detailed example of creating and opening an MVC window.  Be sure to
check out the other class methods exampleOne and exampleTwo!  Squeak is
chock full of such tidbits and breadcrumbs.

Another newbie hint for finding such goodies is to select a class you want
to learn about in the Browser, such as "Form", then pop up the menu in that
pane and select "class references".  This will open a method list browser
that will show you every(!) method in Squeak where the class Form is
referenced.  Since references to classes (with capitalized names like Form,
View, String) are mostly only found when someone is creating a new instance
of them, you will very quickly find lots of examples of how other Squeakers
(and Smalltalkers before them) have used the class.

Morphic is way cool and for this example even simpler to use than FormView.
Try:

Form fromUser asMorph openInWorld

This will work either in an MVC or Morphic Project, although in a Morphic
project the form simply exists as a morph on the desktop, without title or
window frame.

Have fun and consider posting your sim work sometime so others can share in
your discoveries!  :-)

Regards,
Sam

Sam S. Adams, IBM Distinguished Engineer, IBM Research
tie line 444-0736, outside 919-254-0736, email: ssadams at us.ibm.com
<<Hebrews 11:6, Proverbs 3:5-6, Romans 1:16-17, I Corinthians 1:10>>




More information about the Squeak-dev mailing list