コード例 #1
0
  def setup(self, showPreview=False):
    """
    main window is a frame with widgets from the app
    widget repacked into it along with slicer-specific
    extra widgets
    """

    self.setWindowTitle('DICOM Browser')
    self.setLayout(qt.QVBoxLayout())

    self.dicomBrowser.databaseDirectorySelectorVisible = False
    self.dicomBrowser.toolbarVisible = False
    self.dicomBrowser.sendActionVisible = True
    self.dicomBrowser.databaseDirectorySettingsKey = slicer.dicomDatabaseDirectorySettingsKey
    self.dicomBrowser.dicomTableManager().dynamicTableLayout = False
    horizontal = self.settings.setValue('DICOM/horizontalTables', 0)
    self.dicomBrowser.dicomTableManager().tableOrientation = qt.Qt.Horizontal if horizontal else qt.Qt.Vertical
    self.layout().addWidget(self.dicomBrowser)

    self.userFrame = qt.QWidget()
    self.preview = qt.QWidget()

    #
    # preview related column
    #
    self.previewLayout = qt.QVBoxLayout()
    if showPreview:
      self.previewLayout.addWidget(self.preview)
    else:
      self.preview.hide()

    #
    # action related column (interacting with slicer)
    #
    self.loadableTableFrame = qt.QWidget()
    self.loadableTableFrame.setMaximumHeight(200)
    self.loadableTableLayout = qt.QFormLayout(self.loadableTableFrame)
    self.layout().addWidget(self.loadableTableFrame)

    self.loadableTableLayout.addWidget(self.userFrame)
    self.userFrame.hide()

    self.loadableTable = DICOMLoadableTable(self.userFrame)
    self.loadableTable.itemChanged.connect(self.onLoadableTableItemChanged)

    #
    # button row for action column
    #
    self.actionButtonsFrame = qt.QWidget()
    self.actionButtonsFrame.setMaximumHeight(40)
    self.actionButtonsFrame.objectName = 'ActionButtonsFrame'
    self.layout().addWidget(self.actionButtonsFrame)

    self.actionButtonLayout = qt.QHBoxLayout()
    self.actionButtonsFrame.setLayout(self.actionButtonLayout)

    self.uncheckAllButton = qt.QPushButton('Uncheck All')
    self.actionButtonLayout.addWidget(self.uncheckAllButton)
    self.uncheckAllButton.connect('clicked()', self.uncheckAllLoadables)

    self.actionButtonLayout.addStretch(0.05)

    self.examineButton = qt.QPushButton('Examine')
    self.examineButton.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed)
    self.actionButtonLayout.addWidget(self.examineButton)
    self.examineButton.enabled = False
    self.examineButton.connect('clicked()', self.examineForLoading)

    self.loadButton = qt.QPushButton('Load')
    self.loadButton.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed)
    self.loadButton.toolTip = 'Load selected items into the scene'
    self.actionButtonLayout.addWidget(self.loadButton)
    self.loadButton.connect('clicked()', self.loadCheckedLoadables)

    self.actionButtonLayout.addStretch(0.05)

    self.advancedViewButton = qt.QCheckBox('Advanced')
    self.advancedViewButton.objectName = 'AdvancedViewCheckBox'
    self.actionButtonLayout.addWidget(self.advancedViewButton)
    self.advancedViewButton.checked = self.advancedView
    self.advancedViewButton.toggled.connect(self.onAdvancedViewButton)

    if self.advancedView:
      self.loadableTableFrame.visible = True
    else:
      self.loadableTableFrame.visible = False
      self.examineButton.visible = False
      self.uncheckAllButton.visible = False

    #
    # Series selection
    #
    self.dicomBrowser.dicomTableManager().connect('seriesSelectionChanged(QStringList)', self.onSeriesSelected)

    #
    # Plugin selection widget
    #
    self.pluginSelector = DICOMLib.DICOMPluginSelector(self)
    self.loadableTableLayout.addRow(self.pluginSelector, self.loadableTable)
    self.checkBoxByPlugins = []

    for pluginClass in slicer.modules.dicomPlugins:
      self.checkBox = self.pluginSelector.checkBoxByPlugin[pluginClass]
      self.checkBox.connect('stateChanged(int)', self.onPluginStateChanged)
      self.checkBoxByPlugins.append(self.checkBox)

    self.updateButtonStates()
