示例#1
0
    def __init__(self, parent, controller_widget, control_name):

        super(ListValuesEditor, self).__init__(parent)

        self.controller_widget = controller_widget
        self.control_name = control_name
        self.format = 'JSON'
        self.separator = ','
        self.modified = False

        layout = QtGui.QVBoxLayout()
        self.setLayout(layout)
        textedit = QtGui.QTextEdit()
        layout.addWidget(textedit)
        hlayout2 = QtGui.QHBoxLayout()
        layout.addLayout(hlayout2)

        hlayout2.addWidget(QtGui.QLabel('Format:'))
        format_c = QtGui.QComboBox()
        hlayout2.addWidget(format_c)
        hlayout2.addWidget(QtGui.QLabel('Separator:'))
        sep_c = QtGui.QComboBox()
        hlayout2.addWidget(sep_c)

        format_c.addItem('JSON')
        format_c.addItem('CSV')

        sep_c.addItem(',')
        sep_c.addItem(';')
        sep_c.addItem(' ')

        hlayout2.addStretch(1)
        ok = QtGui.QPushButton('OK')
        cancel = QtGui.QPushButton('Cancel')
        hlayout2.addWidget(ok)
        hlayout2.addWidget(cancel)

        ok.pressed.connect(self.accept)
        cancel.pressed.connect(self.reject)

        parent_controller = controller_widget.controller
        value = getattr(parent_controller, control_name)

        text = json.dumps(value)
        textedit.setText(text)

        self.textedit = textedit
        self.format_c = format_c
        self.separator_c = sep_c
        self.internal_change = False

        textedit.textChanged.connect(self.set_modified)
        format_c.currentIndexChanged.connect(self.format_changed)
        sep_c.currentIndexChanged.connect(self.separator_changed)
示例#2
0
    def _create_group_widget(self, group):
        group_widget = QtGui.QGroupBox()
        last_row = self._grid_layout.rowCount()
        self._grid_layout.addWidget(group_widget, last_row, 0, 1, 2)
        lay1 = QtGui.QVBoxLayout()
        lay1.setContentsMargins(0, 0, 0, 0)
        lay2 = QtGui.QHBoxLayout()
        lay1.addLayout(lay2)
        lay2.setContentsMargins(10, 0, 0, 0)
        lay2.addWidget(QtGui.QLabel('<html><em>%s</em></html>' % group))
        lay2.addStretch(1)
        icon = QtGui.QIcon()
        icon.addPixmap(
            QtGui.QPixmap(_fromUtf8(":/soma_widgets_icons/nav_down")),
            QtGui.QIcon.Normal, QtGui.QIcon.Off)
        group_widget.fold_button = QtGui.QPushButton(icon, '')
        group_widget.fold_button.setFixedSize(30, 20)
        lay2.addWidget(group_widget.fold_button)
        widget = QtGui.QWidget()
        group_widget.setLayout(lay1)
        lay1.addWidget(widget)
        group_widget.hideable_widget = widget
        layout = QtGui.QGridLayout()
        widget.setLayout(layout)
        layout.setAlignment(QtCore.Qt.AlignTop)
        layout.setSpacing(3)
        layout.setContentsMargins(5, 5, 5, 5)
        group_widget.setAlignment(QtCore.Qt.AlignLeft)

        visible_groups = getattr(self.controller, 'visible_groups', set())
        if group in visible_groups:
            show = True
        else:
            show = False
        group_widget.hideable_widget.setVisible(show)

        if not show:
            icon = QtGui.QIcon()
            icon.addPixmap(
                QtGui.QPixmap(_fromUtf8(":/soma_widgets_icons/nav_right")),
                QtGui.QIcon.Normal, QtGui.QIcon.Off)
            group_widget.fold_button.setIcon(icon)

        #group_widget.fold_button.clicked.connect(SomaPartial(
        #self._toggle_group_visibility, group))
        # FIXME: if we use this, self gets deleted somewhere. This is not
        # normal.
        group_widget.fold_button.clicked.connect(
            partial(self.__class__._toggle_group_visibility, weak_proxy(self),
                    group))

        return group_widget
示例#3
0
def inlineGUI(self, values, pview, parent, externalRunButton=False):
    from soma.qt_gui.qt_backend import QtGui
    from brainvisa.processing.qtgui import neuroProcessesGUI
    vb = QtGui.QWidget()
    lay = QtGui.QVBoxLayout(vb)
    lay.addWidget(
        neuroProcessesGUI.ProcessView.defaultInlineGUI(pview, vb,
                                                       externalRunButton,
                                                       None))
    lay.addWidget(
        QtGui.QLabel(
            _t_('The SPM paths have not been setup in the configuration.\nCurrently, processes using SPM might not work,\nand the SPM database (normalization templates...) cannot be used.\nThis process can try to detect it and set it in the configuration.\nYou should re-open any process depending on SPM afterwards.'
                ), vb))
    return vb
