Author Topic: DCL codes within the same Lisp file  (Read 6636 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
DCL codes within the same Lisp file
« on: March 13, 2011, 02:06:43 PM »
Hello .

I wonder how to include a DCL codes within the same file of a lisp file to invoke them as tow in one . :-)

Any simple example ?

Thanks.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: DCL codes within the same Lisp file
« Reply #1 on: March 13, 2011, 02:50:35 PM »
Hi,

Here's a simple example :
Code: [Select]
;; ListBox (gile)
;; Dialog box to choose one or more in a list
;;
;; Arguments
;; title : the dialog title (string)
;; msg ; message (string), "" or nil for none
;; keylab : an dotted pairs list of type ((key1 . label1) (key2 . label2) ...)
;; flag : 0 = popup list
;;        1 = single choice list box
;;        2 = multipe choices list box
;;
;; Return value : the choosen key (flag = 0 or 1) or the list of choosen keys (flag = 2)
;;
;; Using example
;; (listbox "Layout" "Choose a layout" (mapcar 'cons (layoutlist) (layoutlist)) 1)

(defun ListBox (title msg keylab flag / tmp file dcl_id choice)
;; create and open a temporay file
  (setq tmp  (vl-filename-mktemp "tmp.dcl")
file (open tmp "w")
  )
;; write the file according to arguments
  (write-line
    (strcat "ListBox:dialog{label=\"" title "\";")
    file
  )
  (if (and msg (/= msg ""))
    (write-line (strcat ":text{label=\"" msg "\";}") file)
  )
  (write-line
    (cond
      ((= 0 flag) "spacer;:popup_list{key=\"lst\";")
      ((= 1 flag) "spacer;:list_box{key=\"lst\";")
      (T "spacer;:list_box{key=\"lst\";multiple_select=true;")
    )
    file
  )
  (write-line "}spacer;ok_cancel;}" file)
  (close file)

;; load the file and show the dialog
  (setq dcl_id (load_dialog tmp))
  (if (not (new_dialog "ListBox" dcl_id))
    (exit)
  )
  (start_list "lst")
  (mapcar 'add_list (mapcar 'cdr keylab))
  (end_list)
  (action_tile
    "accept"
    "(or (= (get_tile \"lst\") \"\")
    (if (= 2 flag) (progn
    (foreach n (str2lst (get_tile \"lst\") \" \")
    (setq choice (cons (nth (atoi n) (mapcar 'car keylab)) choice)))
    (setq choice (reverse choice)))
    (setq choice (nth (atoi (get_tile \"lst\")) (mapcar 'car keylab)))))
    (done_dialog)"
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete tmp)
  choice
)

a more complex (and powerful) example here.
Speaking English as a French Frog

Coder

  • Swamp Rat
  • Posts: 827
Re: DCL codes within the same Lisp file
« Reply #2 on: March 13, 2011, 03:09:07 PM »
Thanks .

I could not deal with it at all , may be some codes must be provided for the subroutine that included in the first line . :|

And I still feel that it is far form me to get and to invoke .

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: DCL codes within the same Lisp file
« Reply #3 on: March 13, 2011, 03:51:33 PM »
You do not need any subroutine to run the upper code, try the example in the header:
Code: [Select]
(listbox "Layout" "Choose a layout" (mapcar 'cons (layoutlist) (layoutlist)) 1)
Here's a more simple example:
Code: [Select]
(defun c:dialogTest (/ tmp file dcl_id name)

  ;; create and open a temporay file
  (setq tmp  (vl-filename-mktemp "tmp.dcl")
file (open tmp "w")
  )

  ;; write the DCL file
  (write-line
    "testDialog :dialog{
      label = \"Dialog Box Test\";
      initial_focus = \"name\";
      :text{
        label = \"Enter your name:\";
      }
      :edit_box{
        key = \"name\";
        width = 32;
        allow_accept = true;
      }
      :boxed_radio_column{
      label = \"Case\";
        key = \"case\";
        :radio_button{
          label = \"Uppercase\";
          key = \"up\";
          value = \"1\";
        }
        :radio_button{
          label = \"Lowercase\";
          key = \"low\";
        }
      }
      ok_cancel;
    }"
    file
  )

  ;; close the file
  (close file)

  ;; load and show the dialog
  (setq dcl_id (load_dialog tmp))
  (if (not (new_dialog "testDialog" dcl_id))
    (exit)
  )
  (action_tile
    "accept"
    "(setq name (get_tile \"name\"))
    (setq case (get_tile \"case\"))
    (done_dialog)")
  (start_dialog)
  (unload_dialog dcl_id)

  ;; delete the file
  (vl-file-delete tmp)

  ;; show the result
  (if name
    (progn
      (setq name (if (= case "up")
   (strcase name)
   (strcase name t)
)
      )
      (alert (strcat "Hello " name))
    )
    (alert "Cancel")
  )
  (princ)
)
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: DCL codes within the same Lisp file
« Reply #4 on: March 13, 2011, 03:54:55 PM »
Another example, similar to Gile's:

Code: [Select]
(defun PromptBox ( title msg / dcl dch file val )

  ;; ------------------------------------------- ;;
  ;; Arguments:-                                 ;;
  ;; ------------------------------------------- ;;
  ;; title - Dialog Box Title                    ;;
  ;; msg   - [Optional] Text to Display          ;;
  ;; ------------------------------------------- ;;
  ;; Returns:-                                   ;;
  ;; ------------------------------------------- ;;
  ;; Entered String if user presses OK, else nil ;;
  ;; ------------------------------------------- ;;
  ;; Example by Lee Mac 2010  -  www.lee-mac.com ;;
  ;; ------------------------------------------- ;;

  (cond
    (
      (not
        (and
          (setq dcl  (vl-filename-mktemp nil nil ".dcl"))
          (setq file (open dcl "w"))
          (progn
            (write-line
              (strcat
                "promptbox : dialog { label = \"" title "\"; initial_focus = \"txt\"; spacer;"
                ": edit_box { key = \"txt\"; edit_width = 60; edit_limit = 2048; allow_accept = true; } spacer; ok_cancel; }"
              )
              file
            )
            (setq file (close file))
            (findfile dcl)
          )
        )
      )
    )
    (
      (<= (setq dch (load_dialog dcl)) 0)

      (vl-file-delete dcl)
    )
    (
      (not (new_dialog "promptbox" dch))

      (unload_dialog dch)
      (vl-file-delete dcl)
    )
    (t
      (if msg (setq val (set_tile "txt" msg)))

      (action_tile "txt" "(setq val $value)")

      (if (zerop (start_dialog)) (setq val nil))

      (unload_dialog dch)
      (vl-file-delete dcl)
    )
  )

  val
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: DCL codes within the same Lisp file
« Reply #5 on: March 13, 2011, 03:58:00 PM »
Here's what I use for a ListBox - not quite as versatile as Gile's though...

Code: [Select]
;;-----------------------=={ List Box }==---------------------;;
;;                                                            ;;
;;  Displays a List Box allowing the user to make a selection ;;
;;  from the supplied data.                                   ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  title    - List Box Dialog title                          ;;
;;  data     - List of Strings to display in the List Box     ;;
;;  multiple - Boolean flag to determine whether the user     ;;
;;             may select multiple items (T=Allow Multiple)   ;;
;;------------------------------------------------------------;;
;;  Returns:  List of selected items, else nil.               ;;
;;------------------------------------------------------------;;

(defun LM:ListBox ( title data multiple / file tmp dch return )
  ;; © Lee Mac 2011
 
  (cond
    (
      (not
        (and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
          (write-line
            (strcat "listbox : dialog { label = \"" title
              "\"; spacer; : list_box { key = \"list\"; multiple_select = "
              (if multiple "true" "false") "; } spacer; ok_cancel;}"
            )
            file
          )
          (not (close file)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch)
        )
      )
    )
    (
      t     
      (start_list "list")
      (mapcar 'add_list data) (end_list)

      (setq return (set_tile "list" "0"))
      (action_tile "list" "(setq return $value)")

      (setq return
        (if (= 1 (start_dialog))
          (mapcar '(lambda ( x ) (nth x data)) (read (strcat "(" return ")")))
        )
      )         
    )
  )
 
  (if (< 0 dch) (unload_dialog dch))
  (if (setq tmp (findfile tmp)) (vl-file-delete tmp))

  return
)

Coder

  • Swamp Rat
  • Posts: 827
Re: DCL codes within the same Lisp file
« Reply #6 on: March 14, 2011, 03:08:33 AM »
Very nice , I liked these codes.  :-)

Thank you so much Gile and Lee Mac as well .

Highly appreciated.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: DCL codes within the same Lisp file
« Reply #7 on: March 14, 2011, 01:23:23 PM »
You're welcome Coder :-)

If you have any questions about the code posted, please do not hesitate to ask.  :-)

Coder

  • Swamp Rat
  • Posts: 827
Re: DCL codes within the same Lisp file
« Reply #8 on: March 14, 2011, 01:31:28 PM »
You're welcome Coder :-)

If you have any questions about the code posted, please do not hesitate to ask.  :-)

It's very kind of you to say that Lee.

Sure I will do .  :-)

Best regards.