Event handlers in a different module than form definition?

Started by alexr, September 09, 2008, 12:22:52 AM

Previous topic - Next topic

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:
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:

#!/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:

#!/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

#1
- '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

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



Something like:


;;; 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:
(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:

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

Lutz

#3
QuoteInstead 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

#4
QuoteYou 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

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