Example #1
0
    def __init__(self, parent=None):
        super(SelectDataPage, self).__init__(parent)

        self.setTitle('X-Socs')
        self.setSubTitle('New project : select data to load/import.')

        icon = XsocsIcons.getQPixmap('xsocs')
        self.setPixmap(Qt.QWizard.WatermarkPixmap, icon)
        icon = XsocsIcons.getQPixmap('logo')
        self.setPixmap(Qt.QWizard.LogoPixmap, icon)

        self.setTitle('Select input data.')

        self.__nextId = -1

        layout = Qt.QGridLayout(self)
        icon = XsocsIcons.getQIcon('logo')
        xsocsBn = Qt.QToolButton()
        xsocsBn.setIcon(icon)
        layout.addWidget(xsocsBn, 1, 1)
        layout.addWidget(Qt.QLabel('Load X-Socs Data (HDF5).'), 1, 2)

        icon = XsocsIcons.getQIcon('spec')
        specBn = Qt.QToolButton()
        specBn.setIcon(icon)
        layout.addWidget(specBn, 2, 1)
        layout.addWidget(Qt.QLabel('Import SPEC data.'), 2, 2)

        layout.setRowStretch(0, 1)
        layout.setRowStretch(3, 1)
        layout.setColumnStretch(3, 1)

        xsocsBn.clicked.connect(partial(self.__buttonClicked, source='XSOCS'))
        specBn.clicked.connect(partial(self.__buttonClicked, source='SPEC'))
Example #2
0
    def __init__(self, parent=None):
        super(IntroPage, self).__init__(parent)

        self.__nextId = XsocsWizard.OpenId

        self.setTitle('Welcome to X-SOCS.')
        self.setSubTitle('X-ray Strain Orientation Calculation Software')

        style = Qt.QApplication.style()
        icon = XsocsIcons.getQPixmap('xsocs')
        self.setPixmap(Qt.QWizard.WatermarkPixmap, icon)
        icon = XsocsIcons.getQPixmap('logo')
        self.setPixmap(Qt.QWizard.LogoPixmap, icon)

        layout = Qt.QGridLayout(self)
        icon = style.standardIcon(Qt.QStyle.SP_DialogOpenButton)
        openBn = Qt.QToolButton()
        openBn.setIcon(icon)
        layout.addWidget(openBn, 1, 1)
        layout.addWidget(Qt.QLabel('Open an existing project.'), 1, 2)

        icon = style.standardIcon(Qt.QStyle.SP_FileDialogNewFolder)
        newBn = Qt.QToolButton()
        newBn.setIcon(icon)
        layout.addWidget(newBn, 2, 1)
        layout.addWidget(Qt.QLabel('Create new project.'), 2, 2)

        layout.setRowStretch(0, 1)
        layout.setRowStretch(3, 1)
        layout.setColumnStretch(3, 1)

        openBn.clicked.connect(partial(self.__buttonClicked,
                                       nextId=XsocsWizard.OpenId))
        newBn.clicked.connect(partial(self.__buttonClicked,
                                      nextId=XsocsWizard.CreateId))
Example #3
0
    def changeWindowFlags(self, node, evt):
        if self.isFloating():
            # The dockWidget will automatically regain it's Qt::widget flag
            # when it becomes docked again
            self.setWindowFlags(qt.Qt.Window | qt.Qt.CustomizeWindowHint
                                | qt.Qt.WindowMaximizeButtonHint)
            # setWindowFlags calls setParent() when changing the flags for a
            # window, causing the widget to be hidden, so:
            self.show()

            # Custom title bar:
            self.titleBar = qt.QWidget()
            self.titleBar.setAutoFillBackground(True)
            self.titleBar.setStyleSheet("QWidget {font: bold; font-size: " +
                                        fontSize + "pt;}")
            pal = self.titleBar.palette()
            pal.setColor(qt.QPalette.Window, qt.QColor("lightgray"))
            self.titleBar.setPalette(pal)
            height = qt.QApplication.style().pixelMetric(
                qt.QStyle.PM_TitleBarHeight)
            self.titleBar.setMaximumHeight(height)
            layout = qt.QHBoxLayout()
            self.titleBar.setLayout(layout)

            buttonSize = qt.QSize(height - 16, height - 16)
            self.titleIcon = qt.QLabel()
            # self.titleIcon.setPixmap(self.parent().runIcon.pixmap(buttonSize))
            self.titleIcon.setPixmap(node.widget.dimIcon.pixmap(buttonSize))
            self.titleIcon.setVisible(True)
            layout.addWidget(self.titleIcon, 0)
            self.title = qt.QLabel(self.windowTitle())
            layout.addWidget(self.title, 0)
            layout.setContentsMargins(4, 4, 4, 4)
            layout.addStretch()

            self.dockButton = qt.QToolButton(self)
            self.dockButton.setIcon(qt.QApplication.style().standardIcon(
                qt.QStyle.SP_ToolBarVerticalExtensionButton))
            self.dockButton.setMaximumSize(buttonSize)
            self.dockButton.setAutoRaise(True)
            self.dockButton.clicked.connect(self.toggleFloating)
            self.dockButton.setToolTip('dock into the main window')
            layout.addWidget(self.dockButton, 0)

            self.maxButton = qt.QToolButton(self)
            self.maxButton.setIcon(qt.QApplication.style().standardIcon(
                qt.QStyle.SP_TitleBarMaxButton))
            self.maxButton.setMaximumSize(buttonSize)
            self.maxButton.setAutoRaise(True)
            self.maxButton.clicked.connect(self.toggleMax)
            layout.addWidget(self.maxButton, 0)

            self.setTitleBarWidget(self.titleBar)

        else:
            self.setTitleBarWidget(None)
            self.parent().setTabIcons()
Example #4
0
    def createIconPanel(self, parent):
        panel = qt.QWidget(parent)
        layout = qt.QGridLayout()
        # layout.setSizeConstraint(qt.QLayout.SetMinAndMaxSize)
        panel.setLayout(layout)

        self.tools = []

        import silx.resources

        icons = silx.resources.list_dir("gui/icons")
        # filter out sub-directories
        icons = filter(lambda x: not silx.resources.is_dir("gui/icons/" + x),
                       icons)
        # remove extension
        icons = [i.split(".")[0] for i in icons]
        # remove duplicated names
        icons = set(icons)
        # sort by names
        icons = sorted(icons)

        for i, icon_name in enumerate(icons):
            col, line = i / 10, i % 10
            icon = silx.gui.icons.getQIcon(icon_name)
            tool = qt.QToolButton(panel)
            tool.setIcon(icon)
            tool.setIconSize(qt.QSize(32, 32))
            tool.setToolTip(icon_name)
            layout.addWidget(tool, col, line)
            self.tools.append(tool)

        return panel
Example #5
0
    def createIconPanel(self, parent):
        panel = qt.QWidget(parent)
        layout = qt.QGridLayout()
        # layout.setSizeConstraint(qt.QLayout.SetMinAndMaxSize)
        panel.setLayout(layout)

        self.tools = []

        # Sort together animated and non animated icons
        fix_icons = self.getAllAvailableIcons()
        animated_icons = self.getAllAvailableAnimatedIcons()
        icons = []
        icons.extend([(i, "_") for i in fix_icons])
        icons.extend([(i, "anim") for i in animated_icons])
        icons = sorted(icons)

        for i, icon_info in enumerate(icons):
            icon_name, icon_kind = icon_info
            col, line = i / 10, i % 10
            if icon_kind == "anim":
                tool = AnimatedToolButton(panel)
                icon = silx.gui.icons.getAnimatedIcon(icon_name)
                tool.setToolTip("Animated icon '%s'" % icon_name)
            else:
                tool = qt.QToolButton(panel)
                icon = silx.gui.icons.getQIcon(icon_name)
                tool.setToolTip("Icon '%s'" % icon_name)
            tool.setIcon(icon)
            tool.setIconSize(qt.QSize(32, 32))
            layout.addWidget(tool, col, line)
            self.tools.append(tool)

        return panel
