Console window in custom-application?

For the Compleat Fan
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Console window in custom-application?

Post 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!!
Hans-Peter

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

Post 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

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post 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?
Hans-Peter

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

Post 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

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post 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.
Hans-Peter

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

Post 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

Locked