-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy pathSampleEtoColorDropDown.py
87 lines (73 loc) · 3.57 KB
/
SampleEtoColorDropDown.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
################################################################################
# SampleEtoColorDropDown.py
# Copyright (c) 2020 Robert McNeel & Associates.
# See License.md in the root of this repository for details.
################################################################################
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
################################################################################
# SampleEtoColorDropDown class
################################################################################
class SampleEtoColorDropDown(forms.DropDown):
def __init__(self, colors):
for c in colors:
self.Items.Add(self.CreateItem(c.ToArgb(), c.Name))
def CreateItem(self, argb, text):
item = forms.ImageListItem()
item.Text = text
size = drawing.Size(20, 14) * int(forms.Screen.PrimaryScreen.LogicalPixelSize)
bitmap = drawing.Bitmap(size, drawing.PixelFormat.Format32bppRgb)
with drawing.Graphics(bitmap) as g:
g.Clear(drawing.Color.FromArgb(argb))
item.Image = bitmap
return item
################################################################################
# SampleEtoColorDropDownDialog dialog
################################################################################
class SampleEtoColorDropDownDialog(forms.Dialog):
def __init__(self, colors):
self.Title = "Sample Color Dropdown Dialog"
self.ClientSize = drawing.Size(400, 200)
self.Padding = drawing.Padding(5)
self.Resizable = False
self.m_dropdown = SampleEtoColorDropDown(colors)
self.m_dropdown.SelectedIndex = 0
self.m_dropdown.SelectedIndexChanged += self.OnSelectedIndexChanged
self.m_label = forms.Label()
self.m_label.Text = self.m_dropdown.Items[0].Text
layout = forms.DynamicLayout()
layout.Padding = drawing.Padding(10)
layout.Spacing = drawing.Size(5, 5)
layout.AddRow("Name:", self.m_label, None)
layout.AddRow("Color:", self.m_dropdown, None)
layout.Add(None, None, True)
self.Content = layout
def OnSelectedIndexChanged(self, sender, e):
idx = self.m_dropdown.SelectedIndex
self.m_label.Text = self.m_dropdown.Items[idx].Text
msg = "DropDown.SelectedIndexChanged, Value: {0}".format(idx)
print(msg)
################################################################################
# Function to test the dialog
################################################################################
def TestSampleEtoColorDropDownDialog():
colors = []
colors.append(System.Drawing.Color.Black)
colors.append(System.Drawing.Color.White)
colors.append(System.Drawing.Color.Red)
colors.append(System.Drawing.Color.Yellow)
colors.append(System.Drawing.Color.Green)
colors.append(System.Drawing.Color.Cyan)
colors.append(System.Drawing.Color.Blue)
colors.append(System.Drawing.Color.Magenta)
dialog = SampleEtoColorDropDownDialog(colors);
rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
################################################################################
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
################################################################################
if __name__ == "__main__":
TestSampleEtoColorDropDownDialog()