Custom UI Elements with Eto.Forms

Hi @antoine, I believe it’s because when you inherit from a .NET class in IronPython the constructor is derived before the derived class constructor. Thanks to @farouk.serragedine for helping me with that one back in October.

try something like this:

import Eto.Forms as forms
import Eto.Drawing as drawing

class WoodDrawable(forms.Drawable):
    @classmethod
    def create(cls, wood_name, color):
        instance = cls()
        instance.initalize(wood_name, color)
        return instance
    
    def on_click(self):
        """ click logic """
        pass
    
    def initalize(self, wood_name, color):
        self.wood_name = wood_name
        self.color = color
        self.Size = drawing.Size(100, 100)
        self.MouseDown += self.on_click

wood_types = [['maple', 'yellow'], ['redwood', 'red']]

if __name__ == "__main__":
    for wood, color in wood_types:
        wood_drawable = WoodDrawable.create(wood, color)
        #layout.AddRow(wood_drawable)
1 Like