A Beginner Does Some Morphic Stuff

Ed Heil uncorrected at yahoo.com
Sun Nov 4 20:22:19 UTC 2001


Hey, guys, just checking in to say... this stuff is *cool*.

I was poking around, doing different things, and came across the
HttpShowGif method, and I thought, "wouldn't it be cool to do a
program that had a button I could push and it would show me today's
Dilbert cartoon?  And another one for pvp online?  And another one for
Get Fuzzy?  and...." 

I knew of a program *like* this, a perl script called 'dailystrips'
(it's on Freshmeat.net if you want to check it out).  I made a class
and gave it class methods (like HttpShowGif is a class method) to grab
several different strips.  And it worked.  :)  I made it a subclass of
rectangle and gave it an 'initialize' instance method that created
SimpleButtonMorphs on itself which did the things it was supposed to
do.  (*)

Then I realized... 

This isn't really quite the Morphic way to do it is it?  I could have
just pulled together a Morph to use as the interface, without
necessarily having it produced by any method of my ComicsGrabber
whatsoever...   Then saved the Morph to a file and that would be the
user interface, not the result of methods called from a class, but
pure Morphs, created as Morphs, saved as Morphs.

Am I correct in believing that that is the optimal way to use Morphic,
that you don't create new classes unless you really are trying to
create something that is different in kind from what has gone before,
and that where possible instead of creating an application by means of
subclassing, you create it by assembling existing bits?

That's cool.  Is that a Self thing kinda?

Thanks,

Ed

P.S. I'll enclose the first version of the comicsgrabber, the one that
has a simplistic UI built into its 'initialize' method, just to show
what I'm talking about....

*ethics note:  by doing this I realize I am bypassing the comics
 creators' pages and costing them advertising revenue.  But I tried to
 go to, say, the Dilbert home page in Scamper and it brought Scamper
 to its knees, all that incredibly gratuitous layout and excess crap!
 I consider the tiny loss of ad hits engendered by this tool to be an
 unfortunate consequence of the syndicates making pages that are too
 hideously complex to be reasonably viewable in Scamper. :)
-------------- next part --------------
'From Squeak3.1alpha of 21 October 2001 [latest update: #3617] on 4 November 2001 at 1:06:35 pm'!
RectangleMorph subclass: #EdsComicsGrabber
	instanceVariableNames: 'date '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'EdsWackShit'!