Example #6
0
    def __init__(self, parent, label, unit):
        qt.QObject.__init__(self, parent=parent)
        validator = validators.DoubleValidator(self)
        self.__label = qt.QLabel(parent)
        self.__label.setText(label)
        self.__lineEdit = qt.QLineEdit(parent)
        self.__lineEdit.setValidator(validator)
        self.__lineEdit.setAlignment(qt.Qt.AlignRight)
        self.__lineEdit.editingFinished.connect(self.__lineEditChanged)
        self.__unit = qt.QLabel(parent)
        self.__unit.setText(unit)
        self.__constraints = qt.QToolButton(parent)
        self.__constraints.setAutoRaise(True)
        self.__constraints.clicked.connect(self.__constraintsClicked)
        self.__model = None
        self.__wavelengthInvalidated = False
        self.__constraintsModel = None

        global _iconVariableFixed, _iconVariableConstrained, _iconVariableConstrainedOut
        if _iconVariableFixed is None:
            _iconVariableFixed = icons.getQIcon("pyfai:gui/icons/variable-fixed")
        if _iconVariableConstrained is None:
            _iconVariableConstrained = icons.getQIcon("pyfai:gui/icons/variable-constrained")
        if _iconVariableConstrainedOut is None:
            _iconVariableConstrainedOut = icons.getQIcon("pyfai:gui/icons/variable-constrained-out")
 def __init__(self, parent=None):
     assert isinstance(parent, qt.QWidget)
     qt.QWidgetAction.__init__(self, parent)
     button = qt.QToolButton(parent)
     button.setPopupMode(qt.QToolButton.MenuButtonPopup)
     self.setDefaultWidget(button)
     self.__button = button
Example #8
0
    def __createOptionsWidget(self):
        menu = qt.QMenu(self)

        # Load peak selection as file
        loadPeaksFromFile = qt.QAction(self)
        icon = icons.getQIcon('document-open')
        loadPeaksFromFile.setIcon(icon)
        loadPeaksFromFile.setText("Load peak selection from file")
        loadPeaksFromFile.triggered.connect(self.__loadPeaksFromFile)
        loadPeaksFromFile.setIconVisibleInMenu(True)
        menu.addAction(loadPeaksFromFile)

        # Save peak selection as file
        savePeaksAsFile = qt.QAction(self)
        icon = icons.getQIcon('document-save')
        savePeaksAsFile.setIcon(icon)
        savePeaksAsFile.setText("Save peak selection as file")
        savePeaksAsFile.triggered.connect(self.__savePeaksAsFile)
        savePeaksAsFile.setIconVisibleInMenu(True)
        menu.addAction(savePeaksAsFile)

        options = qt.QToolButton(self)
        icon = icons.getQIcon('pyfai:gui/icons/options')
        options.setIcon(icon)
        options.setPopupMode(qt.QToolButton.InstantPopup)
        options.setMenu(menu)
        return options
Example #9
0
    def __init__(self, parent, option, index):
        super(FitButton, self).__init__(parent, option, index)
        layout = Qt.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        icon = icons.getQIcon('plot-widget')
        button = Qt.QToolButton()
        button.setIcon(icon)
        button.clicked.connect(self.__clicked)
        layout.addWidget(button)

        button = Qt.QToolButton()
        style = Qt.QApplication.style()
        icon = style.standardIcon(Qt.QStyle.SP_DialogSaveButton)
        button.setIcon(icon)
        button.clicked.connect(self.__export)
        layout.addWidget(button)
        layout.addStretch(1)
Example #10
0
    def __init__(self, parent, option, index):
        super(QSpaceButton, self).__init__(parent, option, index)
        layout = Qt.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        icon = icons.getQIcon('item-ndim')
        button = Qt.QToolButton()
        button.setIcon(icon)
        layout.addWidget(button)
        layout.addStretch(1)

        button.clicked.connect(self.__clicked)
Example #11
0
    def __init__(self, parent, item):
        super(IsoSurfaceAddRemoveWidget, self).__init__(parent)
        self._item = item
        layout = qt.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)

        addBtn = qt.QToolButton()
        addBtn.setText('+')
        addBtn.setToolButtonStyle(qt.Qt.ToolButtonTextOnly)
        layout.addWidget(addBtn)
        addBtn.clicked.connect(self.__addClicked)

        removeBtn = qt.QToolButton()
        removeBtn.setText('-')
        removeBtn.setToolButtonStyle(qt.Qt.ToolButtonTextOnly)
        layout.addWidget(removeBtn)
        removeBtn.clicked.connect(self.__removeClicked)

        layout.addStretch(1)
Example #12
0
    def __init__(self, *args, **kwargs):
        super(QColorEditor, self).__init__(*args, **kwargs)
        layout = qt.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        button = qt.QToolButton()
        icon = qt.QIcon(qt.QPixmap(32, 32))
        button.setIcon(icon)
        layout.addWidget(button)
        button.clicked.connect(self.__showColorDialog)
        layout.addStretch(1)

        self.__color = None
        self.__previousColor = None
Example #13
0
    def __init__(self,
                 parent=None,
                 fileMode=None,
                 options=None,
                 appendPath=None,
                 noLabel=False,
                 **kwargs):
        """
        Extra arguments are passed to the QFileDialog constructor
        :param parent Qt.QWidget:
        :param fileMode Qt.QFileDialog.FileMode:
        :param options Qt.QFileDialog.Options:
        :param noLabel bool: Set to True to remove the label in front of the
            line edit.
        :param kwargs: Keyword arguments passed to the QFileDialog constructor.
        """
        super(FileChooser, self).__init__(parent)

        self.__selectedPath = None
        self.__appendPath = appendPath

        layout = Qt.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)

        lineEdit = StyledLineEdit()
        lineEdit.setAlignment(Qt.Qt.AlignLeft)
        lineEdit.setReadOnly(True)

        pickButton = Qt.QToolButton()
        style = Qt.QApplication.style()
        icon = style.standardIcon(Qt.QStyle.SP_DialogOpenButton)
        pickButton.setIcon(icon)

        if not noLabel:
            label = Qt.QLabel('Path :')
            layout.addWidget(label)

        layout.addWidget(lineEdit)
        layout.addWidget(pickButton)

        pickButton.clicked.connect(self.__pickFile)

        self.__fileDialog = dialog = Qt.QFileDialog(**kwargs)

        if fileMode is not None:
            dialog.setFileMode(fileMode)

        if options is not None:
            dialog.setOptions(options)
Example #14
0
    def __init__(self, parent, label, internalUnit, displayedUnit=None):
        qt.QObject.__init__(self, parent=parent)
        self.__label = qt.QLabel(parent)
        self.__label.setText(label)
        self.__quantity = QuantityEdit(parent)
        self.__quantity.setAlignment(qt.Qt.AlignRight)
        self.__unit = UnitLabel(parent)
        self.__unit.setUnitEditable(True)

        if displayedUnit is None:
            displayedUnit = internalUnit

        self.__quantity.setModelUnit(internalUnit)

        if isinstance(displayedUnit, units.Unit):
            model = DataModel()
            model.setValue(displayedUnit)
            displayedUnit = model
        elif isinstance(displayedUnit, DataModel):
            pass
        else:
            raise TypeError("Unsupported type %s" % type(displayedUnit))
        self.__unit.setUnitModel(displayedUnit)
        self.__quantity.setDisplayedUnitModel(displayedUnit)

        self.__constraints = qt.QToolButton(parent)
        self.__constraints.setAutoRaise(True)
        self.__constraints.clicked.connect(self.__constraintsClicked)
        self.__model = None
        self.__constraintsModel = None

        global _iconVariableFixed, _iconVariableConstrained, _iconVariableConstrainedOut
        if _iconVariableFixed is None:
            _iconVariableFixed = icons.getQIcon(
                "pyfai:gui/icons/variable-fixed")
        if _iconVariableConstrained is None:
            _iconVariableConstrained = icons.getQIcon(
                "pyfai:gui/icons/variable-constrained")
        if _iconVariableConstrainedOut is None:
            _iconVariableConstrainedOut = icons.getQIcon(
                "pyfai:gui/icons/variable-constrained-out")
    def _initThresholdGroupBox(self):
        """Init thresholding widgets"""

        self.belowThresholdAction = qt.QAction(
            icons.getQIcon('plot-roi-below'), 'Mask below threshold', None)
        self.belowThresholdAction.setToolTip(
            'Mask image where values are below given threshold')
        self.belowThresholdAction.setCheckable(True)
        self.belowThresholdAction.setChecked(True)

        self.betweenThresholdAction = qt.QAction(
            icons.getQIcon('plot-roi-between'), 'Mask within range', None)
        self.betweenThresholdAction.setToolTip(
            'Mask image where values are within given range')
        self.betweenThresholdAction.setCheckable(True)

        self.aboveThresholdAction = qt.QAction(
            icons.getQIcon('plot-roi-above'), 'Mask above threshold', None)
        self.aboveThresholdAction.setToolTip(
            'Mask image where values are above given threshold')
        self.aboveThresholdAction.setCheckable(True)

        self.thresholdActionGroup = qt.QActionGroup(self)
        self.thresholdActionGroup.setExclusive(True)
        self.thresholdActionGroup.addAction(self.belowThresholdAction)
        self.thresholdActionGroup.addAction(self.betweenThresholdAction)
        self.thresholdActionGroup.addAction(self.aboveThresholdAction)
        self.thresholdActionGroup.triggered.connect(
            self._thresholdActionGroupTriggered)

        self.loadColormapRangeAction = qt.QAction(
            icons.getQIcon('view-refresh'), 'Set min-max from colormap', None)
        self.loadColormapRangeAction.setToolTip(
            'Set min and max values from current colormap range')
        self.loadColormapRangeAction.setCheckable(False)
        self.loadColormapRangeAction.triggered.connect(
            self._loadRangeFromColormapTriggered)

        widgets = []
        for action in self.thresholdActionGroup.actions():
            btn = qt.QToolButton()
            btn.setDefaultAction(action)
            widgets.append(btn)

        spacer = qt.QWidget()
        spacer.setSizePolicy(qt.QSizePolicy.Expanding,
                             qt.QSizePolicy.Preferred)
        widgets.append(spacer)

        loadColormapRangeBtn = qt.QToolButton()
        loadColormapRangeBtn.setDefaultAction(self.loadColormapRangeAction)
        widgets.append(loadColormapRangeBtn)

        toolBar = self._hboxWidget(*widgets, stretch=False)

        config = qt.QGridLayout()
        config.setContentsMargins(0, 0, 0, 0)

        self.minLineLabel = qt.QLabel("Min:", self)
        self.minLineEdit = FloatEdit(self, value=0)
        config.addWidget(self.minLineLabel, 0, 0)
        config.addWidget(self.minLineEdit, 0, 1)

        self.maxLineLabel = qt.QLabel("Max:", self)
        self.maxLineEdit = FloatEdit(self, value=0)
        config.addWidget(self.maxLineLabel, 1, 0)
        config.addWidget(self.maxLineEdit, 1, 1)

        self.applyMaskBtn = qt.QPushButton('Apply mask')
        self.applyMaskBtn.clicked.connect(self._maskBtnClicked)

        layout = qt.QVBoxLayout()
        layout.addWidget(toolBar)
        layout.addLayout(config)
        layout.addWidget(self.applyMaskBtn)

        self.thresholdGroup = qt.QGroupBox('Threshold')
        self.thresholdGroup.setLayout(layout)

        # Init widget state
        self._thresholdActionGroupTriggered(self.belowThresholdAction)
        return self.thresholdGroup
    def _initDrawGroupBox(self):
        """Init drawing tools widgets"""
        layout = qt.QVBoxLayout()

        self.browseAction = PanModeAction(self.plot, self.plot)
        self.addAction(self.browseAction)

        # Draw tools
        self.rectAction = qt.QAction(icons.getQIcon('shape-rectangle'),
                                     'Rectangle selection', None)
        self.rectAction.setToolTip(
            'Rectangle selection tool: (Un)Mask a rectangular region <b>R</b>')
        self.rectAction.setShortcut(qt.QKeySequence(qt.Qt.Key_R))
        self.rectAction.setCheckable(True)
        self.rectAction.triggered.connect(self._activeRectMode)
        self.addAction(self.rectAction)

        self.ellipseAction = qt.QAction(icons.getQIcon('shape-ellipse'),
                                        'Circle selection', None)
        self.ellipseAction.setToolTip(
            'Rectangle selection tool: (Un)Mask a circle region <b>R</b>')
        self.ellipseAction.setShortcut(qt.QKeySequence(qt.Qt.Key_R))
        self.ellipseAction.setCheckable(True)
        self.ellipseAction.triggered.connect(self._activeEllipseMode)
        self.addAction(self.ellipseAction)

        self.polygonAction = qt.QAction(icons.getQIcon('shape-polygon'),
                                        'Polygon selection', None)
        self.polygonAction.setShortcut(qt.QKeySequence(qt.Qt.Key_S))
        self.polygonAction.setToolTip(
            'Polygon selection tool: (Un)Mask a polygonal region <b>S</b><br>'
            'Left-click to place new polygon corners<br>'
            'Left-click on first corner to close the polygon')
        self.polygonAction.setCheckable(True)
        self.polygonAction.triggered.connect(self._activePolygonMode)
        self.addAction(self.polygonAction)

        self.pencilAction = qt.QAction(icons.getQIcon('draw-pencil'),
                                       'Pencil tool', None)
        self.pencilAction.setShortcut(qt.QKeySequence(qt.Qt.Key_P))
        self.pencilAction.setToolTip(
            'Pencil tool: (Un)Mask using a pencil <b>P</b>')
        self.pencilAction.setCheckable(True)
        self.pencilAction.triggered.connect(self._activePencilMode)
        self.addAction(self.pencilAction)

        self.drawActionGroup = qt.QActionGroup(self)
        self.drawActionGroup.setExclusive(True)
        self.drawActionGroup.addAction(self.rectAction)
        self.drawActionGroup.addAction(self.ellipseAction)
        self.drawActionGroup.addAction(self.polygonAction)
        self.drawActionGroup.addAction(self.pencilAction)

        actions = (self.browseAction, self.rectAction, self.ellipseAction,
                   self.polygonAction, self.pencilAction)
        drawButtons = []
        for action in actions:
            btn = qt.QToolButton()
            btn.setDefaultAction(action)
            drawButtons.append(btn)
        container = self._hboxWidget(*drawButtons)
        layout.addWidget(container)

        # Mask/Unmask radio buttons
        maskRadioBtn = qt.QRadioButton('Mask')
        maskRadioBtn.setToolTip(
            'Drawing masks with current level. Press <b>Ctrl</b> to unmask')
        maskRadioBtn.setChecked(True)

        unmaskRadioBtn = qt.QRadioButton('Unmask')
        unmaskRadioBtn.setToolTip(
            'Drawing unmasks with current level. Press <b>Ctrl</b> to mask')

        self.maskStateGroup = qt.QButtonGroup()
        self.maskStateGroup.addButton(maskRadioBtn, 1)
        self.maskStateGroup.addButton(unmaskRadioBtn, 0)

        self.maskStateWidget = self._hboxWidget(maskRadioBtn, unmaskRadioBtn)
        layout.addWidget(self.maskStateWidget)

        self.maskStateWidget.setHidden(True)

        # Pencil settings
        self.pencilSetting = self._createPencilSettings(None)
        self.pencilSetting.setVisible(False)
        layout.addWidget(self.pencilSetting)

        layout.addStretch(1)

        drawGroup = qt.QGroupBox('Draw tools')
        drawGroup.setLayout(layout)
        return drawGroup
Example #17
0
    def _initMaskGroupBox(self):
        """Init general mask operation widgets"""

        # Mask level
        self.levelSpinBox = qt.QSpinBox()
        self.levelSpinBox.setRange(1, self._maxLevelNumber)
        self.levelSpinBox.setToolTip(
            'Choose which mask level is edited.\n'
            'A mask can have up to 255 non-overlapping levels.')
        self.levelSpinBox.valueChanged[int].connect(self._updateColors)
        self._levelWidget = self._hboxWidget(qt.QLabel('Mask level:'),
                                             self.levelSpinBox)
        # Transparency
        self._transparencyWidget = self._initTransparencyWidget()

        style = qt.QApplication.style()

        def getIcon(*identifiyers):
            for i in identifiyers:
                if isinstance(i, str):
                    if qt.QIcon.hasThemeIcon(i):
                        return qt.QIcon.fromTheme(i)
                elif isinstance(i, qt.QIcon):
                    return i
                else:
                    return style.standardIcon(i)
            return qt.QIcon()

        undoAction = qt.QAction(self)
        undoAction.setText('Undo')
        icon = getIcon("edit-undo", qt.QStyle.SP_ArrowBack)
        undoAction.setIcon(icon)
        undoAction.setShortcut(qt.QKeySequence.Undo)
        undoAction.setToolTip('Undo last mask change <b>%s</b>' %
                              undoAction.shortcut().toString())
        self._mask.sigUndoable.connect(undoAction.setEnabled)
        undoAction.triggered.connect(self._mask.undo)

        redoAction = qt.QAction(self)
        redoAction.setText('Redo')
        icon = getIcon("edit-redo", qt.QStyle.SP_ArrowForward)
        redoAction.setIcon(icon)
        redoAction.setShortcut(qt.QKeySequence.Redo)
        redoAction.setToolTip('Redo last undone mask change <b>%s</b>' %
                              redoAction.shortcut().toString())
        self._mask.sigRedoable.connect(redoAction.setEnabled)
        redoAction.triggered.connect(self._mask.redo)

        loadAction = qt.QAction(self)
        loadAction.setText('Load...')
        icon = icons.getQIcon("document-open")
        loadAction.setIcon(icon)
        loadAction.setToolTip('Load mask from file')
        loadAction.triggered.connect(self._loadMask)

        saveAction = qt.QAction(self)
        saveAction.setText('Save...')
        icon = icons.getQIcon("document-save")
        saveAction.setIcon(icon)
        saveAction.setToolTip('Save mask to file')
        saveAction.triggered.connect(self._saveMask)

        invertAction = qt.QAction(self)
        invertAction.setText('Invert')
        icon = icons.getQIcon("mask-invert")
        invertAction.setIcon(icon)
        invertAction.setShortcut(qt.Qt.CTRL + qt.Qt.Key_I)
        invertAction.setToolTip('Invert current mask <b>%s</b>' %
                                invertAction.shortcut().toString())
        invertAction.triggered.connect(self._handleInvertMask)

        clearAction = qt.QAction(self)
        clearAction.setText('Clear')
        icon = icons.getQIcon("mask-clear")
        clearAction.setIcon(icon)
        clearAction.setShortcut(qt.QKeySequence.Delete)
        clearAction.setToolTip('Clear current mask level <b>%s</b>' %
                               clearAction.shortcut().toString())
        clearAction.triggered.connect(self._handleClearMask)

        clearAllAction = qt.QAction(self)
        clearAllAction.setText('Clear all')
        icon = icons.getQIcon("mask-clear-all")
        clearAllAction.setIcon(icon)
        clearAllAction.setToolTip('Clear all mask levels')
        clearAllAction.triggered.connect(self.resetSelectionMask)

        # Buttons group
        margin1 = qt.QWidget(self)
        margin1.setMinimumWidth(6)
        margin2 = qt.QWidget(self)
        margin2.setMinimumWidth(6)

        actions = (loadAction, saveAction, margin1, undoAction, redoAction,
                   margin2, invertAction, clearAction, clearAllAction)
        widgets = []
        for action in actions:
            if isinstance(action, qt.QWidget):
                widgets.append(action)
                continue
            btn = qt.QToolButton()
            btn.setDefaultAction(action)
            widgets.append(btn)
            if action is clearAllAction:
                self._clearAllBtn = btn
        container = self._hboxWidget(*widgets)
        container.layout().setSpacing(1)

        layout = qt.QVBoxLayout()
        layout.addWidget(container)
        layout.addWidget(self._levelWidget)
        layout.addWidget(self._transparencyWidget)
        layout.addStretch(1)

        maskGroup = qt.QGroupBox('Mask')
        maskGroup.setLayout(layout)
        return maskGroup
Example #18
0
    def __init__(self, parent, label, internalUnit, displayedUnit=None):
        qt.QObject.__init__(self, parent=parent)
        self.__label = label
        self.__labelWidget = qt.QLabel(parent)
        self.__labelWidget.setText("%s:" % label)
        self.__quantity = QuantityEdit(parent)
        self.__quantity.setAlignment(qt.Qt.AlignRight)
        self.__unit = UnitLabel(parent)
        self.__unit.setUnitEditable(True)
        self.__min = qt.QToolButton(parent)
        self.__min.setFixedWidth(12)
        self.__min.setAutoRaise(True)
        self.__min.clicked.connect(self.__dropContraintsOnMin)
        self.__max = qt.QToolButton(parent)
        self.__max.setAutoRaise(True)
        self.__max.setFixedWidth(12)
        self.__max.clicked.connect(self.__dropContraintsOnMax)
        self.__defaultConstraintsModel = None

        self.__subLayout = qt.QHBoxLayout()
        self.__subLayout.setSpacing(0)
        self.__subLayout.setContentsMargins(0, 0, 0, 0)
        self.__subLayout.addWidget(self.__min)
        self.__subLayout.addWidget(self.__quantity)
        self.__subLayout.addWidget(self.__max)

        if displayedUnit is None:
            displayedUnit = internalUnit

        self.__quantity.setModelUnit(internalUnit)

        if isinstance(displayedUnit, units.Unit):
            model = DataModel()
            model.setValue(displayedUnit)
            displayedUnit = model
        elif isinstance(displayedUnit, DataModel):
            pass
        else:
            raise TypeError("Unsupported type %s" % type(displayedUnit))
        self.__units = internalUnit, displayedUnit
        self.__unit.setUnitModel(displayedUnit)
        self.__quantity.setDisplayedUnitModel(displayedUnit)

        self.__constraints = qt.QToolButton(parent)
        self.__constraints.setAutoRaise(True)
        self.__constraints.clicked.connect(self.__constraintsClicked)
        self.__model = None
        self.__constraintsModel = None

        if self._iconVariableFixed is None:
            self._iconVariableFixed = icons.getQIcon("pyfai:gui/icons/variable-fixed")
        if self._iconVariableConstrained is None:
            self._iconVariableConstrained = icons.getQIcon("pyfai:gui/icons/variable-constrained")
        if self._iconVariableConstrainedOut is None:
            self._iconVariableConstrainedOut = icons.getQIcon("pyfai:gui/icons/variable-constrained-out")
        if self._iconConstraintMin is None:
            self._iconConstraintMin = icons.getQIcon("pyfai:gui/icons/constraint-min")
        if self._iconConstraintNoMin is None:
            self._iconConstraintNoMin = icons.getQIcon("pyfai:gui/icons/constraint-no-min")
        if self._iconConstraintMax is None:
            self._iconConstraintMax = icons.getQIcon("pyfai:gui/icons/constraint-max")
        if self._iconConstraintNoMax is None:
            self._iconConstraintNoMax = icons.getQIcon("pyfai:gui/icons/constraint-no-max")
