How to use the slicer.util.findChildren function in slicer

To help you get started, we’ve selected a few slicer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SlicerDMRI / SlicerDMRI / Modules / Loadable / TractographyDisplay / Testing / Python / test_tractography_display.py View on Github external
color_by_strategies = [
        ('Solid Color', displayNode.colorModeSolid),
        ('Of Tensor Property', displayNode.colorModeScalar),
#        (, displayNode.colorModeFunctionOfScalar),
#        ('Color Fibers By Mean Orientation', displayNode.colorModeUseCellScalars),
        ('Of Scalar Value', displayNode.colorModeScalarData),
        ('Color Fibers By Segment Orientation', displayNode.colorModePointFiberOrientation),
        ('Color Fibers By Mean Orientation', displayNode.colorModeMeanFiberOrientation),
    ]
    for widget_text, color_code in color_by_strategies:

        if not visibility.checked:
            visibility.click()

        solidColor = slicer.util.findChildren(tubeTab, text=widget_text)
        if len(solidColor) == 0:
            raise ValueError("Widget %s not found" % widget_text)
        else:
            solidColor = solidColor[0]
        solidColor.click()

        if displayNode and displayNode.GetColorMode() != color_code:
            self.delayDisplay('Setting Color Mode To %s Did not Work' % widget_text)
            raise Exception()
        else:
            self.delayDisplay("Setting Color Mode To %s Worked" % widget_text)

    visibility.click()
github SlicerDMRI / SlicerDMRI / Modules / Loadable / TractographyDisplay / Testing / Python / test_tractography_display.py View on Github external
def test_TestTractographyDisplayColorBy(self, display_node='Tube'):
    self.delayDisplay("Starting the test")

    self.delayDisplay('Showing Advanced Display\n')
    advancedDisplay = slicer.util.findChildren(text='Advanced Display')[0]
    advancedDisplay.collapsed = False

    self.delayDisplay('Selecting tract1\n')
    tractNode = slicer.util.getNode('tract1')
    displayNode = getattr(tractNode, 'Get%sDisplayNode' % display_node)()
    tree = slicer.util.findChildren(name='TractographyDisplayTreeView')[0]
    model = tree.model()
    modelIndex = model.indexFromMRMLNode(tractNode)
    tree.setCurrentIndex(modelIndex)

    tubeTab = slicer.util.findChildren(advancedDisplay, name='%sTab' % display_node)[0]

    visibility = slicer.util.findChildren(tubeTab, text='Visibility')[0]

    color_by_strategies = [
        ('Solid Color', displayNode.colorModeSolid),
github QIICR / QuantitativeReporting / Util / LabelToDICOMSEGConverter / LabelToDICOMSEGConverter.py View on Github external
# reload the source code
    # - set source file path
    # - load the module to the global space
    filePath = eval('slicer.modules.%s.path' % moduleName.lower())
    p = os.path.dirname(filePath)
    if not sys.path.__contains__(p):
      sys.path.insert(0,p)
    fp = open(filePath, "r")
    globals()[moduleName] = imp.load_module(
        moduleName, fp, filePath, ('.py', 'r', imp.PY_SOURCE))
    fp.close()

    # rebuild the widget
    # - find and hide the existing widget
    # - create a new widget in the existing parent
    parent = slicer.util.findChildren(name='%s Reload' % moduleName)[0].parent()
    for child in parent.children():
      try:
        child.hide()
      except AttributeError:
        pass
    # Remove spacer items
    item = parent.layout().itemAt(0)
    while item:
      parent.layout().removeItem(item)
      item = parent.layout().itemAt(0)
    # create new widget inside existing parent
    globals()[widgetName.lower()] = eval(
        'globals()["%s"].%s(parent)' % (moduleName, widgetName))
    globals()[widgetName.lower()].setup()