!EdsComicsGrabber methodsFor: 'as yet unclassified' stamp: 'ejh 11/4/2001 13:05'!
initialize
 "blah"
 | comicslist |
	super initialize.

	date _ (Date today).
	comicslist _ {
					{'Rose Is Rose' . #showUnitedMediaComicsStrip:date: . {'roseisrose' . date } } .
				 	{'Get Fuzzy' . #showUnitedMediaComicsStrip:date: . {'getfuzzy' . date } }.
					{'Monty' . #showUnitedMediaComicsStrip:date: . {'monty' . date } } . 
					{'User Friendly' . #showUserFriendlyDate: . { date } }.
				 	{'Dilbert' . #showUnitedMediaComicsStrip:date: . { 'dilbert' . date } } .
					{'PVP Online' . #showPvpDate: . { date } } .

				}.


	self layoutPolicy: (TableLayout new).
	self vResizing: #shrinkWrap.
	self hResizing: #shrinkWrap.


	comicslist do: [ : comictuple | | abutton|
		abutton _ SimpleButtonMorph new.
		abutton initializeWithLabel: (comictuple at: 1);	
			target: EdsComicsGrabber;
			actionSelector: (comictuple at: 2);
			arguments: (comictuple at: 3).
		self addMorph: abutton.
	].


! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

EdsComicsGrabber class
	instanceVariableNames: ''!

!EdsComicsGrabber class methodsFor: 'as yet unclassified' stamp: 'ejh 11/4/2001 12:41'!
fail
	"oops."

	|   |
	
	Transcript cr;  show: 'Damn, that didn''t work.'; cr.
! !

!EdsComicsGrabber class methodsFor: 'as yet unclassified' stamp: 'ejh 11/4/2001 13:05'!
showDorkTowerDate: stripdate 
	"grabs a strip from Dork Tower."

	"This doesn't work yet, for reasons I don't understand and will look into later.  Everything goes great until
	it actually tries to show the jpg, then the jpeg class chokes on it."

	| searchurl imageurl page searchpattern locationstart locationend  imageurltext |
	
	searchurl _ HttpUrl new privateInitializeFromText: (
		 'http://www.gamespy.com/comics/dorktower/' ).

	page _ (searchurl retrieveContents) content.

	searchpattern _ 'comics/dorktower/DorkTower'.

	locationstart _ (page findString: searchpattern).
	(locationstart = 0) ifTrue: [  Transcript show: searchpattern . EdsComicsGrabber fail. ]
	ifFalse: [
	locationend _ (page findString: '.jpg' startingAt: locationstart).
	imageurltext _ page copyFrom: locationstart to: (locationend + 3).

	imageurl _ ( searchurl asString,imageurltext ).
	HTTPSocket httpShowJpeg: imageurl .
 
	]! !

!EdsComicsGrabber class methodsFor: 'as yet unclassified' stamp: 'ejh 11/4/2001 12:11'!
showPvpDate: stripdate
	"grabs a strip from PVP Online."

	| imageurl |
	
	imageurl _ 'http://www.pvponline.com/archive/',
		(stripdate year asString), '/pvp',
		(stripdate year asString), 
		(stripdate monthIndex asString), 
		(stripdate dayOfMonth asString padded: #left to: 2 with: $0),'.gif'.

	HTTPSocket httpShowGif: imageurl.
 	^ imageurl.
	! !

!EdsComicsGrabber class methodsFor: 'as yet unclassified' stamp: 'ejh 11/4/2001 12:05'!
showUnitedMediaComicsStrip: stripname
	"grabs a strip from a UnitedMedia web page."

	self showUnitedMediaStrip: stripname date: (Date today) location: 'comics'.! !

!EdsComicsGrabber class methodsFor: 'as yet unclassified' stamp: 'ejh 11/4/2001 12:05'!
showUnitedMediaComicsStrip: stripname date: stripdate
	"grabs a strip from a UnitedMedia web page."

	self showUnitedMediaStrip: stripname date: stripdate location: 'comics'.! !

!EdsComicsGrabber class methodsFor: 'as yet unclassified' stamp: 'ejh 11/4/2001 12:41'!
showUnitedMediaStrip: stripname date: stripdate location: location
	"grabs a strip from a UnitedMedia web page."

	| searchurl imageurl imageurltext page searchpattern locationstart locationend  |
	
	searchurl _ HttpUrl new privateInitializeFromText: (
		 'http://www.unitedmedia.com/',location,'/', stripname,'/archive/',stripname,'-',
		(stripdate year asString), 
		(stripdate monthIndex asString), 
		(stripdate dayOfMonth asString padded: #left to: 2 with: $0), '.html').


	page _ (searchurl retrieveContents) content.

	searchpattern _ '/',location,'/',stripname,'/archive/images/',stripname.

	locationstart _ (page findString: searchpattern).
	(locationstart = 0) ifTrue: [  Transcript show: searchpattern . EdsComicsGrabber fail. ]
	ifFalse: [
	locationend _ (page findString: '.gif' startingAt: locationstart) +3.
	imageurltext _ page copyFrom: locationstart to: locationend.

	imageurl _ HttpUrl new privateInitializeFromText: imageurltext relativeTo: searchurl.
	HTTPSocket httpShowGif: (imageurl asString).
 
	]! !

!EdsComicsGrabber class methodsFor: 'as yet unclassified' stamp: 'ejh 11/4/2001 12:48'!
showUserFriendlyDate: stripdate 
	"grabs a strip from User Friendly."

	| searchurl imageurl page searchpattern locationstart locationend  |
	
	searchurl _ HttpUrl new privateInitializeFromText: (
		 'http://ars.userfriendly.org/cartoons/?id=',
		(stripdate year asString), 
		(stripdate monthIndex asString), 
		(stripdate dayOfMonth asString padded: #left to: 2 with: $0),'&mode=classic').

	page _ (searchurl retrieveContents) content.

	searchpattern _  'http://www.userfriendly.org/cartoons/archives/',
		(( (stripdate year ) \\ 100 ) asString padded: #left to: 2 with: $0),
		( (stripdate monthName ) asLowercase copyFrom: 1 to: 3 ), '/uf'.

	locationstart _ (page findString: searchpattern).
	(locationstart = 0) ifTrue: [ EdsComicsGrabber fail]
	ifFalse: [
	locationend _ (page findString: '.gif' startingAt: locationstart).
	imageurl _ page copyFrom: locationstart to: (locationend + 3).
 
	HTTPSocket httpShowGif: imageurl .
	]! !


More information about the Squeak-dev mailing list