Example #19
0
    def _initThresholdGroupBox(self):
        """Init thresholding widgets"""
        layout = qt.QVBoxLayout()

        # Thresholing

        self.belowThresholdAction = qt.QAction(
            icons.getQIcon('plot-roi-below'), 'Mask below threshold', None)
        self.belowThresholdAction.setToolTip(
            'Mask image where values are below given threshold')
        self.belowThresholdAction.setCheckable(True)
        self.belowThresholdAction.triggered[bool].connect(
            self._belowThresholdActionTriggered)

        self.betweenThresholdAction = qt.QAction(
            icons.getQIcon('plot-roi-between'), 'Mask within range', None)
        self.betweenThresholdAction.setToolTip(
            'Mask image where values are within given range')
        self.betweenThresholdAction.setCheckable(True)
        self.betweenThresholdAction.triggered[bool].connect(
            self._betweenThresholdActionTriggered)

        self.aboveThresholdAction = qt.QAction(
            icons.getQIcon('plot-roi-above'), 'Mask above threshold', None)
        self.aboveThresholdAction.setToolTip(
            'Mask image where values are above given threshold')
        self.aboveThresholdAction.setCheckable(True)
        self.aboveThresholdAction.triggered[bool].connect(
            self._aboveThresholdActionTriggered)

        self.thresholdActionGroup = qt.QActionGroup(self)
        self.thresholdActionGroup.setExclusive(False)
        self.thresholdActionGroup.addAction(self.belowThresholdAction)
        self.thresholdActionGroup.addAction(self.betweenThresholdAction)
        self.thresholdActionGroup.addAction(self.aboveThresholdAction)
        self.thresholdActionGroup.triggered.connect(
            self._thresholdActionGroupTriggered)

        self.loadColormapRangeAction = qt.QAction(
            icons.getQIcon('view-refresh'), 'Set min-max from colormap', None)
        self.loadColormapRangeAction.setToolTip(
            'Set min and max values from current colormap range')
        self.loadColormapRangeAction.setCheckable(False)
        self.loadColormapRangeAction.triggered.connect(
            self._loadRangeFromColormapTriggered)

        widgets = []
        for action in self.thresholdActionGroup.actions():
            btn = qt.QToolButton()
            btn.setDefaultAction(action)
            widgets.append(btn)

        spacer = qt.QWidget()
        spacer.setSizePolicy(qt.QSizePolicy.Expanding,
                             qt.QSizePolicy.Preferred)
        widgets.append(spacer)

        loadColormapRangeBtn = qt.QToolButton()
        loadColormapRangeBtn.setDefaultAction(self.loadColormapRangeAction)
        widgets.append(loadColormapRangeBtn)

        container = self._hboxWidget(*widgets, stretch=False)
        layout.addWidget(container)

        form = qt.QFormLayout()

        self.minLineEdit = qt.QLineEdit()
        self.minLineEdit.setText('0')
        self.minLineEdit.setValidator(qt.QDoubleValidator(self))
        self.minLineEdit.setEnabled(False)
        form.addRow('Min:', self.minLineEdit)

        self.maxLineEdit = qt.QLineEdit()
        self.maxLineEdit.setText('0')
        self.maxLineEdit.setValidator(qt.QDoubleValidator(self))
        self.maxLineEdit.setEnabled(False)
        form.addRow('Max:', self.maxLineEdit)

        self.applyMaskBtn = qt.QPushButton('Apply mask')
        self.applyMaskBtn.clicked.connect(self._maskBtnClicked)
        self.applyMaskBtn.setEnabled(False)
        form.addRow(self.applyMaskBtn)

        self.maskNanBtn = qt.QPushButton('Mask not finite values')
        self.maskNanBtn.setToolTip('Mask Not a Number and infinite values')
        self.maskNanBtn.clicked.connect(self._maskNotFiniteBtnClicked)
        form.addRow(self.maskNanBtn)

        thresholdWidget = qt.QWidget()
        thresholdWidget.setLayout(form)
        layout.addWidget(thresholdWidget)

        layout.addStretch(1)

        self.thresholdGroup = qt.QGroupBox('Threshold')
        self.thresholdGroup.setLayout(layout)
        return self.thresholdGroup
Example #20
0
    def __init__(self, **kwargs):
        super(XsocsPlot2D, self).__init__(**kwargs)

        self.setActiveCurveHandling(False)
        self.setKeepDataAspectRatio(True)

        self.__sigPlotConnected = False
        self.__pointSelectionEnabled = False
        self.__showSelectedCoordinates = False
        self.__showMousePosition = False

        self.__logScatter = False
        self.__colormap = cm.jet
        self.__values = {}
        self.__cmapDialog = None

        pointDock = self.__pointWidget = DoublePointDock()

        features = (Qt.QDockWidget.DockWidgetVerticalTitleBar
                    | Qt.QDockWidget.DockWidgetClosable)
        pointDock.setFeatures(features)
        pointDock.sizeHint = lambda: Qt.QSize()
        self.addDockWidget(Qt.Qt.BottomDockWidgetArea, pointDock)
        pointDockAction = pointDock.toggleViewAction()
        pointDockAction.setIcon(getQIcon('crosshair'))
        pointDockAction.setIconVisibleInMenu(True)

        pointDockBn = Qt.QToolButton()
        pointDockBn.setDefaultAction(pointDockAction)
        closeButton = Qt.QToolButton()
        style = Qt.QApplication.style()
        icon = style.standardIcon(Qt.QStyle.SP_TitleBarCloseButton)
        closeButton.setIcon(icon)
        closeButton.setFixedSize(closeButton.iconSize())
        closeButton.clicked.connect(pointDockAction.trigger)
        pointDock.setTitleBarWidget(closeButton)

        toolbars = self.findChildren(Qt.QToolBar)
        for toolbar in toolbars:
            toolbar.hide()

        centralWid = self.centralWidget()

        centralWid.installEventFilter(self)

        self.__optionsBase = optionsBase = Qt.QWidget(centralWid)
        optionsLayout = Qt.QHBoxLayout(optionsBase)
        optionsLayout.setContentsMargins(0, 0, 0, 0)
        optionsLayout.setSpacing(0)

        style = Qt.QApplication.style()
        size = style.pixelMetric(Qt.QStyle.PM_SmallIconSize)
        icon = style.standardIcon(Qt.QStyle.SP_ArrowRight)
        showBarBn = Qt.QToolButton()
        showBarBn.setIcon(icon)
        showBarBn.setFixedWidth(size)
        showBarBn.clicked.connect(self.__showBarBnClicked)
        showBarBn.setAutoFillBackground(True)
        self.__hidden = True
        self.__firstShow = True

        self.__optionsBaseA = optionsBaseA = Qt.QWidget()
        optionsLayoutA = Qt.QHBoxLayout(optionsBaseA)
        optionsLayoutA.setContentsMargins(0, 0, 0, 0)
        optionsLayoutA.setSpacing(0)
        rstZoomAction = self.resetZoomAction
        rstToolBn = Qt.QToolButton()
        rstToolBn.setDefaultAction(rstZoomAction)

        optionsLayoutA.addWidget(rstToolBn)
        optionsLayoutA.addWidget(showBarBn)

        self.__optionsBaseB = optionsBaseB = Qt.QWidget()
        optionsLayoutB = Qt.QHBoxLayout(optionsBaseB)
        optionsLayoutB.setContentsMargins(0, 0, 0, 0)
        optionsLayoutB.setSpacing(0)

        # coordinates dock action
        pointDockBn = Qt.QToolButton()
        pointDockBn.setDefaultAction(pointDockAction)
        optionsLayoutB.addWidget(pointDockBn)

        # colormap dialog action
        self.__colormapBn = colormapBn = Qt.QToolButton()
        colormapBn.setDisabled(True)
        colormapBn.setIcon(getQIcon('colormap'))
        colormapBn.clicked.connect(self.__colormapBnClicked)
        optionsLayoutB.addWidget(colormapBn)

        icon = getKmapIcon('gears')
        options = Qt.QToolButton()

        options.setToolTip('Options')
        options.setIcon(icon)
        options.setPopupMode(Qt.QToolButton.InstantPopup)

        menu = Qt.QMenu()

        # save scatter as 3D
        self.__save2DAction = action = Qt.QAction(
            getKmapIcon('save_2dscatter'), 'Save "2D" scatter', self)
        action.setIconVisibleInMenu(True)
        action.triggered.connect(self.__save2DTriggered)
        action.setEnabled(False)
        menu.addAction(action)

        # save to file action
        try:
            action = self.getSaveAction()
        except AttributeError:
            action = self.saveAction
        action.setIconVisibleInMenu(True)
        menu.addAction(action)

        # print action
        try:
            action = self.getPrintAction()
        except AttributeError:
            action = self.printAction
        action.setIconVisibleInMenu(True)
        menu.addAction(action)

        # screenshot action
        try:
            action = self.getCopyAction()
        except AttributeError:
            action = self.copyAction
        action.setIconVisibleInMenu(True)
        menu.addAction(action)

        # grid action
        try:
            action = self.getGridAction()
        except AttributeError:
            action = self.gridAction
        action.setIconVisibleInMenu(True)
        menu.addAction(action)

        # crosshair action
        try:
            action = self.getCrosshairAction()
        except AttributeError:
            action = self.crosshairAction
        action.setIconVisibleInMenu(True)
        menu.addAction(action)

        # pan action
        try:
            action = self.getPanWithArrowKeysAction()
        except AttributeError:
            action = self.panWithArrowKeysAction
        action.setIconVisibleInMenu(True)
        menu.addAction(action)

        # # x log scale
        # self.xAxisLogarithmicAction.setIconVisibleInMenu(True)
        # menu.addAction(self.xAxisLogarithmicAction)
        #
        # # y log scale
        # self.yAxisLogarithmicAction.setIconVisibleInMenu(True)
        # menu.addAction(self.yAxisLogarithmicAction)

        # x autoscale action
        self.xAxisAutoScaleAction.setIconVisibleInMenu(True)
        menu.addAction(self.xAxisAutoScaleAction)

        # y autoscale action
        self.yAxisAutoScaleAction.setIconVisibleInMenu(True)
        menu.addAction(self.yAxisAutoScaleAction)

        # curvestyle action
        self.curveStyleAction.setIconVisibleInMenu(True)
        menu.addAction(self.curveStyleAction)

        # aspect ratio action
        aspectMenu = self.keepDataAspectRatioButton.menu()
        if aspectMenu is not None:
            action = aspectMenu.menuAction()
            action.setIconVisibleInMenu(True)
            menu.addAction(action)
        else:
            self.keepDataAspectRatioAction.setIconVisibleInMenu(True)
            menu.addAction(self.keepDataAspectRatioAction)

        options.setMenu(menu)

        optionsLayoutB.addWidget(options)

        optionsLayout.addWidget(optionsBaseB)
        optionsLayout.addWidget(optionsBaseA)

        self.setShowMousePosition(self.__showMousePosition)
        self.setShowSelectedCoordinates(self.__showSelectedCoordinates)
        self.setPointSelectionEnabled(self.__pointSelectionEnabled)
