Showing posts with label smalltalk. Show all posts
Showing posts with label smalltalk. Show all posts

Tuesday, July 12, 2011

TWM: Docking Windows

Using Pharo 1.4 and latest TWM packages, you can now group windows as tabs.

Use:
(ConfigurationOfTilingWindowManager project 
    version: #bleedingEdge) load



Tuesday, June 7, 2011

Multiple Worlds for TWM

With the help of my local developper group, I've integrated Sean DeNigris work and now Tiling Window Manager supports Multiple Worlds.

Here's a screencast that shows the progress. (My English seems a little less catastrophic than the previous screencast :)

Note: The tests failing on the screencast (Pharo 1.2) are green on Pharo 1.3.



Load TWM with:
Gofer it
  squeaksource: 'TilingWindowManager';
  package: 'TWM';
  load.


And ConfigurationOfKeyMapping 1.7 (TWM do not work with 1.8 actually) with:
Gofer it
    squeaksource: 'ShortWays';
    package: 'ConfigurationOfKeymapping';
    load.
    
(ConfigurationOfKeymapping project version: '1.7') load.

Saturday, May 28, 2011

Tiling Window Manager

I love Emacs because of editing speed and fast buffer switching among a lot neat features.

This week I've tried to make Pharo a little better on window management. This video shows the progress (thanks Gastón and Patrick for help and ideas).

Next step: KeyMapping integration + history à la Emacs winner-mode.

Sorry for my soooooooo awful english (tired ....).


Update 05/31/2011: you can load last version with colored theme with:
Gofer it
  squeaksource: 'TilingWindowManager';
  package: 'TWM';
  load.
(Smalltalk at: #StandardUITheme) beCurrent.
(Smalltalk at: #TWMBar) showTWMBar:true.


Tested on PharoCore 1.2 and Pharo 1.3.

Now this has support for world snapshot, that means you can arrange the windows and take a snapshot of the layout. Then you can restore these layouts later. (icons camera, <, > and trash). I'm not entirely satisfied with this, thanks for feedback.

In Pharo 1.3 there's initial integration with KeyMapping. To load:

Gofer it
  squeaksource: 'ShortWays';
  package: 'ConfigurationOfKeymapping';
  load.

(Smalltalk at: #ConfigurationOfKeymapping project version: '1.7') load.


Then in settings browser > Keymappings > Tiling Window Managers you have all actions of the dock mapped.

You can choose a Layout Strategy in settings.

Actually there's Horizontal (default) and Vertical (last used windows fills all remaining space) strategies.

To add your own just subclass TWMLayoutStrategy and implement #tileWindows:



To load TWM:
Gofer it
 squeaksource: 'TilingWindowManager';
 package: 'TWM';
 load.


I also think the UI theme Patrick has cleaned fits better with TilingWM:
Gofer it
 squeaksource: 'PBASandbox';
 package: 'PBSandbox';
 load.
 
StandardUITheme beCurrent.

Wednesday, April 13, 2011

Petite Horloge revisited

Another Pharo Smalltalk snippet with temp classes (I like this :)

(Class new
    superclass: StringMorph;
    setFormat: StringMorph format;
    compile: 'step self contents: Time now printString';
    new)
        openInWindowLabeled: 'Petite Horloge'.


Don't forget the setFormat: or the VM will crash.Some explanations.

Polymorph counter example

I've discovered that I can write this in Pharo:

"This creates a class and one instance on the fly"
counter := Class new 
              superclass: Object; 
              addInstVarNamed: 'counter'; 
              compile: 'initialize 
                           counter := 0';
              compile: 'counterString 
                           ^ counter asString';
              compile: 'increment 
                           counter := counter + 1. 
                           self changed:#counterString';
              compile: 'decrement 
                           counter := counter - 1. 
                           self changed:#counterString';
              new.

(UITheme builder newColumn: {
  UITheme builder newLabelFor: counter getLabel: #counterString getEnabled: nil.
  UITheme builder newRow: {
    UITheme builder newButtonFor: counter action: #increment label: '+' help: nil.
    UITheme builder newButtonFor: counter action: #decrement label: '-' help: nil.
  }
}) openInWindowLabeled: 'Counter example'.

Coooooooooooooool ;)

Saturday, March 19, 2011

Multiple worlds for Pharo

Sean DeNigris submitted a changeset to get multiple worlds in Pharo.

I've played a little with it to get a world switcher. If you want it, first file in the changeset file (download it the drag the file on an opened image).

Then the following code add three worlds named 2,3,4 and create a dock in each world.

|wm|
wm := WorldManager instance.
#('2' '3' '4') do: [:aString| wm createOrSwitchToWorldNamed: aString].

wm worlds keysAndValuesDo:  [:aWorldName :aWorld| |dock|
  dock := DockingBarMorph new
          adhereToTop;
          openInWorld: aWorld.

  wm worlds keysAndValuesDo: [:aWorldName2 :aWorld2|
    dock addMorph: (SimpleButtonMorph new
                    label: aWorldName2;
                    target: [wm createOrSwitchToWorldNamed: aWorldName2];
                    actionSelector: #value) ].
                    
  dock addMorph: (StringMorph contents: aWorldName).
].

Monday, February 28, 2011

Work on Mocketry

Mocketry is a Mocketry is Smalltalk mock object framework.

To load it in Pharo:
Gofer it
  squeaksource: 'MetacelloRepository';
  package: 'ConfigurationOfMocketry';
  load.

(Smalltalk at:#ConfigurationOfMocketry) project latestVersion load.


I've done the first part of the Picasa screencast in a TDD way using Mocketry to prevent external HTTP requests.
Gofer it
 squeaksource: 'LaurentLSandbox';
 package: 'Picasa';
 load.

As the requests are done using HTTPSocket class>>httpGet:, one way is to give a mock to PicasaSearch so we can check (and stub) the HTTP request:
PicasaSearchTwoRoughSeaTest>>setUp
  [:mockHTTPSocketClass|
    [photos := PicasaSearch new
        httpSocketClass: mockHTTPSocketClass;
        addKeyword: 'rough';
        addKeyword: 'sea';  
        maxResult: 2;
        photos.] 
 
     should strictly satisfy: [
        (mockHTTPSocketClass httpGet: 
          'http://picasaweb.google.com/data/feed/api/all?q=rough+sea&max-results=2')
        willReturn: self fixtureXMLResponseForTwoRoughSea] 
  ] runScenario.

#fixtureXMLResponseForTwoRoughSea will return an XML string and test methods will check that it is correctly parsed.

In PicasaSearch:
httpGetDocument 
  |url| 
  url := String streamContents: [:aStream|
  aStream 
    nextPutAll: 'http://picasaweb.google.com/data/feed/api/all?q=';
    nextPutAll: ('+'  join: self keywords);
    nextPutAll: '&max-results=';
    nextPutAll: self maxResult asString.    
  ].  

  ^ (self httpSocketClass httpGet: url).


See that mocketry extends BlockClosure to create mocks:
[:myFirstMock :mySecondMock|
"do stuff with mocks"
] runScenario

and set up expectations:
[:myFirstMock :mySecondMock|
  [ "do stuff with mocks" ] 
  should strictly satisfy: 
  [ "what is expected on mocks" ]  
] runScenario

See HelpSystem book loaded with Mocketry for several examples.

Comments and better code propositions are welcome.

Monday, February 21, 2011

XML Browser with Pharo

I've written a little tool to help me browse xml. If you want to try it:
Gofer new
 squeaksource: 'LaurentLSandbox';
 package: 'XML-GUI';
 load.
 
((Smalltalk at:#XMLBrowser) labelled: 'Picasa search')
  browseAtUrl: 
   'http://picasaweb.google.com/data/feed/api/all?q=lighthouse&max-results=10'.



See XMLBrowser comment for examples.

Friday, February 18, 2011

FizzBuzz Kata: minimal solution

Trying to find a minimal solution for the FizzBuzz Kata in Smalltalk:

fb := [:counter| |rules|
       rules := {15->'FizzBuzz'. 5->'Buzz'. 3->'Fizz'. 1->counter}.
       rightRule := rules detect: [:aRule| counter \\ aRule key == 0].
       rightRule value].  

self assert: (fb value: 7) == 7.
self assert: (fb value: 3) == 'Fizz'.
self assert: (fb value: 5) == 'Buzz'.
self assert: (fb value: 15) == 'FizzBuzz'.

1 to: 100 do: [:counter | 
               Transcript 
                 show: (fb value: counter) asString;
                 cr]


Update: Little variant from Alexandre:
rightRule := rules detect: [:aRule| counter isDivisibleBy: aRule key]

Tuesday, February 8, 2011

Smalltalk tiny exercise for TDD newbies

Done in course:

Create the category Exercise in the Browser. All classes you create will be placed in this category.

Implement the class Operation (using Test-Driven Development) which should work like this:
  1. a := Operation new.
    a result.
    
    Should return 0.
  2. b := Operation new.
    b add: 2.
    b add: 3.
    b result.
    
    Should return 5.
  3. Operation new
      add: 2;
      add: 4;
      divideBy: 2;
      result.
    
    Should return 3.

Add the message Operation>>#multiplyBy by yourself.

Sunday, February 6, 2011

new funny ProfStef lesson

Update to last ProfStef (on Pharo 1.2 only):


Gofer it
 squeaksource: 'MetacelloRepository';
 package: 'ConfigurationOfProfStef';
 load.
 
ConfigurationOfProfStef project latestVersion load.

ProfStef 
  go;
  tutorial: SmalltalkSyntaxTutorial lesson: #instanciation.

Friday, January 28, 2011

Smalltalk à l'OSDC.fr 2010

Et là j'ai peur en me voyant en vidéo ....









Sunday, November 28, 2010

Revenge of Smalltalk

(Joke inside)

In Paul Graham's essay Revenge of the Nerds (Read it, good ideas there):

Appendix: Power

As an illustration of what I mean about the relative power of programming languages, consider the following problem. We want to write a function that generates accumulators-- a function that takes a number n, and returns a function that takes another number i and returns n incremented by i.

(That's incremented by, not plus. An accumulator has to accumulate.)

In Common Lisp this would be


(defun foo (n)
  (lambda (i) (incf n i)))


In Smalltalk the code is slightly longer than in Lisp:


foo: n                              
  |s|                      
  s := n.                          
  ^[:i| s := s+i. ]

because although in general lexical variables work, you can't do an assignment to a parameter, so you have to create a new variable s.



Well, the Lisp code has 34 significant characters while the Smalltalk code has only 25 significant characters (we can remove the last dot). So the Smalltalk code is 26% shorter than the Lisp code :)


  • Perl example: 32 characters
  • Javascript example: 46 characters
  • Python example: 54 characters
Yeah, Smalltalk is really powerful ;P


Update:
Looking at Parser code we can easily remove the temp. variable limitation and write:
foo: n               
  ^[:i| n := n+i]

So
  • One power of Smalltalk is to be able to change the system.
  • 17 significant characters: Smalltalk 100% more powerful than Lisp :D
  • (still a joke - but ....)


Why this design decision ? Some explanation from Nicolas and Adrian.

Tuesday, April 20, 2010

easy_squeakvm on github

I've created my first repository on github. So easy!

easy_squeakvm is used to build the squeak vm from scratch on Linux in one command.
To build the VM, just get the the script and execute

./easy_squeakvm.sh


This will

  • checkout squeakvm sources from svn repository
  • download PharoCore image
  • load VMMaker into PharoCore
  • generate the interpreter
  • build the VM
  • put binaries in out/squeakvm, ready to use


I was tired of typing the same commands over and over :)

http://github.com/lolgzs/easy_squeakvm

Wednesday, March 10, 2010

How I build squeak vm on (Arch)Linux

I write this post as a memento for me. I will appreciate some feedback on building the VM on other Linux distro.

1. Prepare a working directory

All the work will take place in ~/squeakvm (/home/lol/squeakvm on my machine):


mkdir ~/squeakvm
cd ~/squeakvm


2. Get squeak-vm source

The easiest part. The VM source code tarball can be found on http://www.squeakvm.org/unix/. At the time of writing, the last stable version is 3.11-3.2135. Go and get it:


wget http://www.squeakvm.org/unix/release/Squeak-3.11.3.2135-src.tar.gz
tar -xvzf Squeak-3.11.3.2135-src.tar.gz


3. Load VMMaker tool

For more explanations on why VMMaker is needed and how it works, here is a good overview.

To generate the source code for your own VM, you need a running Pharo image. Here I use a fresh Pharo 1.0-10508 rc2 image from Pharo website.

Open your image, then load VMMaker by evaluating this in a Workspace:

Gofer new
 squeaksource: 'MetacelloRepository';
 package: 'ConfigurationOfVMMaker';
 load.
 
(Smalltalk at:#ConfigurationOfVMMaker) project lastVersion load.




4. Load FT2Plugin

UPDATE: Should not be necessary now. See Javier's comment.

To display anti-aliased font of Pharo images, you need the FT2Plugin. To load it:

MCHttpRepository
 location:'http://www.squeaksource.com/FreeTypePlus'
 user: ''
 password: ''.

MCHttpRepository
 location: 'http://source.impara.de/freetype'
 user: ''
 password: ''.


5. Configure VMMaker and generate the VM source

Now you can open VMMakerTool:

VMMakerTool openInWorld


In the Path to platforms field put the path to the extracted Squeak VM tarball: ~/squeakvm/Squeak-3.11.3.2135-src.

Then right-click on one of the plugins pane and select make all external for a simple configuration.



Note you can have a description of each plugin by reading the class comment.Classes are part of VMMaker-Plugins category.

In path to generated source select a directory where the VM source will be written. Here ~/squeakvm/src32.

The VMMakerTool window should look like this:



Then click on the Entire button (top-left of window). Wait a moment, pray, and the code should be generated.

Finally, I replace the original VM source with the generated one.

rm -rf ~/squeakvm/Squeak-3.11.3.2135-src/unix/src
cp -a ~/squeakvm/src32 ~/squeakvm/Squeak-3.11.3.2135-src/unix/src


Note: theorically this should not be necessary as the configure script accepts an option to specify the source directory path, but it doesn't seem to work.

6. Build the VM

First create a directory for the build and go in:

mkdir ~/squeakvm/Squeak-3.11.3.2135-src/build
cd ~/squeakvm/Squeak-3.11.3.2135-src/build


Then run the configure script

../unix/cmake/configure 


First problem. I have this error:

CMake Warning (dev) in 
/home/lol/squeakvm/Squeak-3.11.3.2135-src/build/=/CMakeLists.txt:
  Syntax error in cmake code when parsing string

    ${=_link_directories}

  syntax error, unexpected cal_SYMBOL, expecting } (21)


Thanks to this mail there's a patch to correct it.


cd ~/squeakvm/Squeak-3.11.3.2135-src/unix/cmake/
wget http://lolgzs.free.fr/pharo/Plugins.cmake.patch
patch -p0 < Plugins.cmake.patch
Then clean and run the configure script again
cd ~/squeakvm/Squeak-3.11.3.2135-src/build
rm -rf *
../unix/cmake/configure 
You should have the Makefile now. Run make:
make
Then another problem as libfreetype (needed by FT2Plugin) is not found. To correct it, create config.cmake for FT2Plugin this way:
mkdir ~/squeakvm/Squeak-3.11.3.2135-src/unix/plugins/FT2Plugin/
echo "PLUGIN_FIND_LIBRARY(FT2 freetype)" > 
    ~/squeakvm/Squeak-3.11.3.2135-src/unix/plugins/FT2Plugin/config.cmake
More informations on this error here.

UPDATE: See Javier's comment.


Clean and run make again:
make clean
make
Then install:
sudo make install
7. Conclusion
The process is not so easy. To help I put all the squeakvm directory (with sources, pharo image with vmmaker) on http://lolgzs.free.fr/pharo/squeakvm.tar.gz

UPDATE: Good post for MacOSX

Saturday, January 30, 2010

Seaside-Hosting compatible Pharo

L'hébergeur gratuit (pour des applications non-commerciales) Seaside-Hosting accepte maintenant les images Pharo ! J'en ai donc profité pour déployer ma première image Seaside... et c'est d'une simplicité étonnante.

Il suffit juste de créer un compte, uploader son image, clicker sur Start et c'est fini. Cool.

J'ai donc mis en ligne une image avec SimpleWebDoc: http://magaloma.seasidehosting.st/

Friday, January 22, 2010

ProfStef news

ProfStef est inclut dans le Metacello Repository. Metacello permet de spécifier les dépendances entre packages.

Cela signifie qu'il est maintenant assez simple de charger ProfStef et ses dépendances dans Pharo via Loader (l'équivalent d'apt-get pour Pharo):
Gofer new
        squeaksource: 'Loader';
        package: 'Loader';
        load.

Loader new load: 'ProfStef'.


Il est maintenant possible de créer son propre tutorial intéractif pour ProfStef. Comment ? Il y a un tutorial pour ça :).

Dans un Workspace, évaluez:
ProfStef goOn: HowToMakeYourOwnTutorial.

Monday, January 18, 2010

Smalltalk interactive tutorial

ProfStef est un tutorial intéractif sur Smalltalk (un peu inspiré de Try Ruby).
L'objectif est d'apprendre les bases du langage Smalltalk de manière ludique.

Pour charger ProfStef dans votre image, évaluez le code suivant dans un Workspace:

Gofer new
    squeaksource: 'ProfStef';
    package: 'ProfStef';
    load.



Friday, January 8, 2010

GUI et Pharo

J'ai fait une vidéo sur Pharo montrant les techniques de base pour disposer des éléments dans une fenêtre et répondre aux clics sur les boutons.



Voici un des exemples de code de la vidéo:

|aWindow aPanel buttonPanel|

aWindow := SystemWindow labelled: 'My first window'.

aPanel := PluggablePanelMorph new.
aWindow addMorph: aPanel fullFrame: (
    LayoutFrame
        fractions: (0@0 corner: 1@1)
        offsets: (0@0 corner: 0@50 negated)).
aPanel color: (Color blue).

buttonPanel := PluggablePanelMorph new.
aWindow addMorph: buttonPanel fullFrame: ( 
    LayoutFrame
        fractions: (0@0.99 corner: 1@1)
        offsets: (0@50 negated corner: 0@0)).
buttonPanel  color: (Color green).


#(one two three) do: [:label| |aButton| 
 aButton := PluggableButtonMorph new label: label; yourself.
 buttonPanel addMorph: aButton fullFrame: nil.
].


aWindow openInWorld.

Friday, December 18, 2009

SimpleWebDoc et yUML

Je viens d'interfacer SimpleWebDoc et yUML pour générer les diagrammes d'héritage entre les classes d'un même package. Le tout à un clic de souris.

Le package Tests:



Le package Kernel: