明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2700|回复: 8

[函数] 为应用程序数据提供一个简单的修改界面

[复制链接]
发表于 2015-5-5 09:53 | 显示全部楼层 |阅读模式
这是一个简单的表数据编辑器,用于编辑形如(("Width" . 10) ("Height" . 100.0) ("Extendedable" . "Yes"))的表
按确定返回修改后的表,按取消返回nil。

  1. (defun edit (lst / update-textbox update-list)
  2.   (defun update-textbox  (index)
  3.     (set_tile "value"
  4.         (vl-princ-to-string (cdr (nth (atoi index) lst)))
  5.     )
  6.   )

  7.   (defun update-list (value / index new old)
  8.     (setq index  (atoi (get_tile "name"))
  9.     old  (nth index lst)
  10.     )
  11.     (if  (/= (cdr old) value)
  12.       (progn
  13.   (setq new (strcat (car old) "\t" value))

  14.   (start_list "name" 1 index) ;_ 指定修改 index 位置上的数据
  15.   (add_list new)
  16.   (end_list)

  17.   (setq lst (subst (cons (car old) value) old lst))
  18.       )
  19.     )
  20.   )

  21.   (defun make-load-dcl (/ dclfile dlg file)
  22.     (setq dclfile (vl-filename-mktemp nil nil ".dcl")
  23.     file    (open dclfile "w")
  24.     )

  25.     (write-line
  26.       "PropertyEditForm:dialog{label=\"属性编辑\";
  27.       :row{:list_box{key=\"name\";height=25;width=50;tabs=25;}
  28.       :row{:edit_box{key=\"value\";width=30;}}}
  29.       ok_cancel;}"
  30.       file
  31.     )

  32.     (close file)
  33.     (setq dlg (load_dialog dclfile))
  34.     (vl-file-delete dclfile)
  35.     dlg
  36.   )

  37.   (new_dialog "PropertyEditForm" (make-load-dcl))
  38.   (start_list "name")
  39.   (mapcar
  40.     'add_list
  41.     (mapcar
  42.       '(lambda (e) (strcat (car e) "\t" (vl-princ-to-string (cdr e))))
  43.       lst
  44.     )
  45.   )
  46.   (end_list)

  47.   (action_tile "name" "(update-textbox $VALUE)")
  48.   (action_tile "value" "(update-list $VALUE)")
  49.   (if (= (start_dialog) 1)
  50.     lst
  51.   )
  52. )


_$ (edit '(("Width" . 10) ("Height" . 100.0) ("Extendedable" . "Yes")))

修改并确定后返回

(("Width" . "20") ("Height" . "2") ("Extendedable" . "NO"))

评分

参与人数 1明经币 +1 收起 理由
lucas_3333 + 1 赞一个!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下

本帖被以下淘专辑推荐:

发表于 2015-5-5 16:56 | 显示全部楼层
  1. ;;; 楼主为我们提供了一个很好的实用程序,我做了少少修改,楼主莫生气。
  2. ;;; 增加(mode_tile "value" 2),可减少鼠标动作,便于快速修改参数
  3. ;;; 返回值保证与原始参数的格式一致,按"取消"键时仍有返回,只是无修改
  4. ;;; 如有不妥之处,再次请求楼主见谅。
  5. ;;; 原作者:vectra; 修改: HLCAD(USER2128)
  6. (defun edit (Lst0 / Lst update-textbox update-list make-load-dcl)
  7.   (defun update-textbox (index)
  8.     (set_tile "value" (vl-princ-to-string (cdr (nth (atoi index) Lst))))
  9.     )
  10. ;;;
  11.   (defun update-list (value / index new old)
  12.     (setq index (atoi (get_tile "name"))
  13.           old   (nth index Lst)
  14.           )
  15.     (if (/= (cdr old) value)
  16.       (progn
  17.         (setq new (strcat (car old) "\t" value))
  18.         (start_list "name" 1 index) ;_指定修改 index 位置上的数据
  19.         (add_list new)
  20.         (end_list)
  21.         (setq Lst (subst (cons (car old) value) old Lst))
  22.         )
  23.       )
  24.     )
  25. ;;;
  26.   (defun make-load-dcl (/ dclfile dlg file)
  27.     (setq dclfile (vl-filename-mktemp nil nil ".dcl")
  28.           file    (open dclfile "w")
  29.           )
  30.     (write-line
  31.       "PropertyEditForm:dialog{label="属性编辑";
  32.       :column{
  33.         :list_box{key="name";height=15;width=50;tabs=25;}
  34.         :edit_box{key="value";width=30;}
  35.         }
  36.       ok_cancel;}"
  37.       file
  38.       )
  39.     (close file)
  40.     (setq dlg (load_dialog dclfile))
  41.     (vl-file-delete dclfile)
  42.     dlg
  43.     )
  44. ;;;
  45.   (setq Lst Lst0)
  46.   (new_dialog "PropertyEditForm" (make-load-dcl))
  47.   (start_list "name")
  48.   (mapcar
  49.     'add_list
  50.     (mapcar '(lambda(e) (strcat (car e) "\t" (vl-princ-to-string (cdr e)))) Lst)
  51.     )
  52.   (end_list)
  53. ;;;
  54.   (action_tile "name"  "(update-textbox $VALUE) (mode_tile "value" 2)")
  55.   (action_tile "value" "(update-list $VALUE)")
  56.   (if (= (start_dialog) 1)
  57.     (mapcar '(lambda(x / a b c)
  58.       (progn
  59.         (setq a (car x)
  60.               b (cdr x)
  61.               c (cdr (assoc a Lst))
  62.               )
  63.         (cond ((= (type b) 'INT)  (cons a (atoi c)))
  64.               ((= (type b) 'REAL) (cons a (atof c)))
  65.               (t (cons a c))
  66.               )
  67.         )) Lst0)
  68.     Lst0)
  69.   )

  70. ;_$ (edit '(("Width" . 10) ("Height" . 100.0) ("Extendedable" . "Yes")))
  71. ;修改并确定后返回
  72. ;(("Width" . 20) ("Height" . 2.0) ("Extendedable" . "NO"))
  73. ;按"取消"后返原值(("Width" . 10) ("Height" . 100.0) ("Extendedable" . "Yes"))

评分

参与人数 2明经币 +2 收起 理由
vectra + 1 抛砖引玉
lucas_3333 + 1 赞一个!

查看全部评分

发表于 2015-5-5 17:37 | 显示全部楼层
USER2128 发表于 2015-5-5 16:56

感谢俩位大师分享! 来一个成品如何?
发表于 2015-5-6 07:44 | 显示全部楼层
lucas_3333 发表于 2015-5-5 17:37
感谢俩位大师分享! 来一个成品如何?

这个程序早晚要用起来,今要出差几天,如有应用,将及时贴出。
谢谢你的奖励!
 楼主| 发表于 2015-5-6 08:12 | 显示全部楼层
我只是发了个非常简单的雏形,还有很大完善的空间,比如提供下拉列表选项,不同数据类型的编辑,帮助信息等。希望大家一起参与,更加完善。
发表于 2015-5-6 09:04 | 显示全部楼层
ctrl + 1  特性版工具栏里, 与此有何区别?
发表于 2015-8-20 15:44 | 显示全部楼层
USER2128 发表于 2015-5-6 07:44
这个程序早晚要用起来,今要出差几天,如有应用,将及时贴出。
谢谢你的奖励!

想看看成品
发表于 2015-8-21 07:28 来自手机 | 显示全部楼层
提点建议,如果要改首项呢,修改前是数字,修改后也应该是数字,缺少判断,列表框只显示名称,不知道值,需要点击才能显示,可不可以换种方式,名称和值都能出来,一目了然,数量多的时候比较明显,如果采用双列表呢,一个名称,一个值,点那边都能改。
发表于 2015-8-21 08:31 | 显示全部楼层
edata 发表于 2015-8-21 07:28
提点建议,如果要改首项呢,修改前是数字,修改后也应该是数字,缺少判断,列表框只显示名称,不知道值,需 ...

E大,好早啊, 支持提议, 也希望早日见到各位的成果

@vectra  , @USER2128
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-2 11:10 , Processed in 0.603829 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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