Example #21
0
    def __init__(self, roiManager, parent=None):
        # TODO :
        # support multiple ROIs then batch them
        super(RectRoiWidget, self).__init__(parent)

        self.__roiToolBar = roiToolBar = roiManager.toolBar(rois=['rectangle'],
                                                            options=['show'])
        roiToolBar.setMovable(False)

        topLayout = Qt.QVBoxLayout(self)

        grpBox = GroupBox('ROI')
        layout = Qt.QGridLayout(grpBox)

        row = 0
        layout.addWidget(roiToolBar, row, 0, 1, 2, Qt.Qt.AlignTop)

        row += 1
        self._xEdit = edit = StyledLineEdit(nChar=6)
        edit.setReadOnly(True)
        layout.addWidget(Qt.QLabel('x='), row, 0, Qt.Qt.AlignTop)
        layout.addWidget(edit, row, 1, Qt.Qt.AlignTop)

        row += 1
        self._yEdit = edit = StyledLineEdit(nChar=6)
        edit.setReadOnly(True)
        layout.addWidget(Qt.QLabel('y='), row, 0, Qt.Qt.AlignTop)
        layout.addWidget(edit, row, 1, Qt.Qt.AlignTop)

        row += 1
        self._wEdit = edit = StyledLineEdit(nChar=6)
        edit.setReadOnly(True)
        layout.addWidget(Qt.QLabel('w='), row, 0, Qt.Qt.AlignTop)
        layout.addWidget(edit, row, 1, Qt.Qt.AlignTop)

        row += 1
        self._hEdit = edit = StyledLineEdit(nChar=6)
        edit.setReadOnly(True)
        layout.addWidget(Qt.QLabel('h='), row, 0, Qt.Qt.AlignTop)
        layout.addWidget(edit, row, 1, Qt.Qt.AlignTop)

        row += 1

        hLayout = Qt.QHBoxLayout()

        style = Qt.QApplication.style()

        icon = style.standardIcon(Qt.QStyle.SP_DialogApplyButton)
        self.__applyBn = applyBn = Qt.QToolButton()
        applyBn.setToolTip('Apply ROI')
        applyBn.setStatusTip('Apply ROI')
        applyBn.setIcon(icon)
        applyBn.setToolButtonStyle(Qt.Qt.ToolButtonTextBesideIcon)
        applyBn.setText('To Q Space')
        applyBn.setEnabled(False)
        hLayout.addWidget(applyBn)
        applyBn.clicked.connect(self.__applyRoi)

        icon = style.standardIcon(Qt.QStyle.SP_DialogCloseButton)
        self.__discardBn = discardBn = Qt.QToolButton()
        discardBn.setToolTip('Discard ROI')
        discardBn.setStatusTip('Discard ROI')
        discardBn.setIcon(icon)
        discardBn.setEnabled(False)
        hLayout.addWidget(discardBn, Qt.Qt.AlignRight)
        discardBn.clicked.connect(self.__discardRoi)

        layout.addLayout(hLayout, row, 0, 1, 2, Qt.Qt.AlignCenter)

        # topLayout.setSizeConstraint(Qt.QLayout.SetMinimumSize)

        topLayout.addWidget(grpBox)
        topLayout.addStretch(100)

        # TODO : weakref
        self.__roiManager = roiManager
        roiManager.sigRoiDrawingFinished.connect(self.__roiDrawingFinished,
                                                 Qt.Qt.QueuedConnection)
        roiManager.sigRoiRemoved.connect(self.__roiRemoved,
                                         Qt.Qt.QueuedConnection)
        roiManager.sigRoiMoved.connect(self.__roiMoved,
                                       Qt.Qt.QueuedConnection)
