(archive 'newLISPer)

August 25, 2007

Make a Mac app

Filed under: newLISP — newlisper @ 15:29

If you’ve written some handy applications using newLISP-GS, you might want to make them double-clickable – or runnable – so that they behave like other MacOS X apps. You can do this using a handy little utility called Platypus. Just switch to the Finder, drag your newLISP script over to the Platypus window (into the “Script Path” field) and click Create. Your script is now an application!

Of course, it won’t run on another Mac that doesn’t have a newLISP 9.2 installation already present: it’s just a wrapper (or bundle), rather than a stand-alone app. But it means that you can treat your application in the same way as – or even better than – any other app, such as, say, Microsoft Word. Put it in the Dock, select it using Quicksilver or Launchbar, whatever. You don’t have to open a terminal window or an editor to launch it.

I’ve yet to experiment with all the options (the Run in Background looks like it will launch the wrapper application in the background, leaving just the newLISP-GS application visible), but it’s worth noting that you can drag an image to the icon well. This puts a pretty icon onto your new application. I could use the excellent newLISP dragonfly (newlisp128.png) which lurks inside the newLISP-GS distribution, but a special ‘application built with newLISP-GS’ icon would be worth designing. Until then, a picture of the species Cordulegaster Obliqua (from dragonflies.org) resting on some unfinished newLISP documentation will suffice:

In a Finder window it looks a bit too fiddly, perhaps?


August 21, 2007

newLISP news

Filed under: newLISP — newlisper @ 15:56

I’ve not been writing too much here recently, but here are a few bits and pieces to stop the page from fading away completely.

newLISP version 9.2 has just been released, containing all the graphical goodness that I wrote about previously. I’ve been learning how to use it by trying to write some simple applications. You can laugh at these over at the newLISP fan club wiki, which Ryon has kindly made available for us to play around with. After having a go at Life, the well-known cellular automaton game, I tried to write a version of Reversi, the well-known black and white counter game. There’s also a simple countdown timer, and a slideshow app which I abandoned because it didn’t work out as well as I’d hoped. (Finishing things is harder than starting them, I find.)

One of the hardest things to do, particularly if you’ve been used to writing scripts, is to remember that a graphical application is mainly event-driven – you put everything place and then just wait for things to happen, although you don’t know what order they’re going to happen in.

I’ve also been updating my Introduction to newLISP in an attempt to keep up both with the errors and omissions that I and others notice and with the never-ending succession of improvements that Lutz manages to produce for each release. I’ve added a little taster for the new graphics tools in the form of a simple color mixer.

There’s a brief line by line description of the following code in the final chapter:

(if (= ostype "Win32")
    (load (string (env "PROGRAMFILES") "/newlisp/guiserver.lsp"))
    (load "/usr/share/newlisp/guiserver.lsp")


(gs:frame 'Mixer 200 200 400 300 "Mixer")
(gs:set-border-layout 'Mixer)
(gs:set-resizable 'Mixer nil)

(gs:panel 'SliderPanel)
(gs:set-grid-layout 'SliderPanel 3 1)
(gs:panel 'RedPanel)
(gs:panel 'GreenPanel)
(gs:panel 'BluePanel)

(gs:label 'Red   "Red"   "left" 50 10 )
(gs:label 'Green "Green" "left" 50 10 )
(gs:label 'Blue  "Blue"  "left" 50 10 )
(gs:slider 'RedSlider   'slider-handler "horizontal" 0 100 0)
(gs:slider 'GreenSlider 'slider-handler "horizontal" 0 100 0)
(gs:slider 'BlueSlider  'slider-handler "horizontal" 0 100 0)
(gs:label 'RedSliderStatus   "0"  "right" 50 10)
(gs:label 'GreenSliderStatus "0"  "right" 50 10)
(gs:label 'BlueSliderStatus  "0"  "right" 50 10)
(gs:add-to 'RedPanel 'Red 'RedSlider 'RedSliderStatus)
(gs:add-to 'GreenPanel 'Green 'GreenSlider 'GreenSliderStatus)
(gs:add-to 'BluePanel 'Blue 'BlueSlider 'BlueSliderStatus)
(gs:add-to 'SliderPanel 'RedPanel 'GreenPanel 'BluePanel)

(gs:canvas 'Swatch)
(gs:label 'Value "")
(gs:set-font 'Value "Sans Serif" 16)

(gs:add-to 'Mixer 'SliderPanel "north" 'Swatch "center" 'Value "south")
(gs:set-visible 'Mixer true)

(define (codes r g b)
; return codes for r g b values between 0 and 1 as newLISP and hex
  (string (list r g b) {  }
        (fn (n) (format {%02x} (mul n 255)))
        (list r g b)))))

(set 'red 0 'green 0 'blue 0)
(gs:set-color 'Swatch (list red green blue))
(gs:set-text  'Value (codes red green blue))

(define (slider-handler id value)
     ((= id "MAIN:RedSlider")
        (set 'red (div value 100))
        (gs:set-text 'RedSliderStatus (string red)))
     ((= id "MAIN:GreenSlider")
       (set 'green (div value 100))
        (gs:set-text 'GreenSliderStatus (string green)))
     ((= id "MAIN:BlueSlider")
       (set 'blue (div value 100))
       (gs:set-text 'BlueSliderStatus (string blue)))
  (gs:set-color 'Swatch (list red green blue))
  (gs:set-text  'Value (codes red green blue)))


Also, Dukester on the newLISP board convinced me that an HTML version of this PDF intro might a Good Thing. Obviously, keeping the two versions in sync would also be a Good Thing, so I’ve written a translator that converts the TEX (ConTeXt) source file to HTML. You can find a rough HTML translation of the introduction here. Be aware that the graphic images haven’t been uploaded (yet?), and that I’m not known for my HTML and CSS skills anyway. But you should be able to apply a CSS style sheet (called styles.css) to a local copy and get things looking the way you want them.

Blog at WordPress.com.