@curtisw
Is it possible to dyamically add and delete controls with Eto?
I want the user to be able to add a new group by clicking a button.
EDIT: so I tried several things and it seems it is possible. But…, I am able to add a control after initialization of the dialog (line 48), but when I click a button to add a control, it does not show it (line 44).
As far as I can debug, I do create a new group (IronPython.NewTypes.Eto.Forms.GroupBox_1$1 (2)
) and a row (<Eto.Forms.DynamicRow object at 0x000000000000002C [Eto.Forms.DynamicRow]>
), but adding it to the layout doesn’t seem to work…
Here’s my basic code. Any remarks are appreciated.
import Eto.Drawing as drawing
import Eto.Forms as forms
class Group(forms.GroupBox):
def __init__(self, count):
self.Text = 'Group {}'.format(count)
self.Padding = drawing.Padding(5)
buttonDeleteGroup = forms.Button(Text = 'Delete this group')
buttonDeleteGroup.Click += self.ButtonDeleteGroupClick
self.Content = buttonDeleteGroup
def ButtonDeleteGroupClick(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
buttonAddGroup = forms.Button(Text = 'Add group')
buttonAddGroup.Click += self.ButtonAddGroupClick
self.layout = forms.DynamicLayout()
self.layout.AddRow(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()