Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Eto: dynamically add and remove controls

$
0
0

@dick.lelyveld wrote:

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.

If so, can the added control be placed in a specific place in the layout? For example, between the first group and the button in the layout (see code below).

One other question: how do I get the ID of a control?

Here’s my basic code (also included as file). Any remarks are appreciated.

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

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

        # make the first group
        group = self.AddGroup()

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

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

        self.Content = layout

    def AddGroup(self):
        self.countGroups += 1
        print 'Groups: '+str(self.countGroups)

        group = forms.GroupBox(Text = 'Group', Padding = drawing.Padding(5))
        button = forms.Button(Text = 'Delete this group')
        button.Click += self.DeleteGroupButtonClick

        group.Content = button
        return group

    def DeleteGroup(self):
        self.countGroups -= 1
        print 'Groups: '+str(self.countGroups)

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

    def DeleteGroupButtonClick(self, sender, e):
        self.DeleteGroup()
    
def TestMyDialog():
    dialog = MyDialog()
    dialog.ShowModal()

if __name__ == "__main__":
    TestMyDialog()

add and delete controls in dialogs.py (1.4 KB)

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles