I could only load individual files using the default slicelet code given on the website and the documentation, would like help as I want to upload an entire dicom directory.
You can use DICOMLib.DICOMUtils.LoadDICOMFilesToDatabase See complete example here:
See also this post: Imported dicom files do not show in the dicomDatabase
How do I get the following segment to load dicom database, instead of the individual files it is loading at present?
loadDataButton = qt.QPushButton(“Load Data”)
hlayout.addWidget(loadDataButton)
loadDataButton.connect(‘clicked()’, slicer.util.openAddVolumeDialog)
Entire Code:
def onModuleSelected(modulename):
global tabWidget
scrollArea = qt.QScrollArea(tabWidget)
scrollArea.setWidget(getattr(slicer.modules, modulename.lower()).widgetRepresentation())
scrollArea.setHorizontalScrollBarPolicy(qt.Qt.ScrollBarAlwaysOff)
scrollArea.setWidgetResizable(True)
tabWidget.addTab(scrollArea, modulename)
import qt
import __main__try:
mainWidget = qt.QWidget()
mainWidget.objectName = "qSlicerAppMainWindow"
vlayout = qt.QVBoxLayout()
mainWidget.setLayout(vlayout)
# splitter between "layout" and "bottom frame"
#splitter = qt.QSplitter()
#splitter.orientation = qt.Qt.Vertical
#vlayout = qt.QVBoxLayout()
#vlayout.addWidget(splitter)
# layout
layoutManager = slicer.qMRMLLayoutWidget()
layoutManager.setMRMLScene(slicer.mrmlScene)
layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUp3DView)
vlayout.addWidget(layoutManager)
# Bottom frame: including control buttons and tab widget
bottomFrame = qt.QFrame()
bottomVlayout = qt.QVBoxLayout()
bottomFrame.setLayout(bottomVlayout)
vlayout.addWidget(bottomFrame)
# Horizontal layout: Load Data, Save Data, Module Selector
hlayout = qt.QHBoxLayout()
bottomVlayout.addLayout(hlayout)
loadDataButton = qt.QPushButton("Load Data")
#loadDataButton = Button(root, text="Load Data", command=browsefunc)
#loadDataButton.pack()
hlayout.addWidget(loadDataButton)
#loadDataButton.connect('clicked()', browsefunc)
loadDataButton.connect('clicked()', slicer.util.openAddVolumeDialog)
#loadDataButton.connect('clicked()', slicer.util.loadVolume('/path/of/*'))
#loadDataButton.connect('clicked()',DICOMUtils.LoadDICOMFilesToDatabase)
saveDataButton = qt.QPushButton("Save Data")
hlayout.addWidget(saveDataButton)
saveDataButton.connect('clicked()', slicer.util.openSaveDataDialog)
moduleSelector = slicer.qSlicerModuleSelectorToolBar()
moduleSelector.setModuleManager(slicer.app.moduleManager())
hlayout.addWidget(moduleSelector)
#moduleSelector.connect('moduleSelected(QString)', onModuleSelected)
# Tab widget
tabWidget = qt.QTabWidget()
bottomVlayout.addWidget(tabWidget)
# Connections
moduleSelector.connect('moduleSelected(QString)', onModuleSelected)
# Initialize
modules = ["volumes", "models", "labelstatistics"]
for module in modules:
onModuleSelected(module)
#tabWidget.show()
mainWidget.show()
#__main__.tabWidget = tabWidget # Keep track of the widget to avoid its premature destruction
__main__.mainWidget = mainWidget # Keep track of the widget to avoid its premature destruction
How do I get the following segment to load dicom database, instead of the individual files it is loading at present?
loadDataButton = qt.QPushButton(“Load Data”)
hlayout.addWidget(loadDataButton)
loadDataButton.connect(‘clicked()’, slicer.util.openAddVolumeDialog)
Entire Code:
def onModuleSelected(modulename):
global tabWidget
scrollArea = qt.QScrollArea(tabWidget)
scrollArea.setWidget(getattr(slicer.modules, modulename.lower()).widgetRepresentation())
scrollArea.setHorizontalScrollBarPolicy(qt.Qt.ScrollBarAlwaysOff)
scrollArea.setWidgetResizable(True)
tabWidget.addTab(scrollArea, modulename)
import qt
import __main__try:
mainWidget = qt.QWidget()
mainWidget.objectName = “qSlicerAppMainWindow”
vlayout = qt.QVBoxLayout()
mainWidget.setLayout(vlayout)
# splitter between “layout” and “bottom frame”
#splitter = qt.QSplitter()
#splitter.orientation = qt.Qt.Vertical
#vlayout = qt.QVBoxLayout()
#vlayout.addWidget(splitter)
# layout
layoutManager = slicer.qMRMLLayoutWidget()
layoutManager.setMRMLScene(slicer.mrmlScene)
layoutManager.setLayout(slicer.vtkMRMLLayoutNode.SlicerLayoutOneUp3DView)
vlayout.addWidget(layoutManager)
# Bottom frame: including control buttons and tab widget
bottomFrame = qt.QFrame()
bottomVlayout = qt.QVBoxLayout()
bottomFrame.setLayout(bottomVlayout)
vlayout.addWidget(bottomFrame)
# Horizontal layout: Load Data, Save Data, Module Selector
hlayout = qt.QHBoxLayout()
bottomVlayout.addLayout(hlayout)
loadDataButton = qt.QPushButton(“Load Data”)
#loadDataButton = Button(root, text=“Load Data”, command=browsefunc)
#loadDataButton.pack()
hlayout.addWidget(loadDataButton)
#loadDataButton.connect(‘clicked()’, browsefunc)
loadDataButton.connect(‘clicked()’, slicer.util.openAddVolumeDialog)
#loadDataButton.connect(‘clicked()’, slicer.util.loadVolume(’/path/of/*’))
#loadDataButton.connect(‘clicked()’,DICOMUtils.LoadDICOMFilesToDatabase)
saveDataButton = qt.QPushButton(“Save Data”)
hlayout.addWidget(saveDataButton)
saveDataButton.connect(‘clicked()’, slicer.util.openSaveDataDialog)
moduleSelector = slicer.qSlicerModuleSelectorToolBar()
moduleSelector.setModuleManager(slicer.app.moduleManager())
hlayout.addWidget(moduleSelector)
#moduleSelector.connect(‘moduleSelected(QString)’, onModuleSelected)
# Tab widget
tabWidget = qt.QTabWidget()
bottomVlayout.addWidget(tabWidget)
# Connections
moduleSelector.connect(‘moduleSelected(QString)’, onModuleSelected)
# Initialize
modules = [“volumes”, “models”, “labelstatistics”]
for module in modules:
onModuleSelected(module)
#tabWidget.show()
mainWidget.show()
#**main**.tabWidget = tabWidget # Keep track of the widget to avoid its premature destruction
**main**.mainWidget = mainWidget # Keep track of the widget to avoid its premature destruction
Please provide more information. It is not obvious what you would like to do, what do you expect your current code should do, and what happens instead.
The forum is good for discussion but not well suited for code review. If you upload your code to github and send a link to it then there is a better chance that somebody can look at it and give you feeback.