示例#4
0
    def __init__(self, pipeline):
        """ Initialize the WorkflowViewer class
        """
        # Inheritance
        super(PipelineUserView, self).__init__()

        # Class attributets
        self.pipeline = pipeline

        # Initialize the widget
        layout = QtGui.QVBoxLayout(self)
        self.label = QtGui.QLabel()
        layout.addWidget(self.label)
        #self.setLayout(layout)

        self.update()
示例#5
0
 def _completion_progress_changed(self, obj, name, old, new):
     completion_engine = getattr(self.attributed_process,
                                 'completion_engine', None)
     if completion_engine is not None:
         if not hasattr(self, 'progressdialog'):
             self.progressdialog = QtGui.QWidget()
             self.layout().insertWidget(1, self.progressdialog)
             layout = QtGui.QHBoxLayout()
             self.progressdialog.setLayout(layout)
             layout.addWidget(QtGui.QLabel('Completion progress:'))
             self.progressbar = QtGui.QProgressBar()
             layout.addWidget(self.progressbar)
             self.progressbar.setRange(0, 100)
         value = int(round(100 * completion_engine.completion_progress
                     / completion_engine.completion_progress_total))
         self.progressbar.setValue(value)
         if value != 100:
             self.progressdialog.show()
             QtGui.qApp.processEvents()
         else:
             self.progressdialog.hide()
示例#6
0
    def update_controller_widget(cls, controller_widget, control_name,
                                 control_instance):
        """ Update one element of the list controller widget.

        At the end the list controller widget user editable parameter with the
        name 'control_name' will match the controller trait value with the same
        name.

        Parameters
        ----------
        controller_widget: ControllerWidget (mandatory)
            a controller widget that contains the controller we want to update
        control_name: str(mandatory)
            the name of the controller widget control we want to synchronize
            with the controller
        control_instance: QFrame (mandatory)
            the instance of the controller widget control we want to
            synchronize with the controller
        """
        try:
            if control_name not in controller_widget.controller.user_traits():
                return
        except ReferenceError:
            return

        # Get the list widget current connection status
        try:
            was_connected = control_instance.connected
            test = control_instance.control_widget.layout
        except (ReferenceError, RuntimeError):
            # widget deleted in the meantime
            return

        # Disconnect the list controller and the inner list controller
        cls.disconnect(controller_widget, control_name, control_instance)
        control_instance.controller_widget.disconnect()

        widget = control_instance.control_widget
        if sip.isdeleted(widget):
            OffscreenListControlWidget.disconnect(controller_widget,
                                                  control_name,
                                                  control_instance)
            return

        clayout = widget.control_widget.layout()
        owned_widgets = set()
        parent = widget
        for i in range(widget.columnCount()):
            w = widget.cellWidget(0, i)
            if w is not None:
                parent = w.parentWidget()
                owned_widgets.add(w)
        ListControlWidget.update_controller_widget(controller_widget,
                                                   control_name,
                                                   widget.control_widget)
        keys = list(control_instance.controller.user_traits().keys())
        #n = len(control_instance.controller.user_traits())
        parent_value = getattr(controller_widget.controller, control_name)
        if parent_value is traits.Undefined:
            parent_value = []
        elif not isinstance(parent_value, (list, tuple)):
            # in nipype MultiPath, single values are not in a list
            parent_value = [parent_value]
        n = len(parent_value)
        max_items = widget.max_items
        if max_items > 0:
            m = min(max_items, n)
            if n > max_items:
                widget.setColumnCount(m + 1)
            else:
                widget.setColumnCount(n)
        else:
            m = n
            widget.setColumnCount(n)
        for i in range(m):
            try:
                items = widget.control_widget.controller_widget._controls[str(
                    i)]
                item = items[None][2]
                if item not in owned_widgets:
                    widget.setCellWidget(0, i, item)
                if qt_backend.get_qt_backend() == 'PyQt5':
                    widget.horizontalHeader().setSectionResizeMode(
                        i, QtGui.QHeaderView.Stretch)
                else:
                    widget.horizontalHeader().setResizeMode(
                        i, QtGui.QHeaderView.Stretch)
            except KeyError:
                print('KeyError in OffscreenListControlWidget', i)
                print('controls:',
                      widget.control_widget.controller_widget._controls)
        if n > m:
            label = QtGui.QLabel('...')
            width = label.sizeHint().width()
            widget.setCellWidget(0, max_items, QtGui.QLabel('...'))
            if qt_backend.get_qt_backend() == 'PyQt5':
                widget.horizontalHeader().setSectionResizeMode(
                    max_items, QtGui.QHeaderView.Fixed)
            else:
                widget.horizontalHeader().setResizeMode(
                    max_items, QtGui.QHeaderView.Fixed)
            widget.horizontalHeader().resizeSection(max_items, width)

        widget.resizeRowToContents(0)
        height = widget.rowHeight(0) \
            + sum(widget.getContentsMargins()[1:4:2])
        widget.setFixedHeight(height)

        # Restore the previous list controller connection status
        if was_connected:
            cls.connect(controller_widget, control_name, control_instance)
            control_instance.controller_widget.connect()
