Some sample code to help understand Morphic applications

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Some sample code to help understand Morphic applications

Michael Davies-2
Hello all,

I've been interested to read about some of the activities of the Documentation team, as I've recently been trying to work out how to build a GUI application in Squeak.

To that end, I've built a sample image viewer application, heavily annotated, to keep a record of my understanding of the following areas:
- Morphic layout
- Use of Models and Pluggable Morphs
- Interacting with the filesystem
- Launching and managing background processes

The code is attached, and can also be found at <a title="static project url" href="http://www.squeaksource.com/SampleImageViewer.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://www.squeaksource.com/SampleImageViewer.html

I'd appreciate it if anyone could spare some time to have a look at this sample and see if I'm making any obvious mistakes (especially my termination of processes, which I suspect isn't very robust), or if the 'squeakiness' of the code could be improved.

If anyone from the Documentation team is building a repository of sample code for beginners, I'd be happy to incorporate this application into such a repository.

Thanks in advance for any comments,
Michael


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

SampleCode-ImageViewer.st (20K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Some sample code to help understand Morphic applications

Another Dave

Thanks for writing some commented SAMPLE CODE for us Squeak newbies. Very NEEDED and appreciated!

I've been at this for about two weeks, and it's a little tough to make the transition between making a car go in circles to writing something useful.

I know enough to open a Morphic project, get your file list, and open it with the zip viewer. This is as close to the "file in" as I can seem to get, as the "load file" command will not show your file. I can load your code from there, but now what do I do with the blank screen? I'm obviously not loading or running it properly.


Reply | Threaded
Open this post in threaded view
|

Re: Some sample code to help understand Morphic applications

Tapple Gao
In reply to this post by Michael Davies-2
On Mon, Oct 16, 2006 at 01:49:20PM +0100, Michael Davies wrote:

>    Hello all,
>
>    I've been interested to read about some of the activities of the
>    Documentation team, as I've recently been trying to work out how to build
>    a GUI application in Squeak.
>
>    To that end, I've built a sample image viewer application, heavily
>    annotated, to keep a record of my understanding of the following areas:
>    - Morphic layout
>    - Use of Models and Pluggable Morphs
>    - Interacting with the filesystem
>    - Launching and managing background processes

Cool. That heavily commented SampleImageViewerMorph>>initialize is
especially useful

>    The code is attached, and can also be found at
>    http://www.squeaksource.com/SampleImageViewer.html
>
>    I'd appreciate it if anyone could spare some time to have a look at this
>    sample and see if I'm making any obvious mistakes (especially my
>    termination of processes, which I suspect isn't very robust), or if the
>    'squeakiness' of the code could be improved.

I am not sure, but every time I hit enter in the dir box, or
click the main panel, I get a debug window. What Squeak version
is this made for? I am using 3.8. A quick question: is the
correct way to run this program:
SampleImageViewerMorph new openInWorld

>    If anyone from the Documentation team is building a repository of sample
>    code for beginners, I'd be happy to incorporate this application into such
>    a repository.

We have not considered a code repository, but this morph is
quite simple, and may be useful in a tutorial. I might
incorporate it into my beginner's tutorial:
http://minnow.cc.gatech.edu/squeak/5869

--
Matthew Fulmer
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Some sample code to help understand Morphic applications

Michael Davies-2
In reply to this post by Another Dave
Hi Dave,
I know that feeling well! Having programmed in many environments over the years, I recognise that Squeak has lots of great stuff under the covers, but it takes a lot of work to find your way around at first.

Here's how to load and run the application from scratch:

Start in a Morphic Project (the project you're in when you launch Squeak is actually morphic, so there's no need to open one specially except for tidyness).

Click on the background. This will bring up the World menu. Choose "open..." then "file list", which will bring up a file browser.

Navigate to the file and click on it. You will see that the buttons will change to include a "file in" button. Click that button!

The code is then "filed-in" - you can look at it using the Browser (World menu>open>browser  or cmd-B (Mac) / Alt-B (PC)).

To run it, open a Workspace (World menu>open>workspace, cmd-K) and type "SampleImageViewerMorph new" (without the quotes), and press cmd-D/alt-D at the end of the line - the application should then launch.

Press the dir button to select a directory, then press enter in the directory text box, and enjoy the pictures!

I hope this helps.

Michael
 
ps the other way to load the code is using the Monticello Browser against the squeaksource.com code. This is really useful once you work out how to do it, especially for code that is likely to change. I'm sure I remember seeing an email that explained how to use it in great detail, but here's one from Avi Bryant that gives enough to get started:
http://lists.squeakfoundation.org/pipermail/squeak-dev/2004-July/079958.html
(change http://www.squeaksource.com/Graph
to http://www.squeaksource.com/SampleImageViewer in this case).

On 10/16/06, Another Dave <[hidden email]> wrote:


Thanks for writing some commented SAMPLE CODE for us Squeak newbies. Very
NEEDED and appreciated!

I've been at this for about two weeks, and it's a little tough to make the
transition between making a car go in circles to writing something useful.

I know enough to open a Morphic project, get your file list, and open it
with the zip viewer. This is as close to the "file in" as I can seem to get,
as the "load file" command will not show your file. I can load your code
from there, but now what do I do with the blank screen? I'm obviously not
loading or running it properly.



--
View this message in context: http://www.nabble.com/Some-sample-code-to-help-understand-Morphic-applications-tf2451978.html#a6838362
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Some sample code to help understand Morphic applications

Michael Davies-2
In reply to this post by Tapple Gao

On 10/17/06, Matthew Fulmer <[hidden email]> wrote:

Cool. That heavily commented SampleImageViewerMorph>>initialize is
especially useful

Yes, that took a while to get working as I wanted!

>    The code is attached, and can also be found at
>    <a href="http://www.squeaksource.com/SampleImageViewer.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.squeaksource.com/SampleImageViewer.html
>
>    I'd appreciate it if anyone could spare some time to have a look at this
>    sample and see if I'm making any obvious mistakes (especially my
>    termination of processes, which I suspect isn't very robust), or if the
>    'squeakiness' of the code could be improved.

I am not sure, but every time I hit enter in the dir box, or
click the main panel, I get a debug window. What Squeak version
is this made for? I am using 3.8. A quick question: is the
correct way to run this program:
SampleImageViewerMorph new openInWorld

Just "SampleImageViewerMorph new" is enough.
I found that I was using a couple of newish features (String>>startsWith: and Collection>>select:thenDo:), so I've replaced them. I've tested Version 2 (attached) on a 3.7/3.8 image.

>    If anyone from the Documentation team is building a repository of sample
>    code for beginners, I'd be happy to incorporate this application into such
>    a repository.

We have not considered a code repository, but this morph is
quite simple, and may be useful in a tutorial. I might
incorporate it into my beginner's tutorial:
<a href="http://minnow.cc.gatech.edu/squeak/5869" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://minnow.cc.gatech.edu/squeak/5869

Please feel free to do so. I'd be happy to contribute some more commentary if it would help. Maybe I should have written a test-case to go with it as well!

I think it would be a useful to have a set of such simple applications available to point new users at once they'd worked their way through tutorial materials and were wanting to get their teeth into something more meaty.

For instance, I'm now working on a simple rss reader which might sit nicely alongside this (grabbing content from the BBC news rss, parsing xml, and displaying the articles on a map background). I'd be interested in seeing if other people have some simple applications that could demonstrate other aspects which I know can be difficult to 'get' eg, communicating with the OS, use of DBs, persistency solutions. If there was a reasonable cross-section of code, it would be striaghtforward to have a set of "SampleCode-..." packages on SqueakMap to provide easy access.

Cheers,
Michael



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

SampleCode-ImageViewer.st (20K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Some sample code to help understand Morphic applications

Tapple Gao
On Tue, Oct 17, 2006 at 11:40:27AM +0100, Michael Davies wrote:
>    For instance, I'm now working on a simple rss reader which might sit
>    nicely alongside this (grabbing content from the BBC news rss, parsing
>    xml, and displaying the articles on a map background). I'd be interested
>    in seeing if other people have some simple applications that could
>    demonstrate other aspects which I know can be difficult to 'get' eg,
>    communicating with the OS, use of DBs, persistency solutions. If there was
>    a reasonable cross-section of code, it would be striaghtforward to have a
>    set of "SampleCode-..." packages on SqueakMap to provide easy access.

An RSS reader? You may want to work with Derek O'Connell, who is
working on a similar newbie project. His project is a Stock
chart that shows rising companies in blue and falling ones in
red, and he has also written a simple RSS reader:
http://minnow.cc.gatech.edu/squeak/5873

--
Matthew Fulmer
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Some sample code to help understand Morphic applications

Another Dave
In reply to this post by Michael Davies-2

Neither Squeak 3.8 nor 3.9 will give me that "file in" button, but now that I know the .mcz extension means Monticello I can make my incoming directory a repository and open it. From there I can load the image.

Starting things off with "SampleImageViewerMorph new"  in a workspace is really basic, but it is something that us new guys just don't get until we've done a few examples. I gather that the final class in the listing will generally be the one that you start the program with--bottom-up programming, as in Forth?

System browser, rt click on class category, then select printOut is another command that isn't talked about much, and I guess you have to "just know" that the .html output listing is not really HTML, but now I have a printed listing with lots of comments, and a running program with buttons and graphics.

Nice! Thanks!




Reply | Threaded
Open this post in threaded view
|

Re: Some sample code to help understand Morphic applications

Michael Davies-2
In reply to this post by Tapple Gao


An RSS reader? You may want to work with Derek O'Connell, who is
working on a similar newbie project. His project is a Stock
chart that shows rising companies in blue and falling ones in
red, and he has also written a simple RSS reader:
http://minnow.cc.gatech.edu/squeak/5873

Looks interesting - I'll have a closer look at that, thanks!


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Some sample code to help understand Morphic applications

Michael Davies-2
In reply to this post by Another Dave


On 10/18/06, Another Dave <[hidden email]> wrote:


Neither Squeak 3.8 nor 3.9 will give me that "file in" button, but now that
I know the .mcz extension means Monticello I can make my incoming directory
a repository and open it. From there I can load the image.

Sorry, I assumed it was the .st file you were having problems with.

Starting things off with "SampleImageViewerMorph new"  in a workspace is
really basic, but it is something that us new guys just don't get until
we've done a few examples.

That's been my experience too - once you understand the 'shape' of the solution you're trying to build, it's easier to use the browsers to find relevant code to learn from

I gather that the final class in the listing will
generally be the one that you start the program with--bottom-up programming,
as in Forth?

If I understand you right, then the answer's 'no'  - everything's listed alphabetically in the browser - it's just a co-incidence that this reflects the "level" of the classes in this case.

System browser, rt click on class category, then select printOut is another
command that isn't talked about much, and I guess you have to "just know"
that the .html output listing is not really HTML, but now I have a printed
listing with lots of comments, and a running program with buttons and
graphics.
Nice! Thanks!

No problem,
Michael



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners