Jump to content

Error in dialog file


JuniorNogueira

Recommended Posts

 

Hello everyone,
I'm trying to learn AutoLISP and practicing in the program below, but it does not work, can someone tell me why?
and you more experienced, any suggestions for improvement?

(defun c:Senha (/ temp file)
  (setq temp (vl-filename-mktemp "Tmp.dcl")
	file (open temp "w")
	)
  (write-line
    (strcat
      "senha:dialog{"
      "label=\"Senha\";"
      "key=\"efernal\";"
      "initial_focus=\"senha\";"
      "width=40;""fixed_width=true;"
      ":spacer{height=0.5;}"
      ":text{"
      "label=\"Entre com a senha, por favor!\";"
      "alignment=centered;"
      "fixed_width=true;"
      "}"
      ":spacer{height=0.5;}"
      ":edit_box{"
      "key=\"senha\";""width=30;""edit_width=30;""edit_limit=25;"
      "alignment=centered;"
      "fixed_width=true;"
      "password_char=\"*\";"  
      "}"
      ":spacer{height=0.5;}"
      ":button{"
      "label=\"Prosseguir\";"
      "key=\"accept\";"
      "is_default=true;"
      "width=16;"
      "height=2.5;"
      "fixed_width=true;""fixed_height=true;""alignment=centered;"
      "}"":spacer{height=0.5;}"
      "}}"
      )
    file
    )
  (close file)
  (setq dcl_id (load_dialog temp))
  (if (not (new_dialog "senha" dcl_id))
    (exit)
    )
  (progn
    (action_tile "senha" "(setq senha $value)")
    (action_tile "accept" "(done_dialog)")
    (start_dialog) (unload_dialog dcl_id)
    (vl-file-delete temp)
    (cond
      ((= senha "Jk$#@sas");;;
       (alert "Senha correta!")
       )
      (t
       (alert "Senha invalida!")
       )
      )
    nil
    )
    (prompt "\nNot .dcl")(princ)
  )

 

Link to comment
Share on other sites

Hi, 

A good practice is to write the DCL code inside of the temporary file as multiple lines, then it would be easier to determine the error, so instead of 

(write-line (strcat "string1" "string2" ... "stringN") file)

Use:

(foreach line (list "string1" "string2" ... "stringN") 
	(write-line line file)
)

In your code it would look like:

(foreach line 
  '("senha : dialog"
    "{ label = \"Senha\"; key = \"efernal\"; initial_focus = \"senha\"; width = 40; fixed_width = true;"
    "  : spacer{ height = 0.5; }"
    "  : text"
    "  { label = \"Entre com a senha, por favor!\";"
    "    alignment = centered;"
    "    fixed_width = true;"
    "  }"
    "  : spacer { height=0.5; }"
    "  : edit_box"
    "  {"
    "    key = \"senha\";"
    "    width = 30;"
    "    edit_width = 30;"
    "    edit_limit = 25;"
    "    alignment = centered;"
    "    fixed_width = true;"
    "    password_char = \"*\";"
    "  }"
    "  : spacer { height=0.5; }"
    "  : button"
    "  {"
    "    label = \"Prosseguir\";"
    "    key = \"accept\";"
    "    is_default = true;"
    "    width = 16;"
    "    height = 2.5;"
    "    fixed_width = true;"
    "    fixed_height = true;"
    "    alignment = centered;"
    "  }"
    "  : spacer { height = 0.5; }"
    "}"
  ); list
  (write-line line file)
); foreach

 In your case, you had a redundant bracket on the right:

      "fixed_width=true;""fixed_height=true;""alignment=centered;"
      "}"":spacer{height=0.5;}"
      "}}" ; <<<<<--- This one
      )
    file
    )
  (close file)

You wouldn't have done this mistake if you used a proper indentation, so the "containers" that define the tile's properties could be distinct with a naked eye.

 


And suggestion for improvement.. well if you see yourself as a user, the obvious thing would be right after you type the password is to hit enter key, in order to attempt to login.

This can be done with checking the callback reason of the edit_box tile, so with:

(action_tile "senha" "(setq senha $value)(alert (vl-prin1-to-string $reason))")

When you type something and hit [ENTER] you w'll be alerted with a value of 1

 

Then lets make, when you hit enter within the edit_box, just to exit the dialog and continue checking our input:

(action_tile "senha" "(setq senha $value)(if (= 1 $reason) (done_dialog 1))")

 


