Exemplo n.º 1
0
 def _init_widget(self):
     self.ui = loadUi(self.uifile, self)
     header = self.horizontalHeader()
     if qt_backend.get_qt_backend() == 'PyQt5':
         header.setSectionResizeMode(QtGui.QHeaderView.ResizeToContents)
         header.setSectionsMovable(True)
     else:
         header.setResizeMode(QtGui.QHeaderView.ResizeToContents)
         header.setMovable(True)
     self.verticalHeader().setVisible(False)
     self.setItemDelegate(SubjectsItemDelegate())
Exemplo n.º 2
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()
Exemplo n.º 3
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
Exemplo n.º 4
0
  'somabase': (os.environ.get('SOMABASE_INTERSPHINX_URL',
                              os.path.join(docpath, 'soma-base-' + somabase_version + '/sphinx')),
               None),
  'somaworkflow': (os.environ.get('SOMAWORKFLOW_INTERSPHINX_URL',
                                  os.path.join(docpath, 'soma-workflow-'
                                  + somaworkflow_version + '/sphinx')),
                   None),
  'python': ('https://docs.python.org/%s' % pyversion, None),
  'traits': ('https://docs.enthought.com/traits', None),
}

# init for Qt
try:
    from soma.qt_gui import qt_backend
    qt_backend.set_qt_backend(compatible_qt5=True)
    print('Using Qt backend:', qt_backend.get_qt_backend())
except Exception:
    print('Warning: Qt could not be loaded. GUI will not be documented.')

# Notebooks handling:
#
# Several problems are handled here:
# 1. nbsphinx 0.4 does not read (ignores) notebooks in _static/
#    For this reason we moved the NB to tutorial/
# 2. nbsphinx 0.4 does not allow direct links to the .ipynb (for download)
#    but replaces them with the converted HTML page.
#    For this reason we duplicate the NB into _static/ where NB are not
#    processed, and links not changed
# 3. notebooks include kernel information which does not necessarily match the
#    running/installed python and jupyter kernels.
#    For this reason we conbert them using pupyter nbconvert, forcing the
Exemplo n.º 5
0
from __future__ import print_function

# select Qt backend matching the one used by anatomist
import anatomist.direct.api
from soma.qt_gui import qt_backend

qt_backend.set_qt_backend(compatible_qt5=True)
print("qt backend:", qt_backend.get_qt_backend())

from soma.qt_gui.qt_backend import QtCore, QtGui, QtTest, Qt, QtWebKit
from soma.qt_gui.qt_backend import loadUi, loadUiType

# import sip
# API_VERSION = 2
# qt_api = ["QDate", "QDateTime", "QString", "QTextStream", "QTime", "QUrl", "QVariant"]
# for qt_module in qt_api:
# sip.setapi(qt_module, API_VERSION)

# try:
# import PyQt4
# except ImportError:
# raise Exception("error: missing PyQt dependency.")
# else:
# from PyQt4 import QtCore, QtGui, QtTest, Qt, QtWebKit

# import PyQt4.QtCore
# PyQt4.QtCore.Slot = PyQt4.QtCore.pyqtSlot
# PyQt4.QtCore.Signal = PyQt4.QtCore.pyqtSignal


# def loadUi(uifile, baseinstance=None):
Exemplo n.º 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
        """
        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)
Exemplo n.º 7
0
 def test_qtgui(self):
     from soma.qt_gui import qt_backend
     qt_backend.set_qt_backend(compatible_qt5=True)
     self.assertTrue(qt_backend.get_qt_backend() in ('PyQt4', 'PyQt5',
                                                     'PySide'))