Author Topic: DCL radiobutton alignment  (Read 21190 times)

0 Members and 1 Guest are viewing this topic.

ymg

  • Guest
Re: DCL radiobutton alignment
« Reply #30 on: January 04, 2014, 01:58:13 PM »
hmspe,

Could not run your routine as block "fault-CUAL.dwg" is missing.

ymg

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: DCL radiobutton alignment
« Reply #31 on: January 04, 2014, 03:05:38 PM »
One more:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tmplsp (/ choice)
  2.   (defun ClearCol(key)
  3.     (mapcar '(lambda(x) (set_tile x "0")) '("eb0""eb1""eb2""eb3""eb10""eb11""eb12""eb13"))
  4.     (set_tile key "1")
  5.     )
  6.   (if (not (setq dcl_id (load_dialog "testcluster.dcl")))
  7.     (progn  (alert "The file could not be loaded.") (exit))
  8.     (progn
  9.       (if (not (new_dialog "tcluster" dcl_id))
  10.         (alert "The DCL definition could not be found inside the DCL file.")
  11.        
  12.         (progn          
  13.           (action_tile "col0" "(setq choice $value)(clearCol $value)")
  14.           (action_tile "col1" "(setq choice $value)(clearCol $value)")
  15.           (action_tile "accept" "(done_dialog 2)")
  16.           (action_tile "cancel" "(done_dialog 1)")
  17.  
  18.           (setq ddiag (start_dialog))
  19.           (unload_dialog dcl_id)
  20.           (cond
  21.             ((= ddiag 1) (princ "\n \n ...DCL_LSP Cancelled. \n "))
  22.             ((/= ddiag 2)(princ "\n \n ...DCL_LSP Cancelled. \n "))
  23.             ((setq data (assoc choice
  24.                '(("eb0"  "0.56"   "Single Hung 1/2 in")
  25.                  ("eb1"  "1.79"   "Single Hung 3/4 in")
  26.                  ("eb2"  "2.67"   "Single Hung 1 in")
  27.                  ("eb3"  "4.24"   "Single Hung 1-1/2 in")
  28.                  ("eb10" "80.95"  "Single Hung 10 in")
  29.                  ("eb11" "105.53" "Single Hung 12 in")
  30.                  ("eb12" "120.62" "Single Hung 14 in")
  31.                  ("eb13" "147.54" "Single Hung 16 in")
  32.                  )))
  33.               (setq pl_utility (cadr data) pl_weight (caddr data))
  34.                )
  35.              )
  36.           (if data
  37.             (princ (strcat "\n You Selected: " pl_utility " , Weight: " pl_weight))
  38.             (princ "\nNo data on file.")
  39.           )
  40.  
  41.         )
  42.       )
  43.     )
  44.   )
  45.   (princ)
  46. )

Code: [Select]
tcluster : dialog { label = "2007 OPA - Mechancical Pipe - SCD 40  STD";     
  : row {
     : radio_column { key= "col0";
       : radio_button {key = "eb0"; label = "1/2 in";  }
       : radio_button {key = "eb1"; label = "3/4 in";  }
       : radio_button {key = "eb2"; label = "1 in";    }
       : radio_button {key = "eb3"; label = "1-1/2 in";}
       }
     : radio_column { key= "col1";
       : radio_button {key = "eb10"; label = "10 in";   }
       : radio_button {key = "eb11"; label = "12 in";   }
       : radio_button {key = "eb12"; label = "14 in";   }
       : radio_button {key = "eb13"; label = "16 in";   }
       }
  }
  :boxed_row { ok_cancel; }     
}
« Last Edit: January 04, 2014, 03:08:45 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: DCL radiobutton alignment
« Reply #32 on: January 04, 2014, 03:17:48 PM »
Very nice CAB, glad to see you used the "assoc" function to sort out the value for the appropriate radio button, that is my choice also...I have been getting comfortable with list and replacing "cond" statements with list functions where practical. 

Although I would have used nth 1 & nth 2 instead of cadr & caddr, just personal preference though.
« Last Edit: January 04, 2014, 03:22:50 PM by snownut2 »

ymg

  • Guest
Re: DCL radiobutton alignment
« Reply #33 on: January 04, 2014, 03:31:35 PM »
Agree assoc list is the way to go.