Another thoughts.. (maybe you'll solve them, maybe someone will help you here)

What if the user accidentally invoked this command "Senha"" ? wouldn't you let him to cancel the dialog ?

In your case you'll force him to trigger an error in the program with ESC key, but then what would happen to the Tmp.dcl file ?

Would you check for an obviously wrong password like four spaces "    " or an empty string "" ?

🎅

  • Thanks 1
Link to comment
Share on other sites

17 hours ago, Grrr said:

Then lets make, when you hit enter within the edit_box, just to exit the dialog and continue checking our input:


(action_tile "senha" "(setq senha $value)(if (= 1 $reason) (done_dialog 1))")

 

Good explanations indeed Grrr. 

The following attribute could also be used in lieu of that if statement.

allow_accept = true;

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

How can I improve my subroutine?
We are intending to do for when we SIM to do something when we press Não other.

(defun JR:SIM_NAO (a b / dh w@)
  (setq temp (vl-filename-mktemp "Tmp.dcl")
	file (open temp "w"))
  (foreach line
	   '("simnao: dialog"
	     "{ label = \"Escola o que fazer\";fixed_width = true;"
	     "  spacer_1;"
	     "  : text"
	     "  {"
	     "    label =\"\";"
	     "    key = \"a\";"
	     "    width = 60;"
	     "    alignment = centered;"
	     "  }"
	     "  : text"
	     "  {"
	     "    label =\"\";"
	     "    key = \"b\";"
	     "    width = 60;"
	     "    alignment = centered;"
	     "  }"
	     "  spacer_1;"
	     "  : row"
	     "  { fixed_width = true;"
	     "    alignment = centered;"
	     "  : button"
	     "  {"
	     "    label = \"Não\";"
	     "    width = 12;"
	     "    key = \"cancel\";"
	     "    is_cancel = true;"
	     "  }"
	     "  : button"
	     "  {"
	     "    label = \"Sim\";"
	     "    width = 12;"
	     "    key = \"accept\";"
	     "    is_default = true;"
	     "  }"
	   "  }"
	 "  }"
	     
	     );;list
    (write-line line file)
    );foreach
  (close file)
  (setq dcl_id (load_dialog temp))
  (if (new_dialog "simnao" dcl_id)
    (progn
      (set_tile "a" a)
      (set_tile "b" b)
      (action_tile "accept" "(done_dialog 1)")
      (action_tile "cancel" "(done_dialog 0)")
      (setq w@ (start_dialog))
      (unload_dialog dh)
      (vl-file-delete temp)
      (setq simnao w@)
      )
    nil
    )
  (alert ".dcl not")
  )
(defun c:SE nil
  (JR:SIM_NAO
    "Dcl funcionando?"
....
  )

 

Link to comment
Share on other sites

1 hour ago, JuniorNogueira said:

Another thing, why does my DLC not close in (X)?

 

One tile will need to have the is_cancel = true attribute - the action associated with this tile will then be evaluated when the 'X' is clicked.

Link to comment
Share on other sites

As an example, consider the following:

(defun c:test ( / *error* dcl dch des )

    (defun *error* ( msg )
        (if (< 0 dch) (unload_dialog dch))
        (if (= 'file (type des)) (close des))
        (if (and (= 'str (type dcl)) (setq dcl (findfile dcl))) (vl-file-delete dcl))
        (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
    
    (if
        (and
            (setq dcl (vl-filename-mktemp nil nil ".dcl"))
            (setq des (open dcl "w"))
            (foreach str
               '(
                    "butt : button"
                    "{"
                    "    width = 15;"
                    "    height = 2;"
                    "    fixed_width = true;"
                    "    fixed_height = true;"
                    "    alignment = centered;"
                    "}"
                    "test : dialog"
                    "{"
                    "    label = \"Example 1\";"
                    "    spacer_1;"
                    "    : row"
                    "    {"
                    "        : butt { key = \"b1\"; label = \"Button 1\"; }"
                    "        : butt { key = \"b2\"; label = \"Button 2\"; }"
                    "        : butt { key = \"b3\"; label = \"Button 3\"; is_cancel = true; }"
                    "    }"
                    "    spacer;"
                    "    : butt"
                    "    {"
                    "        label = \"OK\";"
                    "        key = \"accept\";"
                    "        is_default = true;"
                    "    }"
                    "    spacer;"
                    "}"
                )
                (write-line str des)
            )
            (not (setq des (close des)))
            (< 0 (setq dch (load_dialog dcl)))
            (new_dialog "test" dch)
        )
        (progn
            (action_tile "b1" "(alert \"I am button 1.\")")
            (action_tile "b2" "(alert \"I am button 2.\")")
            (action_tile "b3" "(alert \"I am button 3.\nI am also cancel.\") (done_dialog 0)")
            (start_dialog)
        )
    )
    (*error* nil)
    (princ)
)

Observe that the action of clicking the red "x" in the corner of the window has the same effect as clicking "Button 3" since this tile has the is_cancel = true attribute.

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...