# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs
import Rhino.UI
import System.Drawing as Drawing
import System.Windows.Forms as Forms
def create_checkbox_window(checkbox_list, title, message):
# 计算窗口高度
height = 60 + len(checkbox_list) // 2 * 30
# 创建窗口
form = Forms.Form()
form.Text = title
form.FormBorderStyle = Forms.FormBorderStyle.FixedDialog
form.MaximizeBox = False
form.StartPosition = Forms.FormStartPosition.CenterParent
form.ClientSize = Drawing.Size(300, height)
form.KeyPreview = True
form.KeyDown += lambda sender, e: e.KeyCode == Forms.Keys.Escape and form.Close()
# 添加提示信息
label_message = Forms.Label()
label_message.Text = message
label_message.AutoSize = True
label_message.Location = Drawing.Point(20, 20)
form.Controls.Add(label_message)
# 添加复选框
for i, checkbox in enumerate(checkbox_list):
row = i // 2
col = i % 2
check_box = Forms.CheckBox()
check_box.Text = checkbox[0]
check_box.Checked = checkbox[1]
check_box.AutoSize = True
check_box.Location = Drawing.Point(20 + col * 150, 50 + row * 30)
form.Controls.Add(check_box)
# 添加确定和取消按钮
button_ok = Forms.Button()
button_ok.Text = "确定"
button_ok.DialogResult = Forms.DialogResult.OK
button_ok.Location = Drawing.Point(100, height - 70)
form.AcceptButton = button_ok
form.Controls.Add(button_ok)
button_cancel = Forms.Button()
button_cancel.Text = "取消"
button_cancel.DialogResult = Forms.DialogResult.Cancel
button_cancel.Location = Drawing.Point(200, height - 70)
form.CancelButton = button_cancel
form.Controls.Add(button_cancel)
# 显示窗口
result = form.ShowDialog(Rhino.UI.RhinoEtoApp.MainWindow)
# 返回结果
if result == Forms.DialogResult.OK:
return [[checkbox.Text, checkbox.Checked] for checkbox in form.Controls if isinstance(checkbox, Forms.CheckBox)]
else:
return None