示例#7
0
    def partial_view_widget(controller_widget, parent_frame, control_value):
        widget = OneLineQTableWidget()
        widget.horizontalHeader().hide()
        widget.verticalHeader().hide()
        widget.max_items = OffscreenListControlWidget.max_items

        if control_value is traits.Undefined:
            control_value = []
        elif not isinstance(control_value, (list, tuple)):
            # in nipype MultiPath, single values are not in a list
            control_value = [control_value]

        control_widget, control_label = ListControlWidget.create_widget(
            controller_widget,
            parent_frame.trait_name,
            control_value,
            parent_frame.trait,
            parent_frame.label_class,
            max_items=widget.max_items,
            user_data=parent_frame.user_data)

        control_label[0].deleteLater()
        control_label[1].deleteLater()
        del control_label

        n = len(control_value)
        max_items = widget.max_items
        if max_items > 0:
            m = min(max_items, n)
            if n > max_items:
                widget.setColumnCount(m + 1)
            else:
                widget.setColumnCount(n)
        else:
            m = n
            widget.setColumnCount(n)
        clayout = control_widget.layout()
        widget.setRowCount(1)
        for i in range(m):
            litem = clayout.itemAtPosition(i + 1, 1)
            if litem is not None:
                item = litem.widget()
                widget.setCellWidget(0, i, item)
            if qt_backend.get_qt_backend() == 'PyQt5':
                widget.horizontalHeader().setSectionResizeMode(
                    i, QtGui.QHeaderView.Stretch)
            else:
                widget.horizontalHeader().setResizeMode(
                    i, QtGui.QHeaderView.Stretch)
        if n > m:
            widget.setCellWidget(0, max_items, QtGui.QLabel('...'))
            if qt_backend.get_qt_backend() == 'PyQt5':
                widget.horizontalHeader().setSectionResizeMode(
                    max_items, QtGui.QHeaderView.Fixed)
            else:
                widget.horizontalHeader().setResizeMode(
                    max_items, QtGui.QHeaderView.Fixed)

        widget.resizeRowToContents(0)
        #scroll_height = widget.findChildren(QtGui.QScrollBar)[-1].height()
        height = widget.rowHeight(0) \
            + sum(widget.getContentsMargins()[1:4:2]) # + scroll_height
        widget.setSizePolicy(QtGui.QSizePolicy.Expanding,
                             QtGui.QSizePolicy.Minimum)
        #widget.viewport().setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,
        #QtGui.QSizePolicy.Fixed)
        #widget.viewport().setFixedHeight(widget.rowHeight(0))
        widget.setFixedHeight(height)

        widget.control_widget = control_widget
        control_widget.hide()

        return widget
    def __init__(self, missing_inputs, overwritten_outputs, parent=None):
        super(PipelineFileWarningWidget, self).__init__(
            QtCore.Qt.Vertical, parent)
        """
        Builds the check widget.

        Parameters
        ----------
        missing_inputs: mapping iterable (mandatory)
            a dict node: (list of pairs (param_name, file_name))
            as output of
            :py:func:`capsul.pipeline_tools.nodes_with_missing_inputs`
        overwritten_outputs: mapping iterable (mandatory)
            a dict node: (list of pairs (param_name, file_name))
            as output of
            :py:func:`capsul.pipeline_tools.nodes_with_existing_outputs`
        parent: QWidget (optional)
            parent widget
        """
        splitter = self
        widget1 = QtGui.QWidget(splitter)
        layout1 = QtGui.QVBoxLayout(widget1)
        widget2 = QtGui.QWidget(splitter)
        layout2 = QtGui.QVBoxLayout(widget2)
        label = QtGui.QLabel()
        layout1.addWidget(label)

        text = '<h1>Pipeline file parameters problems</h1>\n'

        if len(missing_inputs) == 0:
            text += '<h2>Inputs: OK</h2>\n' \
                '<p>All input file are present.</p>\n'
            label.setText(text)
        else:
            text += '<h2>Inputs: missing files</h2>\n'
            label.setText(text)

            table = QtGui.QTableWidget()
            layout1.addWidget(table)
            table.setColumnCount(3)
            sizes = [len(l) for node, l in six.iteritems(missing_inputs)]
            table.setRowCount(sum(sizes))
            table.setHorizontalHeaderLabels(
                ['node', 'parameter', 'filename'])
            row = 0
            for node_name, items in six.iteritems(missing_inputs):
                for param_name, file_name in items:
                    if not file_name or file_name is traits.Undefined:
                        file_name = '<temp. file>'
                    table.setItem(row, 0, QtGui.QTableWidgetItem(node_name))
                    table.setItem(row, 1,
                                  QtGui.QTableWidgetItem(param_name))
                    table.setItem(row, 2, QtGui.QTableWidgetItem(file_name))
                    row += 1
            table.setSortingEnabled(True)
            table.resizeColumnsToContents()

        label_out = QtGui.QLabel()
        layout2.addWidget(label_out)
        if len(overwritten_outputs) == 0:
            text = '<h2>Outputs: OK</h2>\n' \
                '<p>No output file will be overwritten.</p>\n'
            label_out.setText(text)
        else:
            text = '<h2>Outputs: overwritten files</h2>\n'
            label_out.setText(text)

            table = QtGui.QTableWidget()
            layout2.addWidget(table)
            table.setColumnCount(3)
            sizes = [len(l) for node, l in six.iteritems(overwritten_outputs)]
            table.setRowCount(sum(sizes))
            table.setHorizontalHeaderLabels(
                ['node', 'parameter', 'filename'])
            row = 0
            for node_name, items in six.iteritems(overwritten_outputs):
                for param_name, file_name in items:
                    if not file_name or file_name is traits.Undefined:
                        file_name = '<temp. file>'
                    table.setItem(row, 0, QtGui.QTableWidgetItem(node_name))
                    table.setItem(row, 1,
                                  QtGui.QTableWidgetItem(param_name))
                    table.setItem(row, 2, QtGui.QTableWidgetItem(file_name))
                    row += 1
            table.setSortingEnabled(True)
            table.resizeColumnsToContents()