Example #22
0
    def __init__(self, parent=None):
        qt.QToolBar.__init__(self, parent)

        self.__compareWidget = None

        menu = qt.QMenu(self)
        self.__visualizationToolButton = qt.QToolButton(self)
        self.__visualizationToolButton.setMenu(menu)
        self.__visualizationToolButton.setPopupMode(
            qt.QToolButton.InstantPopup)
        self.addWidget(self.__visualizationToolButton)
        self.__visualizationGroup = qt.QActionGroup(self)
        self.__visualizationGroup.setExclusive(True)
        self.__visualizationGroup.triggered.connect(
            self.__visualizationModeChanged)

        icon = icons.getQIcon("compare-mode-a")
        action = qt.QAction(icon, "Display the first image only", self)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        action.setShortcut(qt.QKeySequence(qt.Qt.Key_A))
        action.setProperty("mode", VisualizationMode.ONLY_A)
        menu.addAction(action)
        self.__aModeAction = action
        self.__visualizationGroup.addAction(action)

        icon = icons.getQIcon("compare-mode-b")
        action = qt.QAction(icon, "Display the second image only", self)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        action.setShortcut(qt.QKeySequence(qt.Qt.Key_B))
        action.setProperty("mode", VisualizationMode.ONLY_B)
        menu.addAction(action)
        self.__bModeAction = action
        self.__visualizationGroup.addAction(action)

        icon = icons.getQIcon("compare-mode-vline")
        action = qt.QAction(icon, "Vertical compare mode", self)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        action.setShortcut(qt.QKeySequence(qt.Qt.Key_V))
        action.setProperty("mode", VisualizationMode.VERTICAL_LINE)
        menu.addAction(action)
        self.__vlineModeAction = action
        self.__visualizationGroup.addAction(action)

        icon = icons.getQIcon("compare-mode-hline")
        action = qt.QAction(icon, "Horizontal compare mode", self)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        action.setShortcut(qt.QKeySequence(qt.Qt.Key_H))
        action.setProperty("mode", VisualizationMode.HORIZONTAL_LINE)
        menu.addAction(action)
        self.__hlineModeAction = action
        self.__visualizationGroup.addAction(action)

        icon = icons.getQIcon("compare-mode-rb-channel")
        action = qt.QAction(icon, "Blue/red compare mode (additive mode)",
                            self)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        action.setShortcut(qt.QKeySequence(qt.Qt.Key_C))
        action.setProperty("mode", VisualizationMode.COMPOSITE_RED_BLUE_GRAY)
        menu.addAction(action)
        self.__brChannelModeAction = action
        self.__visualizationGroup.addAction(action)

        icon = icons.getQIcon("compare-mode-rbneg-channel")
        action = qt.QAction(icon,
                            "Yellow/cyan compare mode (subtractive mode)",
                            self)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        action.setShortcut(qt.QKeySequence(qt.Qt.Key_W))
        action.setProperty("mode",
                           VisualizationMode.COMPOSITE_RED_BLUE_GRAY_NEG)
        menu.addAction(action)
        self.__ycChannelModeAction = action
        self.__visualizationGroup.addAction(action)

        icon = icons.getQIcon("compare-mode-a-minus-b")
        action = qt.QAction(icon, "Raw A minus B compare mode", self)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        action.setShortcut(qt.QKeySequence(qt.Qt.Key_W))
        action.setProperty("mode", VisualizationMode.COMPOSITE_A_MINUS_B)
        menu.addAction(action)
        self.__ycChannelModeAction = action
        self.__visualizationGroup.addAction(action)

        menu = qt.QMenu(self)
        self.__alignmentToolButton = qt.QToolButton(self)
        self.__alignmentToolButton.setMenu(menu)
        self.__alignmentToolButton.setPopupMode(qt.QToolButton.InstantPopup)
        self.addWidget(self.__alignmentToolButton)
        self.__alignmentGroup = qt.QActionGroup(self)
        self.__alignmentGroup.setExclusive(True)
        self.__alignmentGroup.triggered.connect(self.__alignmentModeChanged)

        icon = icons.getQIcon("compare-align-origin")
        action = qt.QAction(icon, "Align images on their upper-left pixel",
                            self)
        action.setProperty("mode", AlignmentMode.ORIGIN)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        self.__originAlignAction = action
        menu.addAction(action)
        self.__alignmentGroup.addAction(action)

        icon = icons.getQIcon("compare-align-center")
        action = qt.QAction(icon, "Center images", self)
        action.setProperty("mode", AlignmentMode.CENTER)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        self.__centerAlignAction = action
        menu.addAction(action)
        self.__alignmentGroup.addAction(action)

        icon = icons.getQIcon("compare-align-stretch")
        action = qt.QAction(icon, "Stretch the second image on the first one",
                            self)
        action.setProperty("mode", AlignmentMode.STRETCH)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        self.__stretchAlignAction = action
        menu.addAction(action)
        self.__alignmentGroup.addAction(action)

        icon = icons.getQIcon("compare-align-auto")
        action = qt.QAction(icon, "Auto-alignment of the second image", self)
        action.setProperty("mode", AlignmentMode.AUTO)
        action.setIconVisibleInMenu(True)
        action.setCheckable(True)
        self.__autoAlignAction = action
        menu.addAction(action)
        if sift is None:
            action.setEnabled(False)
            action.setToolTip("Sift module is not available")
        self.__alignmentGroup.addAction(action)

        icon = icons.getQIcon("compare-keypoints")
        action = qt.QAction(icon, "Display/hide alignment keypoints", self)
        action.setCheckable(True)
        action.triggered.connect(self.__keypointVisibilityChanged)
        self.addAction(action)
        self.__displayKeypoints = action
