forked from mcneel/rhino-developer-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleGridViewDialog.py
69 lines (63 loc) · 2.08 KB
/
SampleGridViewDialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import System
import scriptcontext as sc
import Rhino.UI
import Eto
class SampleGridViewDialog(Rhino.UI.Forms.CommandDialog):
def __init__(self, doc):
self._doc = doc
self.Title = 'Layers'
self.Size = Eto.Drawing.Size(350, 350)
self.ShowHelpButton = False
self.Content = self.__create_layout()
def __create_layout(self):
# table
layout = Eto.Forms.TableLayout()
layout.Padding = Eto.Drawing.Padding(4)
layout.Spacing = Eto.Drawing.Size(4, 4)
# label
label = Eto.Forms.Label()
label.Text = 'Turns layers on or off:'
layout.Rows.Add(label)
# grid
grid = self.__create_grid()
row = Eto.Forms.TableRow(grid)
row.ScaleHeight = True
layout.Rows.Add(row)
return layout
def __create_grid(self):
# grid
grid = Eto.Forms.GridView()
grid.Size = Eto.Drawing.Size(300,400)
grid.ShowHeader = True
# column 0
col0 = Eto.Forms.GridColumn()
col0.HeaderText = 'Layer'
col0.DataCell = Eto.Forms.TextBoxCell(0)
col0.AutoSize = True
col0.Editable = False
grid.Columns.Add(col0)
# column `
col1 = Eto.Forms.GridColumn()
col1.HeaderText = 'Visible'
col1.DataCell = Eto.Forms.CheckBoxCell(1)
col1.AutoSize = True
col1.Editable = True
grid.Columns.Add(col1)
# datastore
self.__set_datastore(grid)
return grid
def __set_datastore(self, control):
names = []
visible = []
for layer in self._doc.Layers:
names.append(layer.Name)
visible.append(layer.IsVisible)
self._collection = [list(i) for i in zip(names, visible)]
control.DataStore = self._collection
def GetCollection(self):
return self._collection
if __name__ == '__main__':
dlg = SampleGridViewDialog(sc.doc)
dlg.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
if dlg.Result == Rhino.Commands.Result.Success:
print(dlg.GetCollection())