Try to Fill GroupBox

Hi All,

immagine

    def OnRadiobuttonChange(self, sender, e):
        self.m_group.Content = self.m_slider
        self.Resizable = True

in the example image above, I have three objects, RadioButton, GoupBox, Button
at each click event on a different RadioButton, I would like to set the GoupBox to be filled with other pre-established objects. I had put a slider to try, but I find that the level is no longer adapted:

immagine

the button disappears.

in practice the shape does not automatically adjust:

immagine

no solution?

immagine immagine

I changed strategy, I wanted the form to automatically adapt to the new controls inserted inside the groupbox, but now I have set fixed measures for the form, while the groupbox updates its heights based on the various controls inserted.

Hi,
If you send some code and ask clearly what you would like to do I would love to help you.
Sadly the question is not very clear.
Farouk

Hi, @farouk.serragedine

I would like to add/remove controls in the Layout or in the Group-Box and at the same time that the Eto window adjusts to the new size, It would be possible?

I’ve seen some examples searching the forum,
like in this link:

but the window stays fixed, with the same size. . .

Hi @ 0904,
I’m not sure if increasing the form size is what you really should be doing, probably a listbox display or that sort would work better.

Anyway here’s an example on how to increase form size and hide/show form elements :

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

class MyDialog(forms.Dialog):
    def __init__(self):
        self.Title = "My Dialog"
        self.ClientSize = drawing.Size(200, 200)
        self.Padding = drawing.Padding(5)

        self.layout = forms.DynamicLayout()
        self.layout.DefaultSpacing = drawing.Size(5, 5)

        self.button1 = forms.Button()
        self.button1.Text = "Increase size"
        self.button1.Click += self.OnButton1Click

        self.button2 = forms.Button()
        self.button2.Text = "Hide Button 1"
        self.button2.Click += self.OnButton2Click

        self.groupbox = forms.GroupBox()
        self.groupbox.Text = "Labels"
        self.groupbox.Padding = drawing.Padding(5)
        self.groupbox.Content = forms.DynamicLayout()

        self.layout.Add(self.button1)
        self.layout.Add(self.button2)
        self.layout.Add(self.groupbox)

        self.Content = self.layout

    def OnButton1Click(self, sender, e):
        self.ClientSize += drawing.Size(0, 20)

    def OnButton2Click(self, sender, e):
        self.button1.Visible = False

dialog = MyDialog()
dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

@farouk.serragedine thanks for reply,

import Rhino as rh
import System as sy
import scriptcontext as sc

import Rhino.UI as ui
import Eto.Forms as frm
import Eto.Drawing as drw

class MyForms(frm.Dialog):
    def __init__(self):
        self.layout = frm.DynamicLayout()
        self.radio = frm.RadioButtonList()
        self.radio.DataStore = ['ADD', 'REM', 'DIS']
        self.group = frm.GroupBox(Text = "GB")
        self.label = frm.Label(Text = "Label")
        self.layoutgb = frm.DynamicLayout()
        self.layoutgb.AddRow(self.label)
        
        self.slider = frm.Slider()
        self.button = frm.Button(Text = "Button")
        
        self.radio.SelectedIndexChanged += self.OnRadiobuttonChange
        
        self.layout.AddRow(self.radio)
        self.layout.AddRow(self.group)
        self.layout.AddRow(self.slider)
        self.layout.AddRow(self.button)
        self.Content = self.layout
        
    def OnRadiobuttonChange(self, sender, e):
        if self.radio.SelectedKey == 'ADD': self.slider.Visible = True
        if self.radio.SelectedKey == 'REM': self.slider.Visible = False
        ### OR <alternative>
        #if self.radio.SelectedKey == 'ADD': self.group.Content = self.layoutgb
        #if self.radio.SelectedKey == 'REM': self.group.Content = None
        

def RunCommand():
    MyForms().ShowModal(ui.RhinoEtoApp.MainWindow)
RunCommand()

the layout should have as fixed controls, the radiobuttonlist at the top, while the button at the bottom. between these two controls there should be other controls to show and hide based on the selected radiobutton. (I was trying with self.layout.Remove(self.control) but maybe as you indicated self.control.visible is more suitable.)
as you can see by running the code i posted, when i hide a control, the height of the button increases, while what i would like to achieve is for the layout to decrease its size automatically. (always if possible)

alternatively I thought if the GroupBox adapts to the new dimensions, in your case it works, I think, because in the lower part there is no button, while in my case it is the button that resizes.

maybe this is how it works, the layout once all the objects are added, the size remains the same, but if some objects hide, the last check adjusts to the space that is left.

ps I noticed you use the Add method, unlike me using AddRow.

edit:
looking at your code, you have set the layout with the established dimensions, and then you go to increase the dimensions by clicking on the button. following this concept, taking the dimensions of the objects that I’m going to hide or show, I could resize the layout to my liking.

You could use a StackLayout instead of a DynamicLayout to solve the button issue

.....
class MyForms(frm.Dialog):
    def __init__(self):
        self.layout = frm.StackLayout()  #layout space will be shrinked instead of increasing the button size
        self.radio = frm.RadioButtonList()
        self.radio.DataStore = ['ADD', 'REM', 'DIS']
        self.group = frm.GroupBox(Text = "GB")
.....

I’ll try as you suggested right away, thanks :+1:

ps:
(question to the developers)
on reflection I think it shouldn’t work like this “my opinion” if on a control you use the visible property to False, the control as it happens shouldn’t be seen, but the next control shouldn’t take its place. because the control is hidden, but it should always occupy that space. for this I had not taken into consideration the visible property but I had concentrated on the Remove() method

Let me know if you encounter any more issues

import Rhino as rh
import System as sy
import scriptcontext as sc

import Rhino.UI as ui
import Eto.Forms as frm
import Eto.Drawing as drw

class MyForms(frm.Dialog):
    def __init__(self):
        self.layout = frm.StackLayout()
        self.radio = frm.RadioButtonList()
        self.radio.DataStore = ['ADD', 'REM', 'DIS']
        self.group = frm.GroupBox(Text = "GB")
        self.label = frm.Label(Text = "Label")
        self.layoutgb = frm.DynamicLayout()
        self.layoutgb.AddRow(self.label)
        
        self.slider = frm.Slider()
        self.button = frm.Button(Text = "Button")
        
        self.radio.SelectedIndexChanged += self.OnRadiobuttonChange
        
        self.layout.Items.Add(self.radio)
        self.layout.Items.Add(self.group)
        self.layout.Items.Add(self.slider)
        self.layout.Items.Add(self.button)
        self.Content = self.layout
        
    def OnRadiobuttonChange(self, sender, e):
        if self.radio.SelectedKey == 'ADD': self.slider.Visible = True
        if self.radio.SelectedKey == 'REM': self.slider.Visible = False
        ### OR <alternative>
        #if self.radio.SelectedKey == 'ADD': self.group.Content = self.layoutgb
        #if self.radio.SelectedKey == 'REM': self.group.Content = None
        

def RunCommand():
    MyForms().ShowModal(ui.RhinoEtoApp.MainWindow)
RunCommand()

I used StackLayout() instead of DynamicLayout() as you suggested and indeed the button scaling problem was avoided. this is already a step forward :+1:

self.layout.Items.Add(self.radio)

I don’t understand this: To get the code using StackLayout() to work I had to modify the Add() method, first passing by Items, but Items is a property of StackLayout() so I don’t understand how it works. . .

self.button = frm.StackLayout(frm.Button(Text = "Button"))

Anyway doing a test, I see that it also works like this: initially use DynamicLayout(), then only for the button also use StackLayout()