Example #23
0
    def __init__(self,
                 spec_file=None,
                 img_dir=None,
                 spec_version=1,
                 output_dir=None,
                 tmp_dir=None,
                 **kwargs):
        super(MergeWidget, self).__init__(**kwargs)

        Qt.QGridLayout(self)

        # ################
        # input QGroupBox
        # ################

        if spec_file is not None:
            specFile = spec_file
        else:
            specFile = ''

        if img_dir is not None:
            imgDir = img_dir
        else:
            imgDir = ''

        if spec_version is not None:
            specVersion = spec_version
        else:
            specVersion = self._defaultVersion

        if output_dir is not None:
            outputDir = output_dir
        else:
            outputDir = ''

        # parameters
        self.__input = {
            'specfile': specFile,
            'imgdir': imgDir,
            'version': specVersion,
            'padding': None,
            'offset': None
        }

        self.__output = {'outdir': outputDir, 'prefix': ''}

        inputGbx = GroupBox("Input")
        layout = Qt.QGridLayout(inputGbx)
        self.layout().addWidget(inputGbx, 0, 0, Qt.Qt.AlignTop)

        first_col = 0
        file_bn_col = 4
        last_col = file_bn_col + 1

        spec_row = 0
        img_path_row = 1
        version_row = 2
        apply_bn_row = 3

        # spec file input
        specFileChooser = FileChooser(fileMode=Qt.QFileDialog.ExistingFile,
                                      noLabel=True)
        specFileChooser.lineEdit.setText(specFile)
        specFileChooser.sigSelectionChanged.connect(self.__slotSpecFileChanged)
        layout.addWidget(Qt.QLabel('Spec file :'), spec_row, 0)
        layout.addWidget(specFileChooser, spec_row, 1)

        # image folder input
        imgDirChooser = FileChooser(fileMode=Qt.QFileDialog.Directory,
                                    noLabel=True)
        imgDirChooser.lineEdit.setText(imgDir)
        imgDirChooser.sigSelectionChanged.connect(self.__slotImgDirChanged)
        layout.addWidget(Qt.QLabel('Img dir. :'), img_path_row, 0)
        layout.addWidget(imgDirChooser, img_path_row, 1)

        # version selection
        optionLayout = Qt.QHBoxLayout()
        optionLayout.addStretch(1)

        lab = Qt.QLabel('Version :')
        self.__versionCBx = versionCBx = Qt.QComboBox()

        for version in range(len(self._versions)):
            versionCBx.addItem(str(version))
        versionCBx.addItem('')
        optionLayout.addWidget(lab, Qt.Qt.AlignLeft)
        optionLayout.addWidget(versionCBx, Qt.Qt.AlignLeft)

        # filename padding for the nextNr counter
        self.__padSpinBox = padSpinBox = Qt.QSpinBox()
        optionLayout.addWidget(_vLine())
        optionLayout.addWidget(Qt.QLabel('nextNr padding:'))
        optionLayout.addWidget(padSpinBox, Qt.Qt.AlignLeft)
        padSpinBox.valueChanged[int].connect(self.__slotPaddingValueChanged)

        # filename offset for the nextNr counter
        self.__nextNrSpinBox = nextNrSpinBox = Qt.QSpinBox()
        nextNrSpinBox.setMinimum(-100)
        nextNrSpinBox.setMaximum(100)
        optionLayout.addWidget(_vLine())
        optionLayout.addWidget(Qt.QLabel('nextNr offset:'))
        optionLayout.addWidget(nextNrSpinBox, Qt.Qt.AlignLeft)
        nextNrSpinBox.valueChanged[int].connect(self.__slotNextNrValueChanged)

        optionLayout.addStretch(100)
        layout.addLayout(optionLayout, version_row, 0, 1, layout.columnCount(),
                         Qt.Qt.AlignLeft)

        # last row : apply button
        self.__parseBn = parseBn = FixedSizePushButon('Parse file')
        parseBn.clicked.connect(self.__slotParseBnClicked,
                                Qt.Qt.QueuedConnection)
        layout.addWidget(parseBn, apply_bn_row, 0, 1, last_col - first_col,
                         Qt.Qt.AlignHCenter)

        # ################
        # scans + edf QGroupBox
        # ################
        self.__scansGbx = scansGbx = GroupBox("Spec + EDF")
        grpLayout = Qt.QHBoxLayout(scansGbx)
        self.layout().addWidget(scansGbx, 1, 0,
                                Qt.Qt.AlignLeft | Qt.Qt.AlignTop)

        # ===========
        # valid scans
        # ===========
        scanLayout = Qt.QGridLayout()
        grpLayout.addLayout(scanLayout)

        hLayout = Qt.QHBoxLayout()
        label = Qt.QLabel('<span style=" font-weight:600; color:#00916a;">'
                          'Matched scans</span>')
        label.setTextFormat(Qt.Qt.RichText)
        editScansBn = FixedSizePushButon('Edit')
        editScansBn.clicked.connect(self.__slotEditScansClicked)
        hLayout.addWidget(label)
        hLayout.addWidget(editScansBn)
        scanLayout.addLayout(hLayout, 0, 0, 1, 2)

        label = Qt.QLabel('Total :')
        self.__totalScansEdit = totalScansEdit = Qt.QLineEdit('0')
        totalScansEdit.setReadOnly(True)
        fm = totalScansEdit.fontMetrics()
        width = (fm.boundingRect('0123456').width() +
                 fm.boundingRect('00').width())
        totalScansEdit.setMaximumWidth(width)
        totalScansEdit.setAlignment(Qt.Qt.AlignRight)

        scanLayout.addWidget(label, 1, 0, Qt.Qt.AlignLeft)
        scanLayout.addWidget(totalScansEdit, 1, 1, Qt.Qt.AlignLeft)

        # ====

        label = Qt.QLabel('Selected :')
        self.__selectedScansEdit = selectedScansEdit = Qt.QLineEdit('0')
        selectedScansEdit.setReadOnly(True)
        fm = selectedScansEdit.fontMetrics()
        width = (fm.boundingRect('0123456').width() +
                 fm.boundingRect('00').width())
        selectedScansEdit.setMaximumWidth(width)
        selectedScansEdit.setAlignment(Qt.Qt.AlignRight)

        scanLayout.addWidget(label, 2, 0, Qt.Qt.AlignLeft)
        scanLayout.addWidget(selectedScansEdit, 2, 1, Qt.Qt.AlignLeft)

        # ===

        grpLayout.addWidget(_vLine())

        # ===========
        # "other" scans
        # ===========

        scanLayout = Qt.QGridLayout()
        grpLayout.addLayout(scanLayout)

        hLayout = Qt.QHBoxLayout()
        label = Qt.QLabel('<span style=" font-weight:600; color:#ff6600;">'
                          'Other scans</span>')
        otherScansBn = FixedSizePushButon('View')
        otherScansBn.clicked.connect(self.__slotOtherScansClicked)
        hLayout.addWidget(label)
        hLayout.addWidget(otherScansBn)

        scanLayout.addLayout(hLayout, 0, 0, 1, 2)

        label = Qt.QLabel('No match :')
        self.__noMatchScansEdit = noMatchScansEdit = Qt.QLineEdit('0')
        noMatchScansEdit.setReadOnly(True)
        fm = noMatchScansEdit.fontMetrics()
        width = (fm.boundingRect('0123456').width() +
                 fm.boundingRect('00').width())
        noMatchScansEdit.setMaximumWidth(width)
        noMatchScansEdit.setAlignment(Qt.Qt.AlignRight)

        scanLayout.addWidget(label, 1, 0, Qt.Qt.AlignLeft)
        scanLayout.addWidget(noMatchScansEdit, 1, 1, Qt.Qt.AlignLeft)

        # ====

        label = Qt.QLabel('No img info :')
        self.__noImgInfoEdit = noImgInfoEdit = Qt.QLineEdit('0')
        noImgInfoEdit.setReadOnly(True)
        fm = noImgInfoEdit.fontMetrics()
        width = (fm.boundingRect('0123456').width() +
                 fm.boundingRect('00').width())
        noImgInfoEdit.setMaximumWidth(width)
        noImgInfoEdit.setAlignment(Qt.Qt.AlignRight)

        scanLayout.addWidget(label, 2, 0, Qt.Qt.AlignLeft)
        scanLayout.addWidget(noImgInfoEdit, 2, 1, Qt.Qt.AlignLeft)

        # ===

        grpLayout.addWidget(_vLine())

        # ################
        # parameters
        # ################
        self.__acqParamsGbx = acqParamsGbx = GroupBox("Acq. Parameters")
        grpLayout = Qt.QVBoxLayout(acqParamsGbx)

        self.__acqParamWid = acqParamWid = AcqParamsWidget()
        self.layout().addWidget(acqParamsGbx, 2, 0,
                                Qt.Qt.AlignLeft | Qt.Qt.AlignTop)
        grpLayout.addWidget(acqParamWid)

        # ################
        # output options
        # ################

        self.__outputGbx = outputGbx = GroupBox("Output")
        layout = Qt.QGridLayout(outputGbx)
        self.layout().addWidget(outputGbx, 3, 0, Qt.Qt.AlignTop)

        # ===========
        # master
        # ===========

        lab = Qt.QLabel('Prefix :')
        self.__prefixEdit = prefixEdit = StyledLineEdit(nChar=20)
        prefixEdit.textChanged.connect(self.__slotPrefixChanged)
        hLayout = Qt.QHBoxLayout()
        layout.addLayout(hLayout, 0, 1, Qt.Qt.AlignLeft)
        resetPrefixBn = Qt.QToolButton()
        icon = Qt.qApp.style().standardIcon(Qt.QStyle.SP_BrowserReload)
        resetPrefixBn.setIcon(icon)
        resetPrefixBn.clicked.connect(self.__slotResetPrefixClicked)
        layout.addWidget(lab, 0, 0, Qt.Qt.AlignLeft)
        sp = prefixEdit.sizePolicy()
        sp.setHorizontalPolicy(Qt.QSizePolicy.Maximum)
        prefixEdit.setSizePolicy(sp)
        hLayout.addWidget(prefixEdit, Qt.Qt.AlignLeft)
        hLayout.addWidget(resetPrefixBn, Qt.Qt.AlignLeft)

        # ===========
        # output folder
        # ===========

        outDirChooser = FileChooser(fileMode=Qt.QFileDialog.Directory,
                                    noLabel=True)
        outDirChooser.lineEdit.setText(outputDir)
        outDirChooser.sigSelectionChanged.connect(self.__slotOutDirChanged)
        layout.addWidget(Qt.QLabel('Output directory :'), 1, 0)
        layout.addWidget(outDirChooser, 1, 1)

        # ################
        # merge button
        # ################

        self.__mergeBn = mergeBn = Qt.QPushButton('Merge')
        cancelBn = Qt.QPushButton('Cancel')
        hLayout = Qt.QHBoxLayout()
        self.layout().addLayout(hLayout, 4, 0, 1, 1,
                                Qt.Qt.AlignHCenter | Qt.Qt.AlignTop)
        hLayout.addWidget(mergeBn)
        hLayout.addWidget(cancelBn)
        mergeBn.clicked.connect(self.__slotMergeBnClicked)
        cancelBn.clicked.connect(self.reject)

        # #################
        # setting initial state
        # #################

        # scansGbx.setEnabled(False)
        # acqParamsGbx.setEnabled(False)
        # outputGbx.setEnabled(False)
        # mergeBn.setEnabled(False)
        parseBn.setEnabled(False)

        self.__merger = None
        self.__parser = None
        self.info_wid = None

        if tmp_dir is None:
            tmp_dir, delete_tmp, q_tmp_dir = _create_tmp_dir()
        else:
            delete_tmp = False
            q_tmp_dir = None

        self.__tmp_root = tmp_dir
        self.__delete_tmp_root = delete_tmp
        self.__q_tmp_dir = q_tmp_dir

        tmp_dir = os.path.join(self.__tmp_root, 'xsocs_merge')
        if not os.path.exists(tmp_dir):
            os.makedirs(tmp_dir)

        self.__tmp_dir_merge = tmp_dir

        print('Using temporary folder : {0}.'.format(tmp_dir))

        self.__widgetIsSetup = False

        self.__xsocs_h5 = None

        versionCBx.setCurrentIndex(spec_version)
        self.__slotVersionChanged(spec_version)
        versionCBx.currentIndexChanged[int].connect(self.__slotVersionChanged)

        self.__resetState()

        self.__sigParsed.connect(self.__slotParsed, Qt.Qt.QueuedConnection)