Etoys Tips and Tricks

From OLPC
Revision as of 09:02, 13 March 2008 by Ties (talk | contribs) (added profiling info)
Jump to navigation Jump to search

Just a few tips and tricks to overcome a few common hurdles your average Etoys beginner (that would be me) might run into.


Oneliners

when image hangs: alt-.

recover from hang on smalltalk level: world-leftclick > changes > recently logged changes. Select all the relevant changes and file them in.


Text input box hacks

the Etoys input box is a bit flaky and basic at the moment. One of the OLE Nepal guys is working on a general fix, but for now we can tweak it with a few hacks:

Textboxes change size, depending on whether there is text in there or not. We can fix this by opening an inspector on an instance and execute:

self beAllFont: (StrikeFont familyName: 'BitStreamVeraSans' size: 24)

Or whatever font you want it to be of course.


To let the box respond with a function on a carriage return, define an etoys script (or squeak function) with, say, name #myOwnFunction, open an inspector on the appropriate instance and execute: self crAction:(MessageSend receiver: self player selector: #myOwnFunction)

To obtain keyboard focus on the textbox of your choice, you can use the following function:

obtainKeyboardFocus
	ActiveHand keyboardFocus: self costume renderedMorph.
	self costume renderedMorph editor selectAll

The last line perhaps doesn't give you what you want, cause it selects the whole text every time focus is lost and regained again, but you can always take it away of course.


Installing Monticello on your Etoys image

At the moment you hit upon a bug when you want to install Monticello in an Etoys image through Squeakmap.

There's a way around this though. As from http://ircbrowse.com/channel/squeak/20070927 :

First download MonticelloBackport.8.cs and Monticello-kph-434.st (or, if you want to install monticello as part of the Epaati image customization procedure, go to the monticello-hack-files dir in etoys-migration-files)

Load the MonticelloBackport.8.cs file into your image and then load the Monticello-kph-434.st file. While loading the latter you will hit upon an error. Push 'debug' and find MCWorkingCopy Initialize in the stack trace. Return 'nil' from it. Then open a workspace or something and execute 'MCWorkingCopy registerForNotifications'. This should provide you with a working Monticello. Upgrade Monticello if you feel like it.

There might be another way around this bug, which we have yet to try. There's a compatibility layer called 'level playing field' (levelPlayingField/LPF.st) which tries to smoothen out the differences between different image forks. Might work. Or we could fix the bug of course!!


Profiling in Smalltalk

From Luke Gorrie's mail on the Etoys list:

In this case what I did was find the guts to project loading (ProjectLoading>>openName:stream:fromDirectory:) and wrap most of the method body up like this:

TimeProfileBrowser onBlock: [
... original code ...
].

and that popped up a window with excellent time profile information. An alternative way to do this, which doesn't interact so well with project loading specifically, is to use WorldMenu->debug->'Start message tally' and then drag the mouse to the top of the screen to finish profiling.

Now when I'm looking at memory usage I'm using:

SpaceTally new printSpaceAnalysis

and then running its output (STspace.txt) through e.g.:

awk '$5 > 1 { print }'

to see classes accounting for >= 1% of memory usage. Then individually I can do something like:

(Bitmap allInstances select: [:b | b size > 100000]) explore

and use the inspector's 'chase pointers' command to get some idea of why each one exists.