Yet another one for the clearing function.

Code: [Select]
(defun clrbut (k / b)
   (mapcar '(lambda(x) (if (setq b (get_tile x ))(set_tile b "0"))) (vl-remove k '("col0" "col1")))             

(action_tile "col0" "(setq choice $value)(clrbut $key)")
(action_tile "col1" "(setq choice $value)(clrbut $key)") 

This way we do not iterate through all the buttons, but simply reset the single button that is ON
in a given cluster.

ymg
« Last Edit: January 04, 2014, 04:24:05 PM by ymg »

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: DCL radiobutton alignment
« Reply #34 on: January 04, 2014, 04:22:14 PM »
Yet another one for the clearing function...

Or this, without clrbut
Code - Auto/Visual Lisp: [Select]
  1. (foreach x '("col0" "col1")
  2.   (action_tile x "(if (/= $value choice) (set_tile choice \"0\"))
  3.                  (setq choice $value)")
  4. )

ymg

  • Guest
Re: DCL radiobutton alignment
« Reply #35 on: January 04, 2014, 04:44:49 PM »
stefan,

Probably the most concise and clear one.

Quote
(foreach x '("col0" "col1")
   (action_tile x "(if (/= $value choice) (set_tile choice \"0\")) (setq choice $value)")
)

The clusters are defined in the foreach statement,
and there is no need for multple action_tile.

Maybe:
Code: [Select]
(action_tile x "(if choice (set_tile choice \"0\")) (setq choice $value)"))
Little clearer and concise.

ymg
« Last Edit: January 04, 2014, 05:26:11 PM by ymg »

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: DCL radiobutton alignment
« Reply #36 on: January 04, 2014, 06:11:26 PM »

Maybe:
Code: [Select]
(action_tile x "(if choice (set_tile choice \"0\")) (setq choice $value)"))
Little clearer and concise.

ymg
In this case, the button will be deselected if you click twice on it.
That's the reason I used (/= $value choice).

Anyway, I think the reason of using multiple columns of radio-buttons only in a dialog box is the size of dialog.
A good alternative is dosLib.
If the goal is to pick an item in a list, dos_popupmenu is the best choice.
If the list is huge enough to make it unreadable (using dosLib) then it is more uncomfortable to read it in a dialog box.
Code - Auto/Visual Lisp: [Select]
  1. (setq l '("1/2 in" "3/4 in" "1 in" "1-1/2 in" "10 in" "12 in" "14 in" "16 in"))
  2.   (setq x (dos_popupmenu l))
  3.   (nth x l)
  4.   )
  5.  

ymg

  • Guest
Re: DCL radiobutton alignment
« Reply #37 on: January 04, 2014, 06:16:57 PM »
Here's the final take hopefully!

Code - Auto/Visual Lisp: [Select]
  1. (defun c:testcluster (/ choice data dcl_id ddiag)      
  2.   (if (not (setq dcl_id (load_dialog "testcluster.dcl")))
  3.     (progn  (alert "The file could not be loaded.") (exit))
  4.   )
  5.   (if (not (new_dialog "tcluster" dcl_id))
  6.      (progn (alert "The DCL definition could not be found inside the DCL file.") (exit))
  7.   )      
  8.   (foreach x '("col0" "col1")
  9.      (action_tile x "(if choice (set_tile choice \"0\")) (setq choice $value)")
  10.   )
  11.   (action_tile "accept" "(done_dialog 1)")
  12.   (action_tile "cancel" "(done_dialog 0)")
  13.  
  14.   (setq ddiag (start_dialog))
  15.   (unload_dialog dcl_id)
  16.   (cond
  17.      ((= ddiag 0) (princ "\n \n ...DCL_LSP Cancelled. \n "              ))
  18.      ((not choice)(princ "\n \n ...No Selection. \n "                   ))
  19.      ((setq data (assoc choice '(("eb0"  "0.56"   "Single Hung 1/2 in"  )
  20.                                  ("eb1"  "1.79"   "Single Hung 3/4 in"  )
  21.                                  ("eb2"  "2.67"   "Single Hung 1 in"    )
  22.                                  ("eb3"  "4.24"   "Single Hung 1-1/2 in")
  23.                                  ("eb10" "80.95"  "Single Hung 10 in"   )
  24.                                  ("eb11" "105.53" "Single Hung 12 in"   )
  25.                                  ("eb12" "120.62" "Single Hung 14 in"   )
  26.                                  ("eb13" "147.54" "Single Hung 16 in"   ))
  27.                  )
  28.       )
  29.       (princ (strcat "\nYou Selected: " (caddr data) " , Weight: " (cadr data)))
  30.      )
  31.   )              
  32.   (princ)
  33. )
  34.  

Here is the DCL:

Code - Auto/Visual Lisp: [Select]
  1. tcluster : dialog { label = "2007 OPA - Mechancical Pipe - SCD 40  STD";      
  2.                    : row {
  3.                       : radio_column {
  4.                              key = "col0";
  5.                            
  6.                                 : radio_button {key = "eb0"; label = "1/2 in";  }
  7.                                 : radio_button {key = "eb1"; label = "3/4 in";  }
  8.                                 : radio_button {key = "eb2"; label = "1 in";    }
  9.                                 : radio_button {key = "eb3"; label = "1-1/2 in";}
  10.                         }
  11.                         : radio_column {
  12.                              key = "col1";
  13.                              
  14.                                 : radio_button {key = "eb10"; label = "10 in";   }
  15.                                 : radio_button {key = "eb11"; label = "12 in";   }
  16.                                 : radio_button {key = "eb12"; label = "14 in";   }
  17.                                 : radio_button {key = "eb13"; label = "16 in";   }
  18.                         }                              
  19.                    }
  20.                    :boxed_row {  ok_cancel; }    
  21.          }
  22.  

Not so bad for something designed by a committee  :laugh:

ymg
« Last Edit: January 04, 2014, 06:22:48 PM by ymg »

ymg

  • Guest
Re: DCL radiobutton alignment
« Reply #38 on: January 04, 2014, 06:35:58 PM »
stefan,

I agree with the Doslib thingie.

However the thread was mainly about having Radio Button Clusters in many rows or columns.

This is a recurring theme, and I see in various Forum peoples claiming that you don't need
any special Lisp to handle them.

Hope the issue is put to sleep,

WE DO NEED TO PROCESS THE CLUSTERS!

ymg

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: DCL radiobutton alignment
« Reply #39 on: January 04, 2014, 06:45:10 PM »
Or this, without clrbut
Code - Auto/Visual Lisp: [Select]
  1. (foreach x '("col0" "col1")
  2.   (action_tile x "(if (/= $value choice) (set_tile choice \"0\"))
  3.                  (setq choice $value)")
  4. )

Nicely done Stefan  :-)



Here's the final take hopefully!

This may be cleaner:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tcluster ( / dch itm )
  2.     (if (and (< 0 (setq dch (load_dialog "tcluster.dcl")))
  3.              (new_dialog "tcluster" dch)
  4.         )
  5.         (progn
  6.             (set_tile (cond (tcl:sel) ((setq tcl:sel "0"))) "1")
  7.             (foreach c '("c0" "c1")
  8.                 (action_tile c
  9.                     (vl-prin1-to-string
  10.                        '(if (/= $value tcl:sel)
  11.                             (progn (set_tile tcl:sel "0") (setq tcl:sel $value))
  12.                         )
  13.                     )
  14.                 )
  15.             )
  16.             (if (= 1 (start_dialog))
  17.                 (progn
  18.                     (setq itm
  19.                         (nth (atoi tcl:sel)
  20.                            '(
  21.                                 ("0.56"   "Single Hung 1/2 in"  )
  22.                                 ("1.79"   "Single Hung 3/4 in"  )
  23.                                 ("2.67"   "Single Hung 1 in"    )
  24.                                 ("4.24"   "Single Hung 1-1/2 in")
  25.                                 ("80.95"  "Single Hung 10 in"   )
  26.                                 ("105.53" "Single Hung 12 in"   )
  27.                                 ("120.62" "Single Hung 14 in"   )
  28.                                 ("147.54" "Single Hung 16 in"   )
  29.                             )
  30.                         )
  31.                     )
  32.                     (princ (strcat "\nYou selected: " (cadr itm) ", weight: " (car itm)))
  33.                 )
  34.             )
  35.         )
  36.     )
  37.     (if (< 0 dch) (unload_dialog dch))
  38.     (princ)
  39. )

Save the following as tcluster.dcl:
Code - DCL: [Select]
  1. tcluster : dialog
  2. {
  3.     spacer; label = "Test Cluster";
  4.     : row
  5.     {
  6.         fixed_width = true;
  7.         alignment = centered;
  8.         : radio_column
  9.         {
  10.             key= "c0";
  11.             : radio_button { key = "0"; label = "1/2 in";  }
  12.             : radio_button { key = "1"; label = "3/4 in";  }
  13.             : radio_button { key = "2"; label = "1 in";    }
  14.             : radio_button { key = "3"; label = "1-1/2 in";}
  15.         }
  16.         : radio_column
  17.         {
  18.             key= "c1";
  19.             fixed_width = true;
  20.             : radio_button { key = "4"; label = "10 in"; }
  21.             : radio_button { key = "5"; label = "12 in"; }
  22.             : radio_button { key = "6"; label = "14 in"; }
  23.             : radio_button { key = "7"; label = "16 in"; }
  24.         }
  25.     }
  26.     spacer; ok_cancel;
  27. }

I don't like to use (exit) or (quit) in code if I can avoid it - also, as far as I know load_dialog doesn't return nil, only a negative or zero value on failure.

The action_tile statements for the accept & cancel tiles are redundant since these are predefined.

The above code will also remember the last selection since tcl:sel is global.

ymg

  • Guest
Re: DCL radiobutton alignment
« Reply #40 on: January 04, 2014, 08:50:24 PM »
Lee,

Didn't know about tcl:sel, so I learned something.

Don't much like doing the processing with the dialog ON,
so I prefer (exit).

I would get rid of the progn and move the printing of results outside.

Code - Auto/Visual Lisp: [Select]
  1. (if (= 1 (start_dialog))
  2.                   (setq itm
  3.                        (nth (atoi tcl:sel)
  4.                            '(("0.56"   "Single Hung 1/2 in"  )
  5.                              ("1.79"   "Single Hung 3/4 in"  )
  6.                              ("2.67"   "Single Hung 1 in"    )
  7.                              ("4.24"   "Single Hung 1-1/2 in")
  8.                              ("80.95"  "Single Hung 10 in"   )
  9.                              ("105.53" "Single Hung 12 in"   )
  10.                              ("120.62" "Single Hung 14 in"   )
  11.                              ("147.54" "Single Hung 16 in"   ))
  12.                        )
  13.                   )                
  14.             )
  15.         )
  16.     )
  17.     (if (< 0 dch) (unload_dialog dch))  
  18.     (if itm (princ (strcat "\nYou selected: " (cadr itm) ", weight: " (car itm))))
  19.     (princ)
  20. )
  21.  

But it is all a matter of style.

ymg
« Last Edit: January 04, 2014, 08:55:31 PM by ymg »

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: DCL radiobutton alignment
« Reply #41 on: January 05, 2014, 05:15:25 AM »
Don't much like doing the processing with the dialog ON, so I prefer (exit).

What processing?

The programs operate in much the same way, with the evaluation ceasing if the criteria for the dialog loading successfully is not met. Only, at this point, your code will force an error using (exit), whereas my code will exit cleanly without error - I see no argument for using (exit).

I would get rid of the progn and move the printing of results outside.

Why? I see no reason to do this - on the contrary, this adds redundancy to the code as there is no need to test whether itm is defined if the princ expression is included within the 'then' argument for the if function.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: DCL radiobutton alignment
« Reply #42 on: January 05, 2014, 07:26:37 AM »
Ditto, I haven't used EXIT in years.  :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: DCL radiobutton alignment
« Reply #43 on: January 05, 2014, 07:37:01 AM »
ymg,

How do you build calculator type DCL's if you can not process while DCL is active ? (or nested drop down selection sets)

hmspe

  • Bull Frog
  • Posts: 362
Re: DCL radiobutton alignment
« Reply #44 on: January 05, 2014, 09:14:16 AM »
hmspe,

Could not run your routine as block "fault-CUAL.dwg" is missing.

ymg

My error.  The file is attached. 



"Science is the belief in the ignorance of experts." - Richard Feynman