Jump to content

Recommended Posts

Posted (edited)

Good afternoon and apologies if this is something simple I have missed.

 

 

I have a list box in a DCL dialogue box, and I want to create a button that selects all the items in the list. I found a solution that highlights all the list but doesn't appear to select them if that makes sense. Just wondering where I am going wrong.

 

 

Since I am copying parts of this from other sources and haven't yet credited them fully until I get this working, I am just going to post the relevant parts below if that's OK?

 

 

 

 

 

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Part of DCL File:

               "  : row { "
               "      : list_box { label = \"Select Tag(s)\"; key = \"tags\"; multiple_select = true; }" ;;List box populated elsewhere
               "        }"
               "  : row { "
               "        : button { key = \"ButSEL\"; label = \"Select All Tags\"; }" ;;Select All Button
               "        }"
;;.......
       (action_tile "tags" "(setq tagreturn $value)")
       (action_tile "ButSEL" "(c:SEL_ALL)") ;;When button ButSEL pressed run routine SEL_ALL below.
;;.......
       (setq tagreturn  ;;create tag list into tagreturn (I think)
         (if (= 1 (start_dialog))
           (mapcar '(lambda ( x ) (nth x l)) (read (strcat "(" tagreturn ")")))
         )
       )

   tagreturn
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;This Select all routine doesn't quite work. it highlights the list items but doesn't select them
(defun c:SEL_ALL ()
;;(set_tile "tags" "0 1 2 3 4 5 6") ;;simple only highlights the items, not selects them
 (setq acount 0)     ;;Use a loop
 (repeat 50       ;;How to count the length of the list and use here?
   (set_tile "tags" (itoa acount))  ;;Again only highlights the items and not selects them
   (setq account (acount + 1))
 )
)

 

 

 

 

 

 

 

 

(I have tried to wrap the above in the code tag but it doesn't want to work for me, any ideas why not?)

Edited by Steven P
To put in code tag
Posted

Hi,

 

What is the difference between highlights and selects items in your opinion?

Posted

Hi Tharwat,

 

 

Thanks for looking so far.

Yes, I wasn't very clear there.

 

 

'Highlights' - when I press the 'select all' button the items in the list box are all highlighted as if they have been selected, but when I press 'OK' on the DCL box nothing is passed to the next part of the routine - as if the items were only highlighted but not selected

 

 

'Selected' - say I use the keyboard or mouse to select and highlight the items in the list box, then press 'OK' the selected items are passed to the next part of the routine. Using the mouse / keyboard grabs the items for use later

 

 

Hope that makes sense?

Posted

Hi,

 

The list of items that you feed the list with must be assigned to a variable, so let's assume the name of the variable is 'lst'

FYI when you use get_tile on a list that the multiple_select is activated and the user highlight/selected more than one item, it would return for instance: "0 1"

So we need to wrap this string in a list in order to be able to retrieve the the same related item numbers from the variable 'lst' that has the items added to the list.

 

The following just an example for you to get the idea of retrieving values from a list attribute.

(action_tile "oki" "(if (setq rtn (get_tile \"tags\")) (mapcar '(lambda (x) (setq l (cons (nth x lst) l))) (read (strcat \"(\" rtn \")\")))) (done_dialog)")

 

Finally the variable 'l' should hold the selected items in the list "tags" and you need to use reverse function to get the items in order as they are in the variable 'lst'

 

Hope this is not too much. :) So just ask if you stuck with anything.

Posted

More details with examples:

 

Dcl:

"test : dialog { label = \"Tag list\"; fixed_width = true;
          : list_box { key = \"tags\"; height = 16; multiple_select = true;}
          : button { label = \"select all\"; key = \"ButSEL\";}
          : button { label = \"Okay\"; key = \"oki\"; is_default = true;}
          : button { label = \"Exit\"; key = \"esc\"; is_cancel = true;}}"

 

The last part of the program:

(defun highlight (len / i)
      (setq i -1)
      (repeat len
        (set_tile "tags" (itoa (setq i (1+ i))))
        )
      )
    (setq lst '("A" "B" "C" "D"))
    (start_list "tags") (mapcar 'add_list lst) (end_list)
    (action_tile "ButSEL" "(highlight (length lst))")
    (action_tile "oki" "(if (setq rtn (get_tile \"tags\")) (mapcar '(lambda (x) (setq l (cons (nth x lst) l))) (read (strcat \"(\" rtn \")\")))) (done_dialog)")
    (action_tile "esc" "(done_dialog)")

 

So the variable 'l' should have the return value(s) of the list with the key "tags" and you need to use the following codes to reorder the list as defined in 'lst' variable:

 

(reverse l)

Posted

Thanks SLW210 - Code tags added.

 

 

 

 

Tharwat, I can see how it should work... it just isn't at the moment, I'll work through it today and try to figure out what I have done wrong

Posted

Tharwat, I can see how it should work... it just isn't at the moment, I'll work through it today and try to figure out what I have done wrong

 

Let me know how you get on with it.

 

Good luck.

Posted

Hi,

 

 

Just a quick update - I couldn't get this to work on Friday, so near yet so far (I have some suspicions what I need to look at), but now I have a pile of drawings landed in front of me. I am going to put this to one side for now and work on it later

  • 3 weeks later...
Posted

Hi Tharwat, I am just catching up with everything. I got this working - took some messing around but I think I learnt a few things along the way, thanks

 

 

In the end I couldn't quite get your method to work (I think I know why though, probably I was mixing up variable names somewhere along the way)

 

 

To get it to work I changed the last function SEL_ALL to be:

 

 

(defun c:SEL_ALL (len) ;;len = length of tags list
 (setq tagreturn "") ;;tagreturn = positions in drop list of selected items
 (setq acount 0) ;;acount = a counter
 (repeat len
   (set_tile "tags" (itoa acount))
   (setq tagreturn (strcat (strcat tagreturn (itoa acount)) " "))
   (setq acount (1+ acount))
 )
)

 

 

 

 

Thanks again

Posted

Hi Tharwat, I am just catching up with a few things-and realised I hadn't said if I got this working or not. I didn't quite get your method to work, I think I was confusing variable names along the way somewhere. I ended upjust adding the line:

 

 

(setq tagreturn (strcat (strcat tagreturn (itoa acount)) " "))

 

 

to my last function SEL_ALL which is now:

(defun c:SEL_ALL(len) ;;len = length of tags list
 (setq tagreturn "") ;;tagreturn = positions in drop list of selected items
 (setq acount 0) ;;acount = a counter
 (repeat len
   (set_tile "tags" (itoa acount))
   (setq tagreturn (strcat (strcat tagreturn (itoa acount)) " "))
   (setq acount (1+ acount))
 )
)

 

 

 

 

 

 

Thanks again

Posted

Sorry - I duplicated this comment, tried to delete it but not so sure how

Posted

I duplicated this comment but not sure how to delete it

Posted

You are welcome Steven P.

 

Since you have the Sel_all as a sub-function, you should remove the c: which stands for a stand-alone command and I did a few mods on your sub-function if you are interested.

 

(defun sel_all (len / tagreturn acount)
 ;; len = length of tags list					;;
 ;; tagreturn = positions in drop list of selected items	;;
 ;; acount = a counter						;;
 (setq tagreturn ""
       acount 0
 )
 (repeat len
   (set_tile "tags" (itoa acount))
   (setq tagreturn (strcat tagreturn (itoa acount) " ")
         acount    (1+ acount)
   )
 )
)

Posted

Thanks, I didn't know you could do it that with setq to change several variables

 

 

Yup - your right about the c: I need to change that

Posted
I duplicated this comment but not sure how to delete it

Have a look below your post and you should see a button 'Edit Post' so hit this button and I am sure you'd be able to remove the unwanted post on your own.

 

Thanks, ....

 

Good luck.

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...