RadioButton Icon Example

Description

This demonstrates the RadioButton UI component with visually pleasing icons which may avoid the need to define text for each button.

Python Script Files

  • radio_button_icon_ui.py
  • radio_button_icon.py

Significant Script Features

radio_button_icon_ui.py:

# Define Layout and Components
def getCustomToolPropertyContent():

   # Create a Grid
   my_Grid = WPFControls.Grid()

   # Add 1 Row and One Column
   my_Grid.RowDefinitions.Add(WPFControls.RowDefinition())
   my_Grid.RowDefinitions.Add(WPFControls.RowDefinition())
   my_Grid.ColumnDefinitions.Add(WPFControls.ColumnDefinition())
  
   # Create a label for the icon radio button array
   meshTextBlock = WPFControls.TextBlock()
   meshTextBlock.Text = "Horizontal icon array"
   WPFControls.Grid.SetRow(meshTextBlock, 0)
   WPFControls.Grid.SetColumn(meshTextBlock, 0)

   # Create a horizontal array of three radio buttons
   # Create a Horizontal WrapPanel   
   myWrapPanel = WPFControls.WrapPanel()
   myWrapPanel.Orientation=WPFControls.Orientation.Horizontal
   WPFControls.Grid.SetRow(myWrapPanel, 1)
   WPFControls.Grid.SetColumn(myWrapPanel, 0)
   
   # Create a List to hold the radio buttons
   # We'll use this later to make it easier to find which button is checked 
   global icon_radio_buttons
   icon_radio_buttons = [] 

   # Create a global variable to hold the name of the checked radio button
   global checked_button_name

   # First radio button - make this one checked
   icon_radio_buttons.append(WPFControls.RadioButton())
   icon_radio_buttons[-1].IsChecked = System.Nullable[System.Boolean](True)
   icon_radio_buttons[-1].Name = "Mixed"
   # Set checked_button_name to this radio button
   checked_button_name = icon_radio_buttons[-1].Name
   
   # Add a handler for the "Checked" and "Unchecked" events
   icon_radio_buttons[-1].Checked += CheckIconRadioButton
   icon_radio_buttons[-1].Unchecked += UncheckIconRadioButton
   
   # Assign an image to this button
   icon_radio_buttons[-1].Content = os.path.join(os.path.dirname(current_file_path), r"Icons\mixed.png")
   icon_radio_buttons[-1].SetResourceReference(WPFControls.Control.StyleProperty, "IconOnlyRadioButton")

   # Add it to the WrapPanel     
   myWrapPanel.Children.Add(icon_radio_buttons[-1])
   
   # Second radio button
   icon_radio_buttons.append(WPFControls.RadioButton())
   # Assign a name to the radio button
   icon_radio_buttons[-1].Name = "Quad"

   # Add a handler for the "Checked" and "Unchecked" events
   icon_radio_buttons[-1].Checked += CheckIconRadioButton
   icon_radio_buttons[-1].Unchecked += UncheckIconRadioButton
    
   # Assign an image to this button
   icon_radio_buttons[-1].Content = os.path.join(os.path.dirname(current_file_path), r"Icons\quad.png")
   icon_radio_buttons[-1].SetResourceReference(WPFControls.Control.StyleProperty, "IconOnlyRadioButton")
   # Make this icon semi-transparent since it is not checked
   icon_radio_buttons[-1].Opacity = 0.5
   # Add it to the WrapPanel        
   myWrapPanel.Children.Add(icon_radio_buttons[-1])
   
   # Third radio button
   icon_radio_buttons.append(WPFControls.RadioButton())
   # Assign a name to the radio button
   icon_radio_buttons[-1].Name = "Tria"
      
   # Add a handler for the "Checked" and "Unchecked" events
   icon_radio_buttons[-1].Checked += CheckIconRadioButton
   icon_radio_buttons[-1].Unchecked += UncheckIconRadioButton

   # Assign an image to this button
   icon_radio_buttons[-1].Content = os.path.join(os.path.dirname(current_file_path), r"Icons\tria.png")
   icon_radio_buttons[-1].SetResourceReference(WPFControls.Control.StyleProperty, "IconOnlyRadioButton")
   # Make this icon semi-transparent since it is not checked
   icon_radio_buttons[-1].Opacity=0.5
   # Add it to the WrapPanel        
   myWrapPanel.Children.Add(icon_radio_buttons[-1])

   #Add the WrapPanel to the Grid
   my_Grid.Children.Add(meshTextBlock)   
   my_Grid.Children.Add(myWrapPanel)

   # Return the Grid   
   return my_Grid