Author Topic: About $reason  (Read 13465 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
About $reason
« on: April 09, 2017, 05:08:16 AM »

Quoting from here :

Quote
$reason

The reason code that indicates which user action triggered the action. Used with edit_box, list_box, image_button, and slider tiles.

This variable indicates why the action occurred.
Its value is set for any kind of action, but you need to inspect it only when the action is associated with an edit_box, list_box, image_button, or slider tile.

And thats all...

But I'm actually wondering does anyone analysed this more carefully, so could give an example what is the $reason return, depending on the tile and the user's action, for example like:
- double click on an item from listbox
- multiple selection on items from listbox
- up/increase button from slider
- down/decrease button from slider
- ? ? ?

I just made up the above user actions from my head, that may cause the $reason usage - but certainly this isn't the complete list of user action possibilities.

Currently I did test only with 3 edit_boxes, and by shifting between them with TAB or using the LMB/RMB to access the edit_box tile I get returned a $reason value of 2.
I'm about to try the slider and listbox user action reasons - to see what integers are returned, depending on the actions I do, but first I wanted first to ask you guys here.

Also google did not help much about obtaining more info for that tile attribute.  :straight:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: About $reason
« Reply #1 on: April 09, 2017, 06:00:49 AM »

This has been on my bookshelves for better than 30 years.

Chapter 6 Page 289 has about 1 page on the $REASON variable.

https://www.amazon.com/Autocad-Professional-Api-Toolkit/dp/1562051628?SubscriptionId=179EQG3F3QRNWT8WS602&tag=Trove08-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=1562051628

http://trove.nla.gov.au/work/24445007?q&versionId=29512644

https://books.google.com.au/books?redir_esc=y&id=1Y1RAAAAMAAJ&focus=searchwithinvolume&q=%24REASON


1. The user selected the tile ....

2. The user exited an edit box without making a final selection ...

3.  The user has changed the value of a slider without making a final selection ...

4. The user double clicked on the tile ...


This book is well worth finding. The info has aged reasonably well.

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: About $reason
« Reply #2 on: April 09, 2017, 06:24:23 AM »
Also :

AutoCAD expert’s Visual LISP Volume 4 Advanced Programming Techniques Reinaldo N. Togores

Togores, Reinaldo N.. Advanced Programming Techniques (AutoCAD expert's Visual LISP Book 4) (Kindle Locations 2-4).  . Kindle Edition.

The complete series is an excellent  learning reference.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: About $reason
« Reply #3 on: April 09, 2017, 11:00:04 AM »
Hi,
From the books I got, the only additional info about $reason is:

Quote
Another item of information that you can supply is the reason why the callback function is
being called. The “$reason” keyword is substituted with an integer code. Most of the time, the
reason code has a value of 1, indicating a normal request. The meaning of a normal request
depends on the type of tile. An edit box returns code 1 when the Enter key has been pressed. Code
2 results if the operator moved to the next field with the Tab key or a pointing device. Code 3 is
associated with sliders and indicates a change in value without a final change setting. List boxes
may return code 4 if the operator double-clicks a selection, allowing your callback function to
react differently under that circumstance.

That is quoted from "Bill Kramer The AutoCADETs Guide to Visual LISP" book.
So it resembles with the information you shared:

1. The user selected the tile ....

2. The user exited an edit box without making a final selection ...

3.  The user has changed the value of a slider without making a final selection ...

4. The user double clicked on the tile ...

However, like I mentioned - I've decided to perform more detailed actual test and the results I have are:
Code: [Select]
$reason value - user's type of action

edit_box
1 - Enter
2 - LMB/RMB/TAB

button
1 - Always, LMB or ENTER

list_box
1 - single or multiple selection of items
4 - Double click on single item, or enter while its selected (does not work for multiple items)

popup_list
1 - Always

slider
1 - For pressing the end arrows or the actual slider (pressing them like buttons)
3 - For sliding the actual slider button

radio_button
1 - Always

toggle
1 - Always

edited: the problem was that I alerted the results.
So I was unable to reproduce $reason with value of 4. Heres the code I used:

Code - Auto/Visual Lisp: [Select]
  1. ; Learning about the callback function for (action_tile) :
  2.  
  3. (defun C:test ( / ReportActionCallback *error* dcl des dch dcf )
  4.  
  5.   (defun ReportActionCallback ( _key _label _value _data _reason _x _y )
  6.       '("k" "l" "v" "d" "r" "X" "Y")
  7.       (list
  8.         (strcat "Key: " (vl-prin1-to-string _key) ", type: " (vl-prin1-to-string (type _key)))          ; key of the tile
  9.         (strcat "Label: " (vl-prin1-to-string _label) ", type: " (vl-prin1-to-string (type _label)))    ; Theres no label attribute for the callback
  10.         (strcat "Value: " (vl-prin1-to-string _value) ", type: " (vl-prin1-to-string (type _value)))    ; value of the tile
  11.         (strcat "Data: " (vl-prin1-to-string _data) ", type: " (vl-prin1-to-string (type _data)))       ; what is data ?
  12.         (strcat "Reason: " (vl-prin1-to-string _reason) ", type: " (vl-prin1-to-string (type _reason))) ; what are reasons ?
  13.         (strcat "X: " (vl-prin1-to-string _x) ", type: " (vl-prin1-to-string (type _x)))                ; X coordinate where user clicked on the tile
  14.         (strcat "Y: " (vl-prin1-to-string _y) ", type: " (vl-prin1-to-string (type _y)))                ; Y coordinate where user clicked on the tile
  15.       ); list
  16.     ); mapcar
  17.   ); defun ReportActionCallback
  18.  
  19.   (defun *error* ( msg )
  20.     (and (< 0 dch) (unload_dialog dch))
  21.     (and (eq 'FILE (type des)) (close des))
  22.     (and (eq 'STR (type dcl)) (findfile dcl) (vl-file-delete dcl))
  23.     (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\nError: " msg)) ))
  24.     (princ)
  25.   ); defun *error*
  26.  
  27.   (cond
  28.     (
  29.       (not
  30.         (and (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w"))
  31.           (mapcar (function (lambda (x) (princ (strcat "\n" x) des)))
  32.             '("CallbackTest : dialog"
  33.               "{ label = \"Callback test\";"
  34.               "  : column"
  35.               "  { children_alignment = centered;"
  36.               "    : edit_box { label = \"Input1\"; key = \"eb1\"; width = 16; mnemonic = \"1\"; }"
  37.               "    : edit_box { label = \"Input2\"; key = \"eb2\"; width = 16; mnemonic = \"2\"; }"
  38.               "    : edit_box { label = \"Input3\"; key = \"eb3\"; width = 16; mnemonic = \"3\"; }"
  39.               "    : button { label = \"Button1\"; key = \"b1\"; width = 16; mnemonic = \"a\"; }"
  40.               "    : button { label = \"Button2\"; key = \"b2\"; width = 16; mnemonic = \"s\"; }"
  41.               "    : button { label = \"Button3\"; key = \"b3\"; width = 16; mnemonic = \"d\"; }"
  42.               "    : slider { key = \"sld\"; value = \"15\"; min_value = 0; max_value = 40; big_increment = 5; small_increment = 5; width = 16; }"
  43.               "    : popup_list { label = \"\"; key = \"PL\"; width = 16; }"
  44.               "    : list_box { label = \"Items\"; key = \"LB\"; width = 16; multiple_select = true; allow_accept = false; }"
  45.               "    : radio_column"
  46.               "    { label = \"Radio buttons\";"
  47.               "      : radio_button { label = \"B1\"; key = \"rb1\"; width = 16; }"
  48.               "      : radio_button { label = \"B2\"; key = \"rb2\"; width = 16; }"
  49.               "      : radio_button { label = \"B3\"; key = \"rb3\"; width = 16; }"
  50.               "    }"
  51.               "    : toggle { label = \"On/Off\"; key = \"tg1\"; width = 16; }"
  52.               "    : toggle { label = \"Switch\"; key = \"tg2\"; width = 16; }"
  53.               "  }"
  54.               "  spacer; ok_cancel; "
  55.               "  : text { label = \"\"; key = \"k\"; } "
  56.               "  : text { label = \"\"; key = \"l\"; } "
  57.               "  : text { label = \"\"; key = \"v\"; } "
  58.               "  : text { label = \"\"; key = \"d\"; } "
  59.               "  : text { label = \"\"; key = \"r\"; } "
  60.               "  : text { label = \"\"; key = \"X\"; } "
  61.               "  : text { label = \"\"; key = \"Y\"; } "
  62.               "}"
  63.             ); list
  64.           ); mapcar
  65.           (not (setq des (close des))) (< 0 (setq dch (load_dialog dcl)))
  66.         ); and
  67.       ); not
  68.       (princ "\nUnable to write or load the DCL file.")
  69.     )
  70.     ( (not (new_dialog "CallbackTest" dch)) (princ "\nUnable to display the dialog") )
  71.     (
  72.       (progn
  73.         (start_list "PL") (mapcar 'add_list (mapcar 'chr (vl-string->list "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))) (end_list)
  74.         (start_list "LB") (mapcar 'add_list (mapcar 'chr (vl-string->list "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))) (end_list)
  75.         (mapcar '(lambda (x) (action_tile x "(ReportActionCallback $key $label $value $data $reason $x $y)"))
  76.           '("eb1" "eb2" "eb3" "b1" "b2" "b3" "sld" "PL" "LB" "rb1" "rb2" "rb3" "tg1" "tg2")
  77.         ); mapcar
  78.         (action_tile "accept"
  79.           (vl-prin1-to-string
  80.             '(cond
  81.               ; ( (= "" (get_tile "eb1")) (set_tile "error" "Please fill input 1.") (mode_tile "eb1" 2) )
  82.               ; ( (= "" (get_tile "eb2")) (set_tile "error" "Please fill input 2.") (mode_tile "eb2" 2) )
  83.               ; ( (= "" (get_tile "eb3")) (set_tile "error" "Please fill input 3.") (mode_tile "eb3" 2) )
  84.               ( (done_dialog 1) )
  85.             ); cond
  86.           ); vl-prin1-to-string
  87.         ); action_tile
  88.         (/= 1 (setq dcf (start_dialog)))
  89.       ); progn
  90.       (princ "\nUser cancelled the dialog.")
  91.     )
  92.   ); cond
  93.   (*error* nil) (princ)
  94. ); defun

Thanks for the input, kdub!
Those books really look interesting, unfortunately I rely on the info from the forums.  :|

And another question popped up about what is $data tile attribute, but the thread I've created is about $reason, oh well.  :thinking:

EDIT: Code is modified.
« Last Edit: April 09, 2017, 11:25:24 AM by Grrr1337 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg


kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2120
  • class keyThumper<T>:ILazy<T>
Re: About $reason
« Reply #5 on: April 10, 2017, 12:47:17 AM »
Thanks Roy.
I sometimes forget that some if the older documentation is actually pretty good ... and still available.

Regards,
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: About $reason
« Reply #6 on: April 10, 2017, 07:03:38 AM »
Thanks, Roy!
That was exactly I was trying to understand. :)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg