Author Topic: Toggle on/off  (Read 2142 times)

0 Members and 1 Guest are viewing this topic.

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Toggle on/off
« on: April 04, 2016, 06:24:19 PM »
Hi, how are you:

Someone could give me an example of how I can create a toggle that when I check this with edit_box and activate a while to disable a popup_list when removing the check do the opposite.  :thinking:
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2145
  • class keyThumper<T>:ILazy<T>
Re: Toggle on/off
« Reply #1 on: April 04, 2016, 08:34:18 PM »

Perhaps Try something like this :

Code - Auto/Visual Lisp: [Select]
  1. // POPUP_LIST TOGGLE sample dialogue box
  2. poplist01 : dialog {
  3.   label = "Popup_list TOGGLE example";
  4.   :popup_list {
  5.     key = "choices";
  6.     label = "Choose one:";
  7.     edit_width = 20;
  8.   }
  9.  
  10.   :toggle {
  11.     key = "togglePopup";
  12.     label = "Popup &Active";
  13.     mnemonic = "A";
  14.   }
  15.   ok_only;
  16. }
  17.  
  18.  

Code - Auto/Visual Lisp: [Select]
  1. ;;Test dcl popup_list
  2. ;; codehimbelonga kdub@theSwamp 2016-04-05
  3. ;; Proof of concept code
  4.  
  5. (defun popuplist (/ choice data dcl_file)
  6.   ;; assume no errors , so no error trapping :)
  7.  
  8.   (setq dcl_file (load_dialog "poplist01"))
  9.  
  10.   (new_dialog "poplist01" dcl_file)
  11.   (setq data (list "Alpha" "Bravo" "Charlie" "Delta" "Echo" "Foxtrot"
  12.                    "Golf")
  13.   )
  14.   (start_list "choices")
  15.   (mapcar 'add_list data)
  16.  
  17.     "choices"
  18.     "(setq choice $value)")
  19.     "togglePopup"
  20.     "(mode_tile \"choices\"  (atoi $value))"
  21.   )
  22.   ;;--------------
  23.   (if choice
  24.     (alert (strcat "You chose # "
  25.                    choice
  26.                    " which refers\n"
  27.                    "to choice "
  28.                    (strcase (nth (atoi choice) data))
  29.                    "\nin the list of options."
  30.            )
  31.     )
  32.     (alert "Nothing selected.")
  33.   )
  34. )
  35.  
  36.  
  37. (defun c:doit ()
  38.   (popuplist)
  39. )
  40.  
  41.  
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: 2145
  • class keyThumper<T>:ILazy<T>
Re: Toggle on/off
« Reply #2 on: April 04, 2016, 08:36:11 PM »
Just a note :
Providing a solution would have been easier if you had posted some .lsp and .dcl code as a starter.

just saying :)
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.

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Toggle on/off
« Reply #3 on: April 05, 2016, 06:28:19 AM »
Here's another example, assuming I have correctly understood what you are looking for:

test.dcl
Code - DCL: [Select]
  1. test : dialog
  2. {
  3.     spacer;
  4.     : text
  5.     {
  6.         label = "Choose from list:";
  7.     }
  8.     : popup_list
  9.     {
  10.         key = "lst";
  11.     }
  12.     spacer;
  13.     : text
  14.     {
  15.         label = "Other, please specify: ";
  16.     }
  17.     : row
  18.     {
  19.         : toggle
  20.         {
  21.             key = "tog";
  22.         }
  23.         : edit_box
  24.         {
  25.             key = "str";
  26.             edit_width = 20;
  27.         }
  28.     }
  29.     spacer;
  30.     ok_cancel;
  31. }

test.lsp
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / dch dcl idx lst mod str )
  2.     (cond
  3.         (   (not (setq dcl (findfile "test.dcl")))
  4.             (princ "\nTest.dcl not found.")
  5.         )
  6.         (   (<= (setq dch (load_dialog dcl)) 0)
  7.             (princ "\nUnable to load DCL file.")
  8.         )
  9.         (   (not (new_dialog "test" dch))
  10.             (princ "\nUnable to display dialog.")
  11.         )
  12.         (   (setq lst '("Item 1" "Item 2" "Item 3" "Item 4" "Item 5")
  13.                   str  ""
  14.             )
  15.             (start_list "lst")
  16.             (foreach itm lst (add_list itm))
  17.             (end_list)
  18.             (set_tile  "lst" (setq idx "0"))
  19.             (mode_tile "str" 1)
  20.            
  21.             (action_tile "lst" "(setq idx $value)")
  22.             (action_tile "str" "(setq str $value)")
  23.             (action_tile "tog" "(setq mod (atoi $value)) (mode_tile \"lst\" mod) (mode_tile \"str\" (- 1 mod))")
  24.            
  25.             (if (= 1 (start_dialog))
  26.                 (if (= 1 mod)
  27.                     (princ (strcat "\nUser entered: \"" str "\"."))
  28.                     (princ (strcat "\nUser selected: \"" (nth (atoi idx) lst) "\"."))
  29.                 )
  30.                 (princ "\n*Cancel*")
  31.             )
  32.         )
  33.     )
  34.     (if (< 0 dch) (unload_dialog dch))
  35.     (princ)
  36. )

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Toggle on/off
« Reply #4 on: April 05, 2016, 12:13:48 PM »
I have the toggle and running but for some reason it is not saved the default I get an error

https://www.dropbox.com/sh/nzeyisvcy0pgn95/AADEUejcdwFIu7ChiRh_yxFra?dl=0
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2145
  • class keyThumper<T>:ILazy<T>
Re: Toggle on/off
« Reply #5 on: April 05, 2016, 09:13:02 PM »
I have the toggle and running but for some reason it is not saved the default I get an error

https://www.dropbox.com/sh/nzeyisvcy0pgn95/AADEUejcdwFIu7ChiRh_yxFra?dl=0

This does NOT describe the problem you have.
We are not mind readers and we don't all have spare time to comb through dropbox code looking for 'possible' errors.

Learn to be more descriptive with your issues.
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.

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Toggle on/off
« Reply #6 on: April 06, 2016, 11:26:53 AM »
Here's another example, assuming I have correctly understood what you are looking for:

test.dcl
Code - DCL: [Select]
  1. test : dialog
  2. {
  3.     spacer;
  4.     : text
  5.     {
  6.         label = "Choose from list:";
  7.     }
  8.     : popup_list
  9.     {
  10.         key = "lst";
  11.     }
  12.     spacer;
  13.     : text
  14.     {
  15.         label = "Other, please specify: ";
  16.     }
  17.     : row
  18.     {
  19.         : toggle
  20.         {
  21.             key = "tog";
  22.         }
  23.         : edit_box
  24.         {
  25.             key = "str";
  26.             edit_width = 20;
  27.         }
  28.     }
  29.     spacer;
  30.     ok_cancel;
  31. }

test.lsp
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / dch dcl idx lst mod str )
  2.     (cond
  3.         (   (not (setq dcl (findfile "test.dcl")))
  4.             (princ "\nTest.dcl not found.")
  5.         )
  6.         (   (<= (setq dch (load_dialog dcl)) 0)
  7.             (princ "\nUnable to load DCL file.")
  8.         )
  9.         (   (not (new_dialog "test" dch))
  10.             (princ "\nUnable to display dialog.")
  11.         )
  12.         (   (setq lst '("Item 1" "Item 2" "Item 3" "Item 4" "Item 5")
  13.                   str  ""
  14.             )
  15.             (start_list "lst")
  16.             (foreach itm lst (add_list itm))
  17.             (end_list)
  18.             (set_tile  "lst" (setq idx "0"))
  19.             (mode_tile "str" 1)
  20.            
  21.             (action_tile "lst" "(setq idx $value)")
  22.             (action_tile "str" "(setq str $value)")
  23.             (action_tile "tog" "(setq mod (atoi $value)) (mode_tile \"lst\" mod) (mode_tile \"str\" (- 1 mod))")
  24.            
  25.             (if (= 1 (start_dialog))
  26.                 (if (= 1 mod)
  27.                     (princ (strcat "\nUser entered: \"" str "\"."))
  28.                     (princ (strcat "\nUser selected: \"" (nth (atoi idx) lst) "\"."))
  29.                 )
  30.                 (princ "\n*Cancel*")
  31.             )
  32.         )
  33.     )
  34.     (if (< 0 dch) (unload_dialog dch))
  35.     (princ)
  36. )

Hello such thanks for your help I would like to know how can I make the default of toggle stay saved every time I use it again
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

Lee Mac

  • Seagull
  • Posts: 12921
  • London, England
Re: Toggle on/off
« Reply #7 on: April 06, 2016, 12:32:09 PM »
Store the value of the 'mod' variable (either as a global variable / write the value to a text file / store the value in the registry), and then test this stored value when displaying the dialog, configuring the tiles appropriately.

Currently the edit box will be disabled by default [(mode_tile "str" 1)].

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Toggle on/off
« Reply #8 on: April 06, 2016, 02:58:24 PM »
Hello, this is an excerpt from his NumInc.lisp code in which fits some things to keep me the default value of "key_tog1" my lisp but I get this message error: bad argument type: nil stringp

Code: [Select]
(setq *op* (cons key_tog1 "0"))
(set_tile "key_tog1" key_tog1)
((setq key_tog1_fun
 (lambda ( value )
 (if (eq "1" value)
   (progn (mode_tile "key_list_escala" 0) (mode_tile "key_escala1" 1))
   (progn (mode_tile "key_list_escala" 1) (mode_tile "key_escala1" 0))))) key_tog1)
 
  (action_tile "key_tog1" "(key_tog1_fun (setq key_tog1 $value))")
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>