コード例 #2
0
ファイル: DICOM.py プロジェクト: yehan0223/Slicer
    def setup(self):
        ScriptedLoadableModuleWidget.setup(self)

        # This module is often used in developer mode, therefore
        # collapse reload & test section by default.
        if hasattr(self, "reloadCollapsibleButton"):
            self.reloadCollapsibleButton.collapsed = True

        self.dragAndDropEventFilter = DICOMLoadingByDragAndDropEventFilter()

        globals()['d'] = self

        self.testingServer = None
        self.browserWidget = None
        self.directoryButton = None

        # Load widget from .ui file (created by Qt Designer)
        uiWidget = slicer.util.loadUI(self.resourcePath('UI/DICOM.ui'))
        self.layout.addWidget(uiWidget)
        self.ui = slicer.util.childWidgetVariables(uiWidget)

        self.browserWidget = DICOMLib.SlicerDICOMBrowser()
        self.browserWidget.objectName = 'SlicerDICOMBrowser'

        slicer.modules.DICOMInstance.setBrowserWidgetInDICOMLayout(
            self.browserWidget)

        layoutManager = slicer.app.layoutManager()
        if layoutManager is not None:
            layoutManager.layoutChanged.connect(self.onLayoutChanged)
            viewArrangement = slicer.app.layoutManager().layoutLogic(
            ).GetLayoutNode().GetViewArrangement()
            self.ui.showBrowserButton.checked = (
                viewArrangement ==
                slicer.vtkMRMLLayoutNode.SlicerLayoutDicomBrowserView)

        # connect to the 'Show DICOM Browser' button
        self.ui.showBrowserButton.connect('clicked()',
                                          self.toggleBrowserWidget)

        self.ui.importButton.connect('clicked()', self.importFolder)

        self.ui.subjectHierarchyTree.setMRMLScene(slicer.mrmlScene)
        self.ui.subjectHierarchyTree.currentItemChanged.connect(
            self.onCurrentItemChanged)
        self.ui.subjectHierarchyTree.currentItemModified.connect(
            self.onCurrentItemModified)
        self.subjectHierarchyCurrentVisibility = False
        self.ui.subjectHierarchyTree.setColumnHidden(
            self.ui.subjectHierarchyTree.model().idColumn, True)

        #
        # DICOM networking
        #

        self.ui.networkingFrame.collapsed = True
        self.ui.queryServerButton.connect('clicked()',
                                          self.browserWidget.dicomBrowser,
                                          "openQueryDialog()")

        self.ui.toggleListener.connect('toggled(bool)', self.onToggleListener)

        settings = qt.QSettings()
        self.ui.runListenerAtStart.checked = settingsValue(
            'DICOM/RunListenerAtStart', False, converter=toBool)
        self.ui.runListenerAtStart.connect('toggled(bool)',
                                           self.onRunListenerAtStart)

        # Testing server - not exposed (used for development)

        self.toggleServer = qt.QPushButton("Start Testing Server")
        self.ui.networkingFrame.layout().addWidget(self.toggleServer)
        self.toggleServer.connect('clicked()', self.onToggleServer)

        self.verboseServer = qt.QCheckBox("Verbose")
        self.ui.networkingFrame.layout().addWidget(self.verboseServer)

        # advanced options - not exposed to end users
        # developers can uncomment these lines to access testing server
        self.toggleServer.hide()
        self.verboseServer.hide()

        #
        # Browser settings
        #

        self.ui.browserSettingsFrame.collapsed = True

        self.updateDatabaseDirectoryFromBrowser(
            self.browserWidget.dicomBrowser.databaseDirectory)
        # Synchronize database selection between browser and this widget
        self.ui.directoryButton.directoryChanged.connect(
            self.updateDatabaseDirectoryFromWidget)
        self.browserWidget.dicomBrowser.databaseDirectoryChanged.connect(
            self.updateDatabaseDirectoryFromBrowser)

        self.ui.browserAutoHideCheckBox.checked = not settingsValue(
            'DICOM/BrowserPersistent', False, converter=toBool)
        self.ui.browserAutoHideCheckBox.stateChanged.connect(
            self.onBrowserAutoHideStateChanged)

        self.ui.repairDatabaseButton.connect('clicked()',
                                             self.browserWidget.dicomBrowser,
                                             "onRepairAction()")
        self.ui.clearDatabaseButton.connect('clicked()', self.onClearDatabase)

        # connect to the main window's dicom button
        mw = slicer.util.mainWindow()
        if mw:
            try:
                action = slicer.util.findChildren(mw,
                                                  name='LoadDICOMAction')[0]
                action.connect('triggered()', self.onOpenBrowserWidget)
            except IndexError:
                logging.error(
                    'Could not connect to the main window DICOM button')

        self.databaseRefreshRequestTimer = qt.QTimer()
        self.databaseRefreshRequestTimer.setSingleShot(True)
        # If not receiving new file for 2 seconds then a database update is triggered.
        self.databaseRefreshRequestTimer.setInterval(2000)
        self.databaseRefreshRequestTimer.connect('timeout()',
                                                 self.requestDatabaseRefresh)

        #
        # DICOM Plugins selection widget
        #
        self.ui.dicomPluginsFrame.collapsed = True
        self.pluginSelector = DICOMLib.DICOMPluginSelector(
            self.ui.dicomPluginsFrame)
        self.ui.dicomPluginsFrame.layout().addWidget(self.pluginSelector)
        self.checkBoxByPlugins = []

        for pluginClass in slicer.modules.dicomPlugins:
            self.checkBox = self.pluginSelector.checkBoxByPlugin[pluginClass]
            self.checkBox.connect('stateChanged(int)',
                                  self.onPluginStateChanged)
            self.checkBoxByPlugins.append(self.checkBox)