Skip to content

Instantly share code, notes, and snippets.

@lassoan
Last active December 20, 2018 18:32
Show Gist options
  • Save lassoan/7d4cec3012155e2597ee3f47157f0a65 to your computer and use it in GitHub Desktop.
Save lassoan/7d4cec3012155e2597ee3f47157f0a65 to your computer and use it in GitHub Desktop.
Simple 3D Slicer based image viewer
def showSimpleUserInterface(simpleView):
# Do not store these display settings permanently
settings = qt.QSettings()
settings.setValue('MainWindow/RestoreGeometry', not simpleView)
for toolbar in slicer.util.mainWindow().findChildren('QToolBar'):
toolbar.setVisible(not simpleView)
modulePanelDockWidget = slicer.util.mainWindow().findChildren('QDockWidget','PanelDockWidget')[0]
modulePanelDockWidget.setVisible(not simpleView)
layoutManager = slicer.app.layoutManager()
for sliceViewName in layoutManager.sliceViewNames():
sliceWidget = layoutManager.sliceWidget(sliceViewName)
sliceControlWidget = sliceWidget.sliceController()
sliceControlWidget.setSliceVisible(True)
pinButton = sliceControlWidget.children()[1].children()[1]
if simpleView:
pinButton.hide()
else:
pinButton.show()
def createSimpleDataBrowser():
mainWindow = slicer.util.mainWindow()
dockWidget = qt.QDockWidget("Data browser", mainWindow)
dockWidget.setFeatures(qt.QDockWidget.DockWidgetClosable + qt.QDockWidget.DockWidgetMovable + qt.QDockWidget.DockWidgetFloatable)
mainFrame = qt.QFrame(dockWidget)
mainFrameLayout = qt.QVBoxLayout(mainFrame)
# Add switch layout buttons
displayLayout = qt.QHBoxLayout()
mainFrameLayout.addLayout(displayLayout)
displayPresets = (
(slicer.vtkMRMLLayoutNode.SlicerLayoutFourUpView, "LayoutFourUpView.png"),
(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUpRedSliceView, "LayoutOneUpRedSliceView.png"),
(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUpYellowSliceView, "LayoutOneUpYellowSliceView.png"),
(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUpGreenSliceView, "LayoutOneUpGreenSliceView.png"),
(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUp3DView, "LayoutOneUp3DView.png"),
)
for (layoutId, iconName) in displayPresets:
switchLayoutButton = qt.QPushButton("")
switchLayoutButton.setIcon(qt.QIcon(":Icons/"+iconName))
displayLayout.addWidget(switchLayoutButton, 0, 0)
switchLayoutButton.connect('clicked()', lambda layoutId=layoutId: slicer.app.layoutManager().setLayout(layoutId))
# Add data tree
dataTreeWidget = slicer.qMRMLSubjectHierarchyTreeView(mainFrame)
dataTreeWidget.setMRMLScene(slicer.mrmlScene)
dataTreeWidget.setColumnHidden(dataTreeWidget.model().idColumn, True)
dataTreeWidget.setColumnHidden(dataTreeWidget.model().transformColumn, True)
mainFrameLayout.addWidget(dataTreeWidget)
dockWidget.setWidget(mainFrame)
mainWindow.addDockWidget(qt.Qt.LeftDockWidgetArea, dockWidget)
# Load a scene and show it in simple view:
showSimpleUserInterface(True)
createSimpleDataBrowser()
# Example for loading a scene from file:
# slicer.util.loadScene(r'c:\Users\msliv\OneDrive\Documents\2018-03-29-Scene.mrb')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment