Hi everyone!
I have been writing a python script that allows opening specific modules using keyboard shortcuts.
However, the script does not work quite right.
Below is what I could put together based on the forum topics.
#Makes selected module to popup as second module
def openSegmentEditor():
slicer.modules.segmenteditor.widgetRepresentation().setParent(None)
slicer.modules.segmenteditor.widgetRepresentation().show()
#setup the short cut
shortcut1 = qt.QShortcut(slicer.util.mainWindow())
shortcut1.setKey(qt.QKeySequence(“Ctrl+n”))
shortcut1.connect( ‘activated()’, openSegmentEditor)
This script allowed me to open the segment module as a second panel using ctrl+n.
However, the SegmentEditor hotkeys(numbers, shit+numbers) do not work when opened as a second module.
I am new to python, and I have been looking all over the forum but could not find the proper solution to this problem.
I would be grateful if anyone could help me out with this.
So my questions are:
Is there any way to open the module on the main panel?
I am currently planning to make a shortcut that would allow me to not only open the module but also lead me to the exact widget. For instance, I want to create a shortcut that would directly lead me to EraseInside of the Scissor from the main window. Would this be better, or should I just set up a toggle hotkey and switch around?
#Makes selected module to popup as second module
def openSegmentEditor():
mainWindow = slicer.util.mainWindow()
mainWindow.moduleSelector().selectModule('SegmentEditor')
#setup the short cut
shortcut1 = qt.QShortcut(slicer.util.mainWindow())
shortcut1.setKey(qt.QKeySequence('Ctrl+n'))
shortcut1.connect('activated()', lambda: openSegmentEditor())
Use single quotes only : ‘activated()’ -> 'activated()'
In your first post, the ‘activated()’ signal is not between single quotes, but other similarly looking characters, at least the second ‘quote but not a quote’. By copy/paste in the python console, it won’t run. I did not try with double quotes, may be it’s OK. I meant : not other characters that look like single quote.