示例#9
0
    def update_controller_widget(cls, controller_widget, control_name,
                                 control_instance):
        """ Update one element of the list controller widget.

        At the end the list controller widget user editable parameter with the
        name 'control_name' will match the controller trait value with the same
        name.

        Parameters
        ----------
        controller_widget: ControllerWidget (mandatory)
            a controller widget that contains the controller we want to update
        control_name: str(mandatory)
            the name of the controller widget control we want to synchronize
            with the controller
        control_instance: QFrame (mandatory)
            the instance of the controller widget control we want to
            synchronize with the controller
        """
        if control_name in controller_widget.controller.user_traits():

            # Get the list widget current connection status
            was_connected = control_instance.connected

            # Disconnect the list controller and the inner list controller
            cls.disconnect(controller_widget, control_name, control_instance)
            control_instance.controller_widget.disconnect()

            widget = control_instance.control_widget
            clayout = widget.control_widget.layout()
            owned_widgets = set()
            parent = widget
            for i in range(widget.columnCount()):
                w = widget.cellWidget(0, i)
                if w is not None:
                    parent = w.parentWidget()
                    owned_widgets.add(w)
            ListControlWidget.update_controller_widget(controller_widget,
                                                       control_name,
                                                       widget.control_widget)
            keys = list(control_instance.controller.user_traits().keys())
            #n = len(control_instance.controller.user_traits())
            parent_value = getattr(controller_widget.controller, control_name)
            n = len(parent_value)
            max_items = widget.max_items
            if max_items > 0:
                m = min(max_items, n)
                if n > max_items:
                    widget.setColumnCount(m + 1)
                else:
                    widget.setColumnCount(n)
            else:
                m = n
                widget.setColumnCount(n)
            for i in range(m):
                items = widget.control_widget.controller_widget._controls[str(
                    i)]
                item = items[None][2]
                if item not in owned_widgets:
                    widget.setCellWidget(0, i, item)
                if qt_backend.get_qt_backend() == 'PyQt5':
                    widget.horizontalHeader().setSectionResizeMode(
                        i, QtGui.QHeaderView.Stretch)
                else:
                    widget.horizontalHeader().setResizeMode(
                        i, QtGui.QHeaderView.Stretch)
            if n > m:
                label = QtGui.QLabel('...')
                width = label.sizeHint().width()
                widget.setCellWidget(0, max_items, QtGui.QLabel('...'))
                if qt_backend.get_qt_backend() == 'PyQt5':
                    widget.horizontalHeader().setSectionResizeMode(
                        max_items, QtGui.QHeaderView.Fixed)
                else:
                    widget.horizontalHeader().setResizeMode(
                        max_items, QtGui.QHeaderView.Fixed)
                widget.horizontalHeader().resizeSection(max_items, width)

            widget.resizeRowToContents(0)
            height = widget.rowHeight(0) \
                + sum(widget.getContentsMargins()[1:4:2])
            widget.setFixedHeight(height)

            # Restore the previous list controller connection status
            if was_connected:
                cls.connect(controller_widget, control_name, control_instance)