if it is possible - how to add EtoPanel from custom GH component? RegisterPanel is asking for a Plugin. What should be used in this case?
Any small example of registering and showing Panel from GH comp is highly appreciated.
I don’t think this is the best way, but here is something I tried a while back. connect a button component to the x input of your ghpy component. This code will show a grid of running windows processes. (Windows only, won’t work on mac). From GH, I couldn’t get it to be modeless, but maybe this helps?
some more discussion here.
some samples here are certainly a better reference:
import Eto.Forms as forms
import Eto.Drawing as drawing
import Rhino.UI
from System.Diagnostics import Process
from operator import itemgetter
from System.Windows.Forms import MessageBox
Names = []
Ids = []
SessIds = []
Memory = []
COUNT = 0
#get some data to use in the grid, could be anything
def GetProcs():
procs = Process.GetProcesses()
for p in procs:
Names.append(p.ProcessName)
Ids.append(p.Id)
SessIds.append(p.SessionId)
Memory.append(int(p.WorkingSet / 1024))
#make an incrementer function to use for tracking clicks. (c
def Increment():
global COUNT
COUNT = COUNT+1
return COUNT
class ServicesDialog(forms.Dialog):
def __init__(self):
self.Title = "Running Services"
self.Size = drawing.Size(375,565)
self.Resizable = True
self.grid = forms.GridView()
self.grid.Size = drawing.Size(300,400)
self.grid.AllowColumnReordering = True
self.grid.CellFormatting += self.OnCellFormatting
#attach event handler to ColumnHeaderClick event
self.grid.ColumnHeaderClick += self.OnColumnHeaderClick
#COLUMNS
serviceColumn = forms.GridColumn()
serviceColumn.HeaderText = "Service\t"
serviceColumn.DataCell = forms.TextBoxCell(0)
serviceColumn.Sortable = True
idsColumn = forms.GridColumn()
idsColumn.HeaderText = "PID\t"
idsColumn.DataCell = forms.TextBoxCell(1)
idsColumn.Sortable = True
memoryColumn = forms.GridColumn()
memoryColumn.HeaderText = "Memory\t K \t"
memoryColumn.DataCell = forms.TextBoxCell(2)
memoryColumn.Sortable = True
self.grid.Columns.Add(serviceColumn)
self.grid.Columns.Add(idsColumn)
self.grid.Columns.Add(memoryColumn)
#format data for grid with list comprehension, (list(i) makes it a nested list, could also use "i for i"
GridData = [list(i) for i in zip(Names, Ids, Memory)]
#using python function to sort based on key(columnHeading)
#the first column's data type is a string with upper and lower case first letters, let's sort by name first/default
GridData2 = sorted(GridData, key=lambda x:x[0].lower())
self.grid.DataStore = GridData2
#instantiate the layout, let the dynamic layout create the rows for all the data in the grid, bind conent to layout
layout = forms.DynamicLayout()
layout.AddRow(self.grid)
self.Content = layout
#some cell formatting
def OnCellFormatting(self, sender, e):
#set the text color
e.ForegroundColor = drawing.Colors.Black
#color rows with alternating colors
if e.Row % 2 == 0:
e.BackgroundColor = drawing.Colors.White
else:
e.BackgroundColor = drawing.Colors.LightGrey
#create event Handler for column header click
def OnColumnHeaderClick(self, sender, e):
GridData = [list(i) for i in zip(Names, Ids, Memory)]
Increment()
try:
#get the column heading that was clicked
sortItem = self.grid.Columns.IndexOf(e.Column)
sort = COUNT % 2
#if the Name column is clicked, we need to make sure it sorts properly. (names that start with upper case vs lower case).
if sortItem == 0:
GridData2 = sorted(GridData, key=lambda x:x[0].lower(), reverse=sort)
#else it's any other column, (numbers), sort it
else:
GridData2 = sorted(GridData, key=itemgetter(sortItem), reverse=sort)
self.grid.DataStore = GridData2
except:
pass
def main():
GetProcs()
dialog = ServicesDialog()
dialog.Location = drawing.Point(115, 200)
dialog.ShowModal()
if x:
main()
Thank you, @chanley.
But I see you are adding window, not the panel.
I have seen @dale 's example here: Examples but panel here requires compiled Plugin.