Author Topic: Modify code to include DCL  (Read 1878 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Modify code to include DCL
« on: August 01, 2018, 08:37:45 AM »
Can anyone suggest how to modify this section of code to use dialogue box rather than the command line?
This DCL stuff is way beyond me. Thanks

Code: [Select]

(initget 5)
(setq n (getint "\nAdditional Layouts required: "))
(repeat (- n 0)
(command "._layout" "_N" "")
)


rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Modify code to include DCL
« Reply #1 on: August 01, 2018, 08:52:12 AM »
That code asks the user for an integer, then creates that many layouts.
Where is a dialog needed?
Just to prompt for the integer?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Modify code to include DCL
« Reply #2 on: August 01, 2018, 09:34:58 AM »
You could use a message box:  http://www.theswamp.org/index.php?topic=29537.0
I also found this old thread:http://www.theswamp.org/index.php?topic=31107.0  Another MessageBox utility by Keith
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.

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Modify code to include DCL
« Reply #3 on: August 01, 2018, 11:04:55 AM »
That code asks the user for an integer, then creates that many layouts.
Where is a dialog needed?
Just to prompt for the integer?

Like this. I can create the DCL file, just don't know how to incorporate into the code.

efernal

  • Bull Frog
  • Posts: 206
Re: Modify code to include DCL
« Reply #4 on: August 01, 2018, 11:40:18 AM »
(DEFUN foo (/ accept dh f_help my_path n w@)
  (IF (NULL (FINDFILE "foo_dcl.dcl"))
    (PROGN (SETQ my_path (STRCAT (SUBSTR (FINDFILE ".\\Icons") 1 (- (STRLEN (FINDFILE ".\\Icons")) 5)) "foo_dcl.dcl")
                 my_path (OPEN my_path "w")
           )
           (PRINC (STRCAT "my_foo:dialog{label=\"Add Layouts\";initial_focus=\"n\";"
                          ":edit_box{label=\"How many Layouts do you want do add?\";edit_width=10;key=\"n\";}ok_cancel;}"
                  )
                  my_path
           )
           (CLOSE my_path)
    )
  )
  (DEFUN accept ()
    (IF (AND (SETQ n (GET_TILE "n")) (> (ATOI n) 0) (< (ATOI n) 65))
      (PROGN (SETQ n (ATOI n)) (DONE_DIALOG 1))
      (ACET-UI-MESSAGE "Error:\n\n\n\tNeed an integer between 1 and 64" "Please, correct..." 16)
    )
  )
  (DEFUN f_help ()
    (ACET-UI-MESSAGE "How to use:\n\n\n\tWrite your help explanation here..." "My_help title" 32)
  )
  (IF (> (SETQ dh (LOAD_DIALOG "foo_dcl.dcl")) 0)
    (IF (NEW_DIALOG "my_foo" dh)
      (PROGN (ACTION_TILE "accept" "(accept)")
             (ACTION_TILE "cancel" "(DONE_DIALOG 0)")
             (ACTION_TILE "help" "(f_help)")
             (SETQ w@ (START_DIALOG))
             (UNLOAD_DIALOG dh)
             (COND ((= w@ 1) (REPEAT n (COMMAND "_.LAYOUT" "_N" "")))
                   (T (PRINC "\n-> Nothing to do..."))
             )
      )
    )
    (ACET-UI-MESSAGE "Error:\n\n\n\tNo dcl file loaded..." "Message" 16)
  )
  (PRINC)
)
(DEFUN c:nlayouts () (foo) (PRINC))

 ;|
(INITGET 5)
(SETQ n (GETINT "\nAdditional Layouts required: "))
(REPEAT (- n 0) (COMMAND "._layout" "_N" ""))
|;
e.fernal

efernal

  • Bull Frog
  • Posts: 206
Re: Modify code to include DCL
« Reply #5 on: August 01, 2018, 11:42:21 AM »
oops, use ok_cancel_help instead of ok_cancel
e.fernal

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Modify code to include DCL
« Reply #6 on: August 01, 2018, 02:11:41 PM »
Wow, that was more than I expected. Thank you...it works great. Could you tell me how to just hit enter rather than select the OK button? The focus seems to be on the button, but requires it to be selected.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Modify code to include DCL
« Reply #7 on: August 01, 2018, 02:56:59 PM »
Somewhat more generic - you want to be working with the "action" of the tile.  If you have a single-purpose DCL you can state it in the DCL file e.g.

action = "(setq count_var (atoi $value))";

Not necessary to use global variables for this, as long as you know what the variable name is.  The "$value" is the current value of the tile, which is always a string - you need to convert (and possibly test) it if you need to work on it as another data type.

If the dialog is more general purpose, or if you want more control over the action from your code, you can call the (action_tile ...) function.  This will do the same thing as above.  Mind the quoted strings, using escapes ( \ ) where needed.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Biscuits

  • Swamp Rat
  • Posts: 502
Re: Modify code to include DCL
« Reply #8 on: August 03, 2018, 08:54:30 AM »
Thanks for the help...works great. Couldn't get the focus to change, but I can live with that. Thanks again!