Dynamically add and remove controls

54 views
Skip to first unread message

Dicko

unread,
Dec 13, 2019, 8:04:30 AM12/13/19
to Eto.Forms
I use Eto in Rhinoceros in Python.

In this example the user should be able to add a new control by clicking a button.


I am able to add a control after initialization of the dialog (line 47), but when I click a button to add a control, it does not show (line 43).
As far as I can debug, I do create a new group and row, but adding it to the layout doesn’t work…


Here’s my basic code:


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


class Group(forms.GroupBox):


   
def __init__(self, count):
       
self.Padding = drawing.Padding(5)


        buttonRemoveGroup
= forms.Button(Text = 'Remove this group')
        buttonRemoveGroup
.Click += self.ButtonRemoveGroupClick


       
self.Content = buttonRemoveGroup


   
def ButtonRemoveGroupClick(self, sender, e):
       
self.Detach()


class MyDialog(forms.Dialog):


   
def __init__(self):
       
self.Title = 'Add and delete controls'
       
self.ClientSize = drawing.Size(300, 500)
       
self.Padding = drawing.Padding(10)
       
self.Resizable = False


       
self.countGroups = 0


       
self.buttonAddGroup = forms.Button(Text = 'Add group')
       
self.buttonAddGroup.Click += self.ButtonAddGroupClick


       
self.layout = forms.DynamicLayout()
       
self.layout.AddRow(self.buttonAddGroup)
       
self.layout.AddRow(None)


       
self.Content = self.layout


   
def AddGroup(self):
       
self.countGroups += 1
       
group = Group(self.countGroups)
       
self.layout.AddRow(group)
       
self.layout.AddRow(None)


   
def ButtonAddGroupClick(self, sender, e):
       
self.AddGroup()


def TestMyDialog():
    dialog
= MyDialog()
    dialog
.AddGroup()
    dialog
.ShowModal()


if __name__ == '__main__':
   
TestMyDialog()


Will Wang

unread,
Dec 14, 2019, 9:11:52 PM12/14/19
to Eto.Forms
I think you may have better luck asking on McNeel's discourse channel. Go to discourse.mcneel.com

Dicko

unread,
Dec 16, 2019, 2:44:30 AM12/16/19
to Eto.Forms
Thanks Will.
I already did, so I thought this is the last possibility :)

Op zondag 15 december 2019 03:11:52 UTC+1 schreef Will Wang:

Dicko

unread,
Dec 17, 2019, 4:16:20 AM12/17/19
to Eto.Forms
The solution: Create()

def AddGroup(self, msg):

   
self.countGroups += 1
   
group = Group(self.countGroups)
   
self.layout.AddRow(group)
   
self.layout.AddRow(None)

   
self.layout.Create()



Op maandag 16 december 2019 08:44:30 UTC+1 schreef Dicko:
Reply all
Reply to author
Forward
0 new messages