View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Timmy Douglas cases

Other links: Timmy Douglas, timmy. gtg277i

Mini-Tutorials




Fixing the annoying 'print-it' behavior


"new code:"
        ifFalse: [Transcript show: (result printString); cr]
"old code:
        ifFalse: [self afterSelectionInsertAndSelect: result printString]"


"I left the old code commented out so I could always revert if it caused problems"

Advantages: printIt should no longer modify (making you delete it and confirming the changes with Alt-s, or having to click yes or no to some dialog) the current buffer when you just want to print stuff, so you don't have to worry about losing your selection or getting new crap output thrown into your current buffer.

Disadvantages: You need a transcript open and when you are modifying code in the debugger, sometimes it could get annoying to have to switch focus back and forth from the transcript to see the value from printit.

A GUI in 2 minutes

top

When I was trying to get a GUI in morphic for the first time, it was really annoying to have to swift through all the stupid cases code and old MVC code and bloated morphic code that wasn't quite what I was looking for. Here I'm going to tell you how to get something up with buttons that send messages to objects for you.

Note: supposedly AlignmentMorph is depricated, but squeak is a mess, and a lot of stuff uses(depends on) this morph, so I don't think you'll have any problems with this.

Note 2: I'm going to tell you what you can type into a Workspace window. You get these from the 'Tools' option on the side. You might also want a transcript. You will have to modify this code just a little when you put it inside an actual message (like by putting all the variables you use in separator bars).


First we make an object that can accept the 'value' message:

myMessageAcceptor := [Transcript show: 'hurray'].
"myMessageAcceptor value --> prints hurray on transcript"


Then we make two buttons, I show you how to use quotes in a string in the second button:

sayHurrayButton := SimpleButtonMorph new
		extent: 300@40;
		on: #mouseDown send: #value to: myMessageAcceptor;
		label: 'Cheer'.

nextLineButton := SimpleButtonMorph new
		extent: 300@40;
		on: #mouseDown send: #cr to: Transcript;
		label: 'Let''s go down a line'.


Now we make something that can hold these two buttons. (We don't have to—we could just say 'nextLineButton openInWorld', but then the user would have a harder time managing everything). Here it is:
gui := AlignmentMorph newColumn
		color: Color white;
		position: 50@200;		
		borderWidth: 1;		
		borderColor: Color black;
		hResizing: #shrinkWrap;		
		vResizing: #shrinkWrap;
		addMorph: sayHurrayButton;
		addMorph: nextLineButton.


Now that we have everything, we can tell the gui to display with:
gui openInWorld.


That's it—if you want to get rid of it, drag it to the trash can.
For another exercise, try making a button that sends the 'hide' message to 'gui'.


Delaying

top
I use:
    targetTime := (Time now) addTime: (Time fromSeconds: delay).

"..a little later on.."

    [ Time now < targetTime ]
        whileTrue: [ World doOneCycle. ].



Discussion: Depending on the situation, you can also override the 'step' and 'stepTime' message that derivatives of Morph have if you want to use morphic. But I opted not to do it that way. I think it complicates things. I want to be able to know where the point of execution in my program is. If I use step, then I _might_ have to think about syncronization and other timing issues as well.

Keyboard focus

top

You might be like: wtf is my imagemorph not getting keyboard focus when I click on it and drag it around and crap?!? The long answer is that morphic is crappy. The short answer is that you need to do something like this:

ActiveHand newKeyboardFocus: myMorphThatCantGetKeyBoardFocus.

Then you just have to override:
handleKeystroke evt:
    (evt keyCharacter asciiValue = 27) ifTrue: [Transcript show: 'whoa!';cr.].





top



Link to this Page