明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 7813|回复: 25

[源码] 源码DCL通用函数再次修改版!

[复制链接]
发表于 2014-7-21 13:17:19 | 显示全部楼层 |阅读模式
本帖最后由 AbnerXk 于 2014-7-21 13:22 编辑

初版界面:

此函数原作者为:llsheng_73 在此感谢。

新版界面:
  1. (defun c:tt()
  2.   (setq lst '((" " ("xxx1 个人工具" "xxx2 个人工具" "xxx3 个人工具" "xxx4 个人工具" "xxx5 个人工具" "xxx6 个人工具"))))
  3.   (Dcl-ButtonM "xx工具" lst nil "帮助字符串")
  4. )
  5. ;; titl:标题; buttons:按钮列表; flag:nil先行后列T先列后行 helpstr: nil "帮助字符串"
  6. (defun Dcl-ButtonM (titl buttons flag helpstr / a b bq1 bq2 bqb c DivlstTh lsxth wh cmds csz ctl d dcl dclfile dclhandle divlst divth fileid i is_cancel kbnil key lst1 lsx n sk-cmdunknown sk-rctcmds str str_lst tem tems true tx v vr x y zbcd zhcfb)
  7. (or (and helpstr (/= helpstr "")) (setq helpstr "!!!死心吧,没写呢!!!"))
  8. (defun strsplist (str / i)
  9.   (if  (setq i (vl-string-search " " str))
  10.   (list (substr str 1 i)
  11.     (vl-string-trim " " (substr str (+ 2 i)))
  12.   )
  13.   )
  14. )
  15. (defun makedcl (str_lst / fileID dclHandle);临时生成对话框文件,用完需删除
  16.   (setq dclfile (vl-filename-mktemp nil nil ".dcl")
  17.     fileID(open dclfile "w")
  18.   )
  19.   (cond ((= (type str_lst) 'str) (write-line str_lst fileID))
  20.     ((= (type str_lst) 'list)
  21.    (foreach n str_lst (write-line n fileID))
  22.     )
  23.   )
  24.   (close fileID)
  25.   (setq dclHandle (load_dialog dclfile))
  26. )
  27.   (setq vr 0)

  28. (setq  b (if flag
  29.     ":column{ label = \""
  30.     ":row{children_alignment = top ;\n
  31.   children_fixed_height = true ;\n label = \""
  32.     )
  33.   c (if flag
  34.     ":row{children_alignment = top ;\n
  35.   children_fixed_height = true ;\nlabel = \""
  36.     ":column{label = \""
  37.     )
  38.   d '("ESC")
  39.   a (strcat (vl-string-translate
  40.       "$~"
  41.       "AB"
  42.       (vl-filename-base (vl-filename-mktemp))
  43.       )
  44.       ":dialog{label=\""
  45.       titl
  46.       "\";\n"
  47.       b
  48.       "\";\n"
  49.     )
  50. )
  51.   (setq kbnil '())
  52. (foreach x buttons
  53.   (setq lsx (last x))
  54.   (setq a (strcat a c (car x) "\";\n"))
  55.   (setq tem 0)
  56.   (setq csz 500)
  57.   (setq lsxth (length lsx))
  58.   (if (or (> lsxth 70) (= lsxth 70))
  59.     (setq wh 6)
  60.     (setq wh 5)
  61.   )
  62.   (setq divlst (Div-List lsx wh))
  63.   (setq zbcd (length (nth (- (length divlst) 1) divlst)))
  64.   (setq DivlstTh (length divlst))
  65.   (if (and (< zbcd wh) (/= zbcd wh))
  66.     (progn
  67.         (setq bq1 (- wh zbcd))
  68.       (repeat bq1
  69.             (setq tems (rtos tem))
  70.         (setq bqb (append (nth (- DivlstTh 1) divlst) (list (strcat "~" tems " "))))
  71.         (setq divlst (append (vl-remove (nth (- DivlstTh 1) divlst) divlst) (list bqb)))
  72.         (setq divth DivlstTh)
  73.         (setq tem (1+ tem))
  74.       )
  75.      )
  76.   )
  77.   (if (or (and (< divth 10) (/= divth 10) (/= divth nil)) (<= DivlstTh 10))
  78.     (progn
  79.         (setq bq2 (- 10 DivlstTh))
  80.       (repeat bq2
  81.         (repeat wh (setq kbnil (append kbnil (list (strcat "~" (rtos csz) " ")))) (setq csz (1+ csz)))
  82.       )
  83.     )
  84.   )
  85.     (setq zhcfb (Div-List kbnil wh))
  86.   (setq divlst (append divlst zhcfb))
  87.   (foreach v divlst
  88.     (setq a (strcat a ":row{\n"))
  89.   (foreach y v
  90.     (setq  b (strsplist y)
  91.       a (if b
  92.       (strcat a
  93.           ":button {key =\""
  94.           (car b)
  95.           "\";label=\""
  96.           (last b)
  97.           "\";"
  98.     (if (= (substr (car b) 1 1) "~")
  99.     "is_enabled = false ;" "\n")
  100.   "width = 15 ;"
  101.   "height = 2.5 ;"
  102.     "}\n"
  103.       )
  104.       (strcat a "spacer_0;\n")
  105.       )
  106.       d (if (/= (car b) nil)
  107.       (cons (car b) d)
  108.       d
  109.       )
  110.   )
  111.   )
  112.           ":button {key =\"" (car b) "\";label=\""
  113.   (setq a (strcat a "}\n"))
  114.   )
  115.   (setq a (strcat a "}\n"))

  116. );End foreach

  117. (setq  d  (cdr (REVERSE d))
  118.   a  (strcat a
  119.        (if flag
  120.        "} spacer_1;:row"
  121.        "} spacer_1;:row"
  122.        )
  123.        "{alignment = centered ;fixed_width = true ;
  124.         :button{fixed_width = true ;width = 4 ;height = 2 ;key = \"help\";label = \" 帮助 \";}\n"
  125.        ":button{fixed_width = true ;width = 4 ;height = 2 ;key=\"cancel\";label=\" 取消 \";
  126.        is_cancel = true;is_default = true;}}}"
  127.      )
  128.   dcl(makedcl a)
  129.   lst1 '()
  130.   i  1
  131. )
  132. (foreach key d
  133.   (setq tx (strcat "(action_tile \""
  134.        key
  135.        "\"\"(done_dialog "
  136.        (itoa i)
  137.        ")\")"
  138.      )
  139.     lst1 (cons tx lst1)
  140.     i  (1+ i)
  141.   )
  142. )
  143. (new_dialog (substr a 1 8) dcl)
  144. (action_tile "cancel" "(done_dialog 0)")
  145. (action_tile "help" "(alert helpstr)")
  146. (eval (read (strcat "(progn" (apply 'strcat lst1) ")")))
  147. (setq ctl (start_dialog))
  148. (unload_dialog dcl)
  149. (vl-file-delete dclfile)
  150. (if (/= ctl 0)
  151.   (progn
  152.   (setq cmds(nth (- ctl 1) d))
  153.   ;;检查命令是否~开头,有就去掉,如果运行中没有更改该命令button的enable值,这句可以不要
  154.   (if (= (substr cmds 1 1) "~") (setq cmds (substr cmds 2 (1- (strlen cmds)))))
  155.   ;;
  156. ;  ;设置未知命令反应器
  157. ;  (if (= sk-rctCmds nil)
  158. ;(setq sk-rctCmds (vlr-command-reactor nil '((:vlr-unknownCommand . sk-cmdunknown))))
  159. ;(vlr-add sk-rctCmds)
  160. ;)
  161.   ;新的命令判断方式,代码更短
  162.     (cond
  163.         ((boundp (read (strcat "c:" cmds)))
  164.           (princ "\n")
  165.           (eval (read (strcat "(c:" cmds ")")))
  166.         )
  167.         ((boundp (read cmds))
  168.           (princ "\n")
  169.           (eval (read (strcat "(" cmds ")")))
  170.         )
  171.         (t (princ "\n")(vl-load-com)(vl-cmdf cmds))
  172.     )
  173.   )
  174. )
  175. )

  176. ;;;拆分表
  177. (defun Div-List (lst num / ptn1 ptn2)

  178.   (while (> (length lst) num)

  179.     (repeat num

  180.       (setq ptn1 (cons (car lst) ptn1)

  181.       lst   (cdr lst)

  182.       )

  183.     )

  184.     (setq ptn2 (cons (reverse ptn1) ptn2)

  185.     ptn1 '()

  186.     )

  187.   )

  188.   (if (>= (length lst) 1)

  189.     (setq ptn2 (cons lst ptn2))

  190.   )

  191.   (reverse ptn2)

  192. )




此次修改只考虑了一个"column",因为我只会用到一个,如果有其他需求,请自行理清其中逻辑关系再修改;

自定义按钮将按行排列,数量在70个以下一行按钮数量为5个,超出则一行按钮为6个,如果按钮够多,可再增加判断;

集思广益,如有更好的想法,可一起讨论并继续完善。

取之于明,还之于明,函数下载:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 3明经币 +3 金钱 +10 收起 理由
zctao1966 + 1 下的人还真多
spp_wall + 1 + 10 赞一个!
lucas_3333 + 1 这种精神要学习!

查看全部评分

发表于 2018-10-1 11:08:02 | 显示全部楼层
不错  感谢分享
发表于 2018-10-3 12:12:23 | 显示全部楼层
谢谢楼主分享,学习中
发表于 2018-7-16 09:33:07 | 显示全部楼层
面板不错,值得借鉴
发表于 2014-7-21 14:59:55 | 显示全部楼层
谢谢LZ 共享  一直用老迈的!!!!
发表于 2014-7-22 08:27:16 | 显示全部楼层
谢谢分享。
发表于 2014-7-22 11:36:04 | 显示全部楼层
这是那个ODCL面板,还是DCL面板?好像ODCl面板!

 楼主| 发表于 2014-7-22 12:21:36 | 显示全部楼层
tianyi1230 发表于 2014-7-22 11:36
这是那个ODCL面板,还是DCL面板?好像ODCl面板!

这是DCL面板。
发表于 2014-7-22 14:53:51 | 显示全部楼层
好东西,谢谢分享。
发表于 2014-7-22 17:49:51 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2014-7-23 08:21:05 | 显示全部楼层
谢谢分享,看一下
发表于 2014-7-24 23:11:25 | 显示全部楼层
一直用老迈的对话框,这个也挺好
发表于 2014-7-26 09:08:27 | 显示全部楼层
谢谢楼主的无私奉献
(setq lst '((" " ("xxx1 个人工具" "xxx2 个人工具" "xxx3 个人工具" "xxx4 个人工具" "xxx5 个人工具" "xxx6 个人工具"))))
请教下,xxx1是要替换成对应LSP的快捷命令吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-19 04:52 , Processed in 0.185282 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表