.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/07_ui/viz_combobox.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_07_ui_viz_combobox.py: ======== ComboBox ======== This example shows how to use the Combobox UI. We will demonstrate how to create ComboBoxes for selecting colors for a label. First, some imports. .. GENERATED FROM PYTHON SOURCE LINES 11-14 .. code-block:: Python from fury import ui, window from fury.data import fetch_viz_icons .. GENERATED FROM PYTHON SOURCE LINES 15-16 First we need to fetch some icons that are included in FURY. .. GENERATED FROM PYTHON SOURCE LINES 16-19 .. code-block:: Python fetch_viz_icons() .. rst-class:: sphx-glr-script-out .. code-block:: none Data size is approximately 12KB Dataset is already in place. If you want to fetch it again please first remove the folder /Users/skoudoro/.fury/icons ({'icomoon.tar.gz': ('https://digital.lib.washington.edu/researchworks/bitstream/handle/1773/38478/icomoon.tar.gz', 'BC1FEEA6F58BA3601D6A0B029EB8DFC5F352E21F2A16BA41099A96AA3F5A4735')}, '/Users/skoudoro/.fury/icons') .. GENERATED FROM PYTHON SOURCE LINES 20-21 First, we create a label. .. GENERATED FROM PYTHON SOURCE LINES 21-31 .. code-block:: Python label = ui.TextBlock2D( position=(200, 300), font_size=40, color=(1, 0.5, 0), justification='center', vertical_justification='top', text='FURY rocks!!!', ) .. GENERATED FROM PYTHON SOURCE LINES 32-34 Now we create a dictionary to store colors as its key and their RGB values as its value. .. GENERATED FROM PYTHON SOURCE LINES 34-45 .. code-block:: Python colors = { 'Violet': (0.6, 0, 0.8), 'Indigo': (0.3, 0, 0.5), 'Blue': (0, 0, 1), 'Green': (0, 1, 0), 'Yellow': (1, 1, 0), 'Orange': (1, 0.5, 0), 'Red': (1, 0, 0), } .. GENERATED FROM PYTHON SOURCE LINES 46-50 ComboBox =================== Now we create a ComboBox UI component for selecting colors. .. GENERATED FROM PYTHON SOURCE LINES 50-58 .. code-block:: Python color_combobox = ui.ComboBox2D( items=list(colors.keys()), placeholder='Choose Text Color', position=(75, 50), size=(250, 150), ) .. GENERATED FROM PYTHON SOURCE LINES 59-63 Callbacks ================================== Now we create a callback for setting the chosen color. .. GENERATED FROM PYTHON SOURCE LINES 63-73 .. code-block:: Python def change_color(combobox): label.color = colors[combobox.selected_text] # `on_change` callback is set to `change_color` method so that # it's called whenever a different option is selected. color_combobox.on_change = change_color .. GENERATED FROM PYTHON SOURCE LINES 74-78 Show Manager ================================== Now we add label and combobox to the scene. .. GENERATED FROM PYTHON SOURCE LINES 78-90 .. code-block:: Python current_size = (400, 400) showm = window.ShowManager(size=current_size, title='ComboBox UI Example') showm.scene.add(label, color_combobox) # To interact with the UI, set interactive = True interactive = False if interactive: showm.start() window.record(showm.scene, out_path='combobox_ui.png', size=(400, 400)) .. image-sg:: /auto_examples/07_ui/images/sphx_glr_viz_combobox_001.png :alt: viz combobox :srcset: /auto_examples/07_ui/images/sphx_glr_viz_combobox_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.050 seconds) .. _sphx_glr_download_auto_examples_07_ui_viz_combobox.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_combobox.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_combobox.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_