Event handlers in a different module than form definition?

Guiserver, GTK-server, OpenGL, PostScript,
HTML 5, MIDI, IDE
Locked
alexr
Posts: 4
Joined: Tue Sep 09, 2008 5:20 am

Event handlers in a different module than form definition?

Post by alexr »

I am a newcomer to newlisp and am not sure how to break my code up in modules when it comes to gui forms.

The app I'd like to write will need a few forms and I would like to save each form definition (hence calls to gs: functions) in its own file. Actions local to each form would be defined within that form's file. Other actions would ideally be defined as passing control to some controller defined in the main file.

I tried the code below, but it fails and reports the following error:

Code: Select all

ERR: symbol is protected in function setq : callback
called from user defined function form1
called from user defined function app:run
My code goes like this:

Code: Select all

#!/usr/bin/env newlisp

; app.lsp
;

;; load modules
(load (append (env "NEWLISPDIR") "/guiserver.lsp")) 
(load "form1.lsp")
(load "form2.lsp")

;; definitions
(context 'app)

;;; handlers	
(define (app:got-event id value)
	(begin
		()))
		
;;; run
(define (run)
	(begin
		(setq f1 (form1 'app:got-event))
		(setq f2 (form2 'app:got-event))
		(gs:set-visible 'f1 true)
		(gs:listen)))

;; go
(run)
Form1 file goes like this:

Code: Select all

#!/usr/bin/env newlisp

; form1.lsp
;

;; load modules
(load (append (env "NEWLISPDIR") "/guiserver.lsp")) 

;; definitions
(context 'form1)

(define (form1:form1 callback)
	(begin
		(gs:init)
		(gs:frame 'Form1 200 200 320 480 "Form 1")
		(gs:button 'Btn1 callback "OK 1")
		(gs:add-to 'Form1 'Btn1)))
Thanks in advance,
Alex

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

- 'callback' is a newLISP built-int function reserved name, you cannot use that as a parameter name in the function form1:form1

- don't load guiserver.lsp a second time in form1.lsp , everytime you load guiserver.lsp you start a new application. Make the main application widnow a gs:frame and others gs:dialog.

alexr
Posts: 4
Joined: Tue Sep 09, 2008 5:20 am

Post by alexr »

Instead of making the other components dialogs, can I make them panels instead and add those to my application frame?

Something like:

Code: Select all

;;; run
(define (run)
	(begin
		(gs:init)
		(gs:frame 'Main 200 200 320 480 "Main")
		(setq p1 (pane1 'app:got-event))
		(setq p2 (pane2 'app:got-event))
		(gs:add-to 'Main 'p1)
		(gs:set-visible 'Main true)
		(gs:listen)))

;; go
(run)
and in my pane1.lsp and pane2.lsp files:

Code: Select all

(define (pane1:pane1 cbak)
	(begin
		(gs:panel 'pane1)
		(gs:button 'Btn1 cbak "OK 1")
		(gs:add-to 'pane1 'Btn1)))
Rhetorical question actually, because I just tried and get an error message:

Code: Select all

add-to app:Main app:p1 : Could not invoke method add-to with app:Main

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Instead of making the other components dialogs, can I make them panels instead and add those to my application frame?
Yes, absolutely.

You may also want to look into the gs:tabbed-pane control. There is a demo about this in tabs-demo.lsp. These are nice when you need to switch beck and forth between different forms.

alexr
Posts: 4
Joined: Tue Sep 09, 2008 5:20 am

Post by alexr »

You may also want to look into the gs:tabbed-pane control. There is a demo about this in tabs-demo.lsp. These are nice when you need to switch beck and forth between different forms.
I'm running on OSX and just installed the latest (9.4.5). Where is tabs-demo.lsp?

Thanks
Alex

alexr
Posts: 4
Joined: Tue Sep 09, 2008 5:20 am

Post by alexr »

Okay found it in /usr/share/newlisp/guiserver. I must have missed it in the docs.

Locked