you may try to do a segment editor effect. For example, you can take a look at the user-interactions available in the paint effect (works both in 2d and 3d: takes the input coordinates for left-click events) and create your own:
The editor has an effects factory, so you can register your new editor effect very simply, something like this:
When I execute self.promptSeedSelect("background")
It is returning [0,0,0]. Is there any way I can force the program to wait for a mouse click when the user clicks ‘Ok’?
def promptSeedSelect(self, seed):
c = ctk.ctkMessageBox()
c.setIcon(qt.QMessageBox.Information)
c.setText("Click on a point in the %s to select the seed" % seed)
c.setStandardButtons(qt.QMessageBox.Ok)
c.setDefaultButton(qt.QMessageBox.Ok)
answer = c.exec_()
if answer == qt.QMessageBox.Cancel:
logging.info("Terminating...")
self.logic = None
return
logging.info("Coords are: " + self.drawFiducial(seed))
def drawFiducial(self, seed):
ras = [0.0,0.0,0.0]
fidNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLMarkupsFiducialNode', seed)
selectionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSelectionNodeSingleton")
selectionNode.SetReferenceActivePlaceNodeID(fidNode.GetID())
interactionNode = slicer.mrmlScene.GetNodeByID("vtkMRMLInteractionNodeSingleton")
# For multiple clicks, change this to 1
placeModePersistence = 0
interactionNode.SetPlaceModePersistence(placeModePersistence)
interactionNode.SetCurrentInteractionMode(1)
fidNode.GetNthFiducialPosition(0, ras)
return ras
You need to add an observer on the fiducial list node for the
slicer.vtkMRMLMarkupsNode.MarkupAddedEvent
and then you can get the last fiducial position since it’s then been added.
Thank you. When I did that, the code runs fine but then I couldn’t get it to capture the input a second time if the user chooses to. Here is my full code:
To reproduce my problem, select this extension from Slicer’s Extension Wizard, then add a breakpoint to line 265 and set a watch with the following:
slicer.mrmlScene.GetNodeByID(“vtkMRMLInteractionNodeSingleton”).GetCurrentInteractionMode()
You’ll see that it shows 1 in the debugger, which we want, but then when it exits the call stack, it spontaneously switches to 2, which does not allow placement of a fiducial.
As I see, you have commented out the markup place widget, while you shouldn’t have, because that widget is exactly what you need (it makes sure that the correct markup list is selected, placement mode is active, and single/multiple markup placement option is selected). Just add this widget to the GUI and modify the place multiple markups mode:
Thank you for all your help so far. The reason I commented out the widget is because it would require more manual work from the user. I just want the user to be able to choose whether to add more markups or to stop adding more, using this dialog
When the user clicks “Add More”, it should create a new fiducial and set an observer to it and show this dialog when the user places a markup, and so on, until the user clicks “Save All”, then it would move to the next step. However, the problem I mentioned above happens when the user clicks “Add More”, and I don’t know why…
Instead of the “Add more” button, use the place widget, configured to show only a single place button, with single markup place mode. It works reliably, used in many modules.