Example #1
0
    def setup(self):
        ScriptedLoadableModuleWidget.setup(self)

        # Load UI file
        moduleName = 'Home'
        scriptedModulesPath = os.path.dirname(
            slicer.util.modulePath(moduleName))
        path = os.path.join(scriptedModulesPath, 'Resources', 'UI',
                            moduleName + '.ui')

        self.Widget = slicer.util.loadUI(path)
        self.layout.addWidget(self.Widget)

        # Setup data buttons
        numberOfColumns = 2
        iconPath = os.path.join(
            os.path.dirname(__file__).replace('\\', '/'), 'Resources', 'Icons')
        desktop = qt.QDesktopWidget()
        mainScreenSize = desktop.availableGeometry(desktop.primaryScreen)
        iconSize = qt.QSize(mainScreenSize.width() / 15,
                            mainScreenSize.height() / 10)

        buttonsLayout = self.get('DataCollapsibleGroupBox').layout()
        columnIndex = 0
        rowIndex = 0

        files = {
            'annotation_25':
            os.path.join(scriptedModulesPath, 'CellLocatorData',
                         'annotation_25.nrrd'),
            'annotation_50':
            os.path.join(scriptedModulesPath, 'CellLocatorData',
                         'annotation_50.nrrd')
        }
        for (file, filepath) in files.iteritems():
            button = qt.QToolButton()
            button.setText(file)

            # Set thumbnail
            thumbnailFileName = os.path.join(scriptedModulesPath, 'Resources',
                                             'Icons', file + '.png')
            button.setIcon(qt.QIcon(thumbnailFileName))
            button.setIconSize(iconSize)
            button.setToolButtonStyle(qt.Qt.ToolButtonTextUnderIcon)
            qSize = qt.QSizePolicy()
            qSize.setHorizontalPolicy(qt.QSizePolicy.Expanding)
            button.setSizePolicy(qSize)

            button.name = '%sPushButton' % file
            buttonsLayout.addWidget(button, rowIndex, columnIndex)
            columnIndex += 1
            if columnIndex == numberOfColumns:
                rowIndex += 1
                columnIndex = 0
            button.connect('clicked()',
                           lambda p=filepath: slicer.util.loadVolume(p))
Example #2
0
    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.observerTags = []
        self.logic = SampleDataLogic(self.logMessage)

        numberOfColumns = 3
        iconPath = os.path.join(
            os.path.dirname(__file__).replace('\\', '/'), 'Resources', 'Icons')
        desktop = qt.QDesktopWidget()
        mainScreenSize = desktop.availableGeometry(desktop.primaryScreen)
        iconSize = qt.QSize(mainScreenSize.width() / 15,
                            mainScreenSize.height() / 10)

        categories = slicer.modules.sampleDataSources.keys()
        categories.sort()
        if 'BuiltIn' in categories:
            categories.remove('BuiltIn')
        categories.insert(0, 'BuiltIn')
        for category in categories:
            frame = ctk.ctkCollapsibleGroupBox(self.parent)
            self.layout.addWidget(frame)
            frame.title = category
            frame.name = '%sCollapsibleGroupBox' % category
            layout = qt.QGridLayout(frame)
            columnIndex = 0
            rowIndex = 0
            for source in slicer.modules.sampleDataSources[category]:
                name = source.sampleName
                if not name:
                    name = source.nodeNames[0]

                b = qt.QToolButton()
                b.setText(name)

                # Set thumbnail
                if source.thumbnailFileName:
                    # Thumbnail provided
                    thumbnailImage = source.thumbnailFileName
                else:
                    # Look for thumbnail image with the name of any node name with .png extension
                    thumbnailImage = None
                    for nodeName in source.nodeNames:
                        if not nodeName:
                            continue
                        thumbnailImageAttempt = os.path.join(
                            iconPath, nodeName + '.png')
                        if os.path.exists(thumbnailImageAttempt):
                            thumbnailImage = thumbnailImageAttempt
                            break
                if thumbnailImage and os.path.exists(thumbnailImage):
                    b.setIcon(qt.QIcon(thumbnailImage))

                b.setIconSize(iconSize)
                b.setToolButtonStyle(qt.Qt.ToolButtonTextUnderIcon)
                qSize = qt.QSizePolicy()
                qSize.setHorizontalPolicy(qt.QSizePolicy.Expanding)
                b.setSizePolicy(qSize)

                b.name = '%sPushButton' % name
                layout.addWidget(b, rowIndex, columnIndex)
                columnIndex += 1
                if columnIndex == numberOfColumns:
                    rowIndex += 1
                    columnIndex = 0
                if source.customDownloader:
                    b.connect('clicked()', source.customDownloader)
                else:
                    b.connect(
                        'clicked()',
                        lambda s=source: self.logic.downloadFromSource(s))

        self.log = qt.QTextEdit()
        self.log.readOnly = True
        self.layout.addWidget(self.log)
        self.logMessage('<p>Status: <i>Idle</i>\n')

        # Add spacer to layout
        self.layout.addStretch(1)