Understanding ETO Drawable

Hello,

I try several times to use ETO drawable, on simple examples without success… I am sure I am close… but…
My code need to open a windows, with drawable rectangles, that I input from a list…
Then in a layout I would like to see this rectangle.
I created a class for my Drawable graphics, then a Layout, and a function to iterate my rectangle… but something is wrong in my code…

Thanks a lot for any help or advices…


# coding: utf-8
import Rhino
import Eto
import rhinoscriptsyntax as rs
import Eto.Drawing as drawing
import Eto.Forms as forms

class WoodDrawable(forms.Drawable):
    def __init__(self, wood_name, color):
        super(WoodDrawable, self).__init__()
        self.wood_name = wood_name
        self.color = color
        self.Size = drawing.Size(100, 100)
        self.MouseDown += self.on_click

    def on_click(self, sender, e):
        self.Close(True)

    def OnPaint(self, sender, e):
        graphics = e.Graphics
        brush = drawing.SolidBrush(self.color)
        graphics.FillRectangle(brush, 0, 0, self.Width, self.Height)

class MainForm(forms.Dialog[bool]):
    def __init__(self):
        self.Title = "Wood selection"
        self.ClientSize = drawing.Size(200, 200)
        self.Resizable = True

        self.draw = Create_wood_drawable()
        self.draw.visible = True

# Create layout
        layout = forms.DynamicLayout()
        layout.Padding = drawing.Padding(10)
        layout.Spacing = drawing.Size(5, 5)

        layout.BeginVertical()
        layout.AddRow(self.Mytext())
# I want to view my rectangle inside my layout my object made from class WoodDrawable
        layout.AddRow(self.draw())
        layout.EndVertical()

        self.Content = layout

    def Mytext(self):
        self.label_titredessin = Eto.Forms.Label(Text = 'My DRAWABLE wood:')
        return

def Create_wood_drawable(wood, color):
    return WoodDrawable(wood, color)

    wood_types = [['maple', 'yellow'], ['redwood', 'red']]
    for wood, color in wood_types:
        wood_drawable = create_wood_drawable(wood, color)
        layout.AddRow(wood_drawable)
        self.Content = layout    

def RunDialog():
    dialog = MainForm()
    dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

if __name__ == "__main__":
    RunDialog()

Hey @antoine,

Did you ever resolve this?

– Dale

Hi Dale,
No unfortunately, Eto Drawable is strange to use for me , my goal was to manage easily from a future external .csv list a preset of datas, but with drawable I always have a problem of “arguments”
I know that Eto could offer an improvement in UserInterface but It stay “complicated” when I want to use Drawables (simple button are easy, lot of tutorials on simple Eto windows)

If you can provide me some help to understand the logic behind drawable… :slight_smile: