TypeError: 'NoneType' object is not callable

Hey all,

I’m developing a module to Slicer and I’m facing some issues. One of the functionalities is to place a control point and get its coordinates through a button that calls a method. I put a print on the beggining of this method and it’s called right when I start the module, but when I place de control point and click the button it gives this error: TypeError: 'NoneType' object is not callable

def setup(self):
      
        ScriptedLoadableModuleWidget.setup(self)

        uiWidget = slicer.util.loadUI(self.resourcePath('UI/Module.ui'))
        self.layout.addWidget(uiWidget)
        self.ui = slicer.util.childWidgetVariables(uiWidget)

        markupsNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsFiducialNode")
        self.ui.PontoCentralButton.setCurrentNode(markupsNode)
        self.ui.PontoCentralButton.buttonsVisible=False
        self.ui.PontoCentralButton.placeButton().show()
        self.ui.PontoCentralButton.placeMultipleMarkups = slicer.qSlicerMarkupsPlaceWidget.ForcePlaceSingleMarkup

        uiWidget.setMRMLScene(slicer.mrmlScene)

# [...]

        # Buttons
        self.ui.CoordsButton.connect("clicked(bool)", self.logic.coordCentral(self.ui.MRMLNodeComboBox_frame.currentNode(),markupsNode))
def coordCentral(self, inputFrame, markupsNode):
        print("method called ")

My guess is that self.ui.MRMLNodeComboBox_frame is the NoneType object. Make sure your UI file has this object with this exact objectName of MRMLNodeComboBox_frame and that you have saved this UI file (not unsaved changes).

1 Like

Hi James, I checked that but it’s the exact same name. And the .ui file is saved too

I would suggest you do some continued debugging to find the NoneType object. Adding a print statement for self.ui.MRMLNodeComboBox_frame will help confirm if it is indeed an object or a NoneType.

I printed the inputFrame on coordCentral, where inputFrame = self.ui.MRMLNodeComboBox_frame and it returned this:

vtkMRMLViewNode (000001CC95966B90)
  ID: vtkMRMLViewNode1
  ClassName: vtkMRMLViewNode
  Name: View1
  Debug: false
  MTime: 227115
  Description: (none)
  SingletonTag: 1
  HideFromEditors: false
  Selectable: true
  Selected: false
  UndoEnabled: false
  Attributes:
    MappedInLayout:1
  Node references:
    InteractionNodeRef: (none)
    ParentLayoutNodeRef: (none)
  LayoutLabel: 1
  ViewGroup: 0
  Active: 0
  Visibility: 1
  BackgroundColor: (0.756863, 0.764706, 0.909804)
  BackgroundColor2: (0.454902, 0.470588, 0.745098)
  LayoutColor: (0.454902, 0.513725, 0.913725)
  OrientationMarkerType: none
  OrientationMarkerSize: medium
  RulerType: none
  RulerColor: white
   AxisLabels: L;R;P;A;I;S
  FieldOfView: 200
  LetterSize: 0.05
  BoxVisible: true
  BoxColor: (1, 0, 1)
  FiducialsVisible: true
  FiducialLabelsVisible: true
  AxisLabelsVisible: true
  AxisLabelsCameraDependent: true
  AnimationMode: Off
  ViewAxisMode: LookFrom
  SpinDegrees: 2
  AnimationMs: 5
  SpinDirection: YawLeft
  RotateDegrees: 5
  RockLength: 200
  RockCount: 0
  StereoType: NoStereo
  RenderMode: Perspective
  UseDepthPeeling: 1
  GPUMemorySize: 0
  AutoReleaseGraphicsResources: false
  ExpectedFPS: 8
  VolumeRenderingQuality: 1
  RaycastTechnique: 0
  VolumeRenderingSurfaceSmoothing: 0
  VolumeRenderingOversamplingFactor: 2
  Interacting: 0
  LinkedControl: 0

From Description: (none) it seems to be a NoneType right? But again the method was called right when the module started, before selecting the input node and placing the control point. So I’m guessing that’s why it’s NoneType.

Don’t know why this is happening.

Please copy-paste the whole error message you get. Without it it is only possible to keep guessing around.

You seem to be using

self.ui.PontoCentralButton

and

self.ui.CoordsButton

in your example, which will probably not work …

I copied on the original qustion: TypeError: 'NoneType' object is not callable

There’s nothing else.

They are different things actually. I don’t know if that’s the most effiecient way because I’m new to Slicer but the idea is: the user place a control point trought the Markups Control Point button (PontoCentralButton), and when it’s placed they click on the “Coordenadas” button (CoordsButton), wich should call the method and get the coordinates of that control point.

image

Hope this helps to give more context to the problem.

Please put your function into the YourExtensionWidget class, not into the YourExtensionLogic.

Connect it like:

      self.ui.toggleButton.connect('clicked(bool)', self.onToggleButton)

Hope that helps.

Unfortunately the same behavior happens :frowning:
I made onToggleButton call the processing function on the Logic class too, but it didn’t work either.

Maybe you can print the coordinates of your markup like described here and avoid passing the view argument.

Great, I’ll try that and let you know if it works, thanks!

1 Like