Page 1 of 1
Console window in custom-application?
Posted: Wed Oct 22, 2003 7:01 am
by HPW
A nice feature would be to intergrate a console window in our own TK-Frontend. Like a listener-object in common-lisp, it would allow to output a command-log and input lisp-direct calls. Yes, sounds like an autocad command-line (Teach an old horse somthing new). Would be an subset of the newlisp-TK main-window logic. Command-promt should be configurable, so instead of "> " we can make "command: " or "Befehl: ". Also size and position should be configurable through TK. Sample would be very wellcomed for Tips and Tricks!!
Posted: Wed Oct 22, 2003 2:07 pm
by Lutz
Get a book about Tcl/Tk programming and look into the examples in the distribution, how to make callbacks from Tcl/Tk into newLISP. Here is something to get you started:
Code: Select all
(context 'EDIT)
(define (edit )
(tk "if {[winfo exists .ewin] == 1} {destroy .ewin}")
(tk "toplevel .ewin")
(tk "text .ewin.edit -width 60 -height 10")
(tk "pack .ewin.edit")
(tk "bind .ewin.edit <Return> {Newlisp {(silent (EDIT:getEditText))}}")
(tk "update idletasks"))
(define (getEditText )
(set 'text (tk ".ewin.edit get 1.0 end"))
(tk ".ewin.edit insert end {" (upper-case text) "}")
(tk "update idletasks"))
(context 'MAIN)
(EDIT:edit)
a window comes up and you type something in and hit <enter>, it comes back in uppercase (works only once, and I din't want to spend more time on it).
Lutz
Posted: Thu Oct 23, 2003 6:09 am
by HPW
Thanks for the start.
I had problems to get it to work.
I think this was a problem with this makro from init.lsp
Code: Select all
(define-macro (edit _func)
(save (string _func) _func)
(! (string "/usr/bin/vi " _func))
(load (string _func)))
So I rename the new edit function to "myedit" and it works as expected.
Is it possible that the namespace does not isolate the function against this makro?
Posted: Thu Oct 23, 2003 11:52 am
by Lutz
all functions defined in the parent context MAIN are also accessible in the other contexts. When you loadet the context it redefined 'edit' in main istead of creating it in the context EDIT.
Lutz
Posted: Thu Oct 23, 2003 1:07 pm
by HPW
Code: Select all
(context 'EDIT)
(define (edit )
(tk "if {[winfo exists .ewin] == 1} {destroy .ewin}")
(tk "toplevel .ewin")
(tk "text .ewin.edit -width 60 -height 10")
(tk "pack .ewin.edit")
(tk "bind .ewin.edit <Return> {Newlisp {(silent (EDIT:getEditText))}}")
(tk "update idletasks"))
(define (getEditText )
(set 'text (tk ".ewin.edit get 1.0 end"))
(tk ".ewin.edit insert end {" (upper-case text) "}")
(tk "update idletasks"))
(context 'MAIN)
When I load this code from file I find it strange that getEditText is in the namespace EDIT and edit is in MAIN. So when I use accidently a same name, it overwrites the function in main. It is not a matter of accessibility.
Posted: Thu Oct 23, 2003 4:50 pm
by Lutz
yes, because the 'edit' symbol existed already in MAIN :(
I have changed this behaviour for the next development version (due this week). Now 'define' and 'constant' will always force a creation of a symbol local to the context, even if it already exists in MAIN.
Lutz