ETO TabControl Click event not registering

Hi all, I am trying to use a nonmodal dialog with tabcontrols in cpython Rhino 8. So far so good, but I would like tot use the forms.TabPage Click event.

For some reason the event it is not registering and firing when I click the TabPage. The same code works in the ironpython so what am I doing wrong?

#! python3

################################################################################
# SampleEtoDialog.py
# MIT License - Copyright (c) 2017 Robert McNeel & Associates.
# See License.md in the root of this repository for details.
################################################################################
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs


################################################################################
# Sample dialog
################################################################################

class ModelessDlg(forms.Form):
    def __init__(self):
        super().__init__()

        self.Title = "Sample Eto Dialog"
        self.ClientSize = drawing.Size(400, 400)
        self.Padding = drawing.Padding(5)
        self.Resizable = True

        # Create a tabcontrol for controlling all tabs
        tabcontrol = forms.TabControl()
        tabcontrol.Pages.Add(TemplateTabClass())
        tabcontrol.Pages.Add(TemplateTabClass())

        # Tab cotrol colletion
        tab_items = forms.StackLayoutItem(tabcontrol, True)

        # Create the layout of the form
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(tabcontrol)

        # Adds the tabular layout to the main form
        self.Content = layout


class TemplateTabClass(forms.TabPage):

    # Initialize panel with settings
    def __init__(self):
        super().__init__()

        # Frame Table Tab 
        self.Text = 'Test Tab'

        # Add panel and layout
        pan = forms.Panel()
        pan.Content = self.PanelLayout()
        self.Content = pan
        self.Click += self.OnTabClick


    # Panel layout function
    def PanelLayout(self):

        # create a layout
        layout = forms.DynamicLayout()
        layout.DefaultSpacing = drawing.Size(5, 5)
        layout.Padding = drawing.Padding(5)

        # set the panel content
        layout.BeginVertical()
        layout.AddSpace()
        layout.EndVertical()

        return layout
    
    # Tab clicked event
    def OnTabClick(self, sender, e):
        print('Tab Clicked')



def showdlg():
    dlg = ModelessDlg()
    dlg.Owner = Rhino.UI.RhinoEtoApp.MainWindow
    dlg.Location = drawing.Point(200, 200)
    dlg.Show()

    

################################################################################
if __name__ == "__main__":
    showdlg()

Hi @etiennekasteel,

I’m not at my computer right now but what happens if you replace the line:

Tab clicked event

def OnTabClick(self, sender, e):
    print('Tab Clicked')

With:

Tab clicked event

def OnTabClick(self, sender, e):
    Rhino.RhinoApp.Writeline("Tab Clicked")

?

See @michaelvollrath response.

Currently, the print statement is only bound to the Rhino command prompt during the execution of script. Since this is a non-modal window, the script ‘ends’ but the window stays open. So print statements from event handles are not captured.

Using Rhino.RhinoApp.Writeline fixes the issue.

I added a note to this ticket to improve:
RH-77370 Improve stdout handling

1 Like

Thanks for confirming @eirannejad !

1 Like

Thanks both, can confirm this works as well!

Calls to rhinoscriptsyntax do work fortunately!

1 Like