You should be automatically redirected . If not, visit
and update your bookmarks.



The big newLISP news at the moment is the imminent first release of the graphical user interface toolkit that's been developed to enhance and complement the newLISP language. Currently still in development, it's already an impressive system for creating graphical user interfaces using newLISP.

I haven't spent much time with it yet - there's a lot of documentation to read too - but it looks as if it continues the newLISP tradition of combining considerable power with elegance and ease of use.

Here's a very simple example of how it works, an on-screen digital clock. It's only about 16 lines of code, so it's short and sweet.


Oh yes.

Check to see whether we're running on Windows or a Unix, and load the right version:

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

This creates a gs context with all the functions we'll need. We'll initialize it:


Now to create a window at (100,800), 400 pixels wide by 100 pixels high, and set the background colour to be transparent black (the four numbers here are the RGB values plus an alpha component):

    (gs:window 'Window 100 800 400 100)
    (gs:set-background 'Window 0 0 0 0)

We want somewhere to put the text. We'll use a label, call it 'Time, and set the horizontal justification to 'left':

    (gs:label 'Time "" "left")

We can now set the font and colour properties of this label. I'm quite partial to those old-style numbers (with descenders), so I'm going to use Big Caslon, in white. You may prefer a dainty Helvetica or a more technical mono-spaced Courier look:

    (gs:set-font 'Time "Big Caslon" 32)
    (gs:set-foreground 'Time gs:white )

Next, a crucial step: add all the bits we've defined to the container. By default, newLISP uses the flow layout (you can get an idea of the concepts behind the various layout techniques here, which is the easiest one to handle: we can just add the Time label to the Window container.

    (gs:add-to 'Window 'Time)

So far all this has been done with the window invisible, so let's make the window visible:

    (gs:set-visible 'Window true)

Now for the main event (loop). This basically just hangs around waiting for something to happen, and occasionally sets the label's text to show the current date and time.

    (while (gs:check-event 100000) ; microseconds
        (sleep 200) ; milliseconds
        (gs:set-text 'Time 
            (date (date-value) 0 "%Y-%m-%d %H:%M:%S")))

and that's it!


(Not sure whether we need that...)

Bear in mind that this is just a trivial 'hello world' widget. It doesn't use any of the controls that make up rich interfaces, such as menus, sliders, radio buttons, check boxes, and so on, although these are all available and just as easy to use. With a bit more code, it would be a straightforward task to build a newLISP application. There's already a newLISP editor application written in newLISP provided as part of the installation.

As I see it, there are only two problems with these new capabilities.

The first is that it's so much fun playing with this stuff that I may not get anything else done at all.

The second thing is that I have a slight aversion to the word 'guiserver' - it's that ugly combination of TLA abbreviation and tech-speak that I don't want to see wherever I look on my computer. So I've been unable to resist changing a few lines in the /usr/share/newlisp/guiserver.lsp code so that I don't have to see it:

    (if   (not (= (main-args 3) "javastart"))
                (string {java 
                     -Xdock:name="newLISP GS"  
                    -jar } server-path " " portIn)))

These command-line options (which are probably MacOS X specific) do two things. The first replaces the Java coffee cup icon with the finely fashioned dragonfly (courtesy of michael I believe) which I've copied out of the Java archive. The second displays the application name 'newLISP GS' in the dock, menu bar, and activity viewer. Yes, I'll have to do this every time the guiserver.lsp file is updated! Worth every second, though...


At 18:01, Blogger don Lucio said...

Nice application, thanks for showing the dock-icon trick. For MacBook users I recommend changing the windows coordinates so the clock doesn't appear off screen:

(gs:window 'Window 100 650 400 100)

it will now appear in the bottom left.

At 20:34, Anonymous m i c h a e l said...

Hi cormullion!

Just wanted to say I enjoyed your article (always do) and wanted to give you a little script:


(set 'file-name "/usr/share/newlisp/guiserver.lsp")

{(process (string "java -jar " server-path " " portIn))}
(read-file file-name)
[text](process (string {java -Xdock:icon="/usr/share/newlisp/newLISP128.png" -Xdock:name="newLISP GS" -jar } server-path " " portIn))[/text]))



Makes it a little easier, anyway ;-)

m i c h a e l

P.S. Forgot to post a comment on your moon phases article, but I meant to say how much I liked it and think the graphics you did with ps look great!

At 21:40, Blogger newlisper said...

thanks! the script works a treat...

If you keep on encouraging me, I'll only write some more ... ;-)


Post a Comment

Links to this post:

Create a Link

<< Home