parameters: (moduleName)
return_statement: return reloaded_module
docstring: Generic reload method for any scripted module.
  
    The function performs the following:
  
    * Ensure ``sys.path`` includes the module path and use ``imp.load_module``
      to load the associated script.
    * For the current module widget representation:
  
      * Hide all children widgets
      * Call ``cleanup()`` function and disconnect ``ScriptedLoadableModuleWidget_onModuleAboutToBeUnloaded``
      * Remove layout items
  
    * Instantiate new widget representation
    * Call ``setup()`` function
    * Update ``slicer.modules.<moduleName>Widget`` attribute
docstring_summary: Generic reload method for any scripted module.
docstring_tokens: Generic reload method for any scripted module .
function: def reloadScriptedModule(moduleName):
    """Generic reload method for any scripted module.
  
    The function performs the following:
  
    * Ensure ``sys.path`` includes the module path and use ``imp.load_module``
      to load the associated script.
    * For the current module widget representation:
  
      * Hide all children widgets
      * Call ``cleanup()`` function and disconnect ``ScriptedLoadableModuleWidget_onModuleAboutToBeUnloaded``
      * Remove layout items
  
    * Instantiate new widget representation
    * Call ``setup()`` function
    * Update ``slicer.modules.<moduleName>Widget`` attribute
    """
    import imp, sys, os
    import slicer
  
    widgetName = moduleName + "Widget"
  
    # reload the source code
    filePath = modulePath(moduleName)
    p = os.path.dirname(filePath)
    if not p in sys.path:
      sys.path.insert(0,p)
    with open(filePath, encoding='utf8') as fp:
      reloaded_module = imp.load_module(
          moduleName, fp, filePath, ('.py', 'r', imp.PY_SOURCE))
  
    # find and hide the existing widget
    parent = eval('slicer.modules.%s.widgetRepresentation()' % moduleName.lower())
    for child in parent.children():
      try:
        child.hide()
      except AttributeError:
        pass
  
    # if the module widget has been instantiated, call cleanup function and
    # disconnect "_onModuleAboutToBeUnloaded" (this avoids double-cleanup on
    # application exit)
    if hasattr(slicer.modules, widgetName):
      widget = getattr(slicer.modules, widgetName)
      widget.cleanup()
  
      if hasattr(widget, '_onModuleAboutToBeUnloaded'):
        slicer.app.moduleManager().disconnect('moduleAboutToBeUnloaded(QString)', widget._onModuleAboutToBeUnloaded)
  
    # remove layout items (remaining spacer items would add space above the widget)
    items = []
    for itemIndex in range(parent.layout().count()):
      items.append(parent.layout().itemAt(itemIndex))
    for item in items:
      parent.layout().removeItem(item)
  
    # create new widget inside existing parent
    widget = eval('reloaded_module.%s(parent)' % widgetName)
    widget.setup()
    setattr(slicer.modules, widgetName, widget)
  
    return reloaded_module
function_tokens: def reloadScriptedModule ( moduleName ) : import imp , sys , os import slicer widgetName = moduleName + "Widget" # reload the source code filePath = modulePath ( moduleName ) p = os . path . dirname ( filePath ) if not p in sys . path : sys . path . insert ( 0 , p ) with open ( filePath , encoding = 'utf8' ) as fp : reloaded_module = imp . load_module ( moduleName , fp , filePath , ( '.py' , 'r' , imp . PY_SOURCE ) ) # find and hide the existing widget parent = eval ( 'slicer.modules.%s.widgetRepresentation()' % moduleName . lower ( ) ) for child in parent . children ( ) : try : child . hide ( ) except AttributeError : pass # if the module widget has been instantiated, call cleanup function and # disconnect "_onModuleAboutToBeUnloaded" (this avoids double-cleanup on # application exit) if hasattr ( slicer . modules , widgetName ) : widget = getattr ( slicer . modules , widgetName ) widget . cleanup ( ) if hasattr ( widget , '_onModuleAboutToBeUnloaded' ) : slicer . app . moduleManager ( ) . disconnect ( 'moduleAboutToBeUnloaded(QString)' , widget . _onModuleAboutToBeUnloaded ) # remove layout items (remaining spacer items would add space above the widget) items = [ ] for itemIndex in range ( parent . layout ( ) . count ( ) ) : items . append ( parent . layout ( ) . itemAt ( itemIndex ) ) for item in items : parent . layout ( ) . removeItem ( item ) # create new widget inside existing parent widget = eval ( 'reloaded_module.%s(parent)' % widgetName ) widget . setup ( ) setattr ( slicer . modules , widgetName , widget ) return reloaded_module