Esempio n. 1
0
    def empty_list ( self ):
        """ Creates an empty list entry (so the user can add a new item).
        """
        # Connecting the new button to the mapper
        from pyface.qt import QtCore, QtGui
        from pyface.qt import qt_api
        from traitsui.qt4.helper import IconButton

        #control = IconButton('list_editor.png', self.mapper.map)
        if qt_api == 'pyside':
            control = IconButton('list_editor.png', self.mapper.map)
        elif qt_api == 'pyqt':
            control = IconButton('list_editor.png',
                lambda : self.popup_empty_menu(
                    self._list_pane.layout().sender() ))

        # Setting the mapping and asking it to send the sender to the
        # callback method
        self.mapper.setMapping(control, control)
        self.mapper.mapped[QtCore.QObject].connect(self.popup_empty_menu)
        control.is_empty = True
        self._cur_control = control

        from traitsui.editors.list_editor import ListItemProxy
        proxy    = ListItemProxy( self.object, self.name, -1, None, None )
        pcontrol = QtGui.QLabel('   (Empty List)')
        pcontrol.proxy = control.proxy = proxy

        layout = self._list_pane.layout()
        layout.addWidget(control, 0, 0)
        layout.addWidget(pcontrol, 0, 1)
Esempio n. 2
0
    def empty_list(self):
        """ Creates an empty list entry (so the user can add a new item).
        """
        # Connecting the new button to the mapper
        from pyface.qt import QtCore, QtGui
        from pyface.qt import qt_api
        from traitsui.qt4.helper import IconButton

        #control = IconButton('list_editor.png', self.mapper.map)
        if qt_api == 'pyside':
            control = IconButton('list_editor.png', self.mapper.map)
        elif qt_api == 'pyqt':
            control = IconButton(
                'list_editor.png',
                lambda: self.popup_empty_menu(self._list_pane.layout().sender(
                )))

        # Setting the mapping and asking it to send the sender to the
        # callback method
        self.mapper.setMapping(control, control)
        self.mapper.mapped[QtCore.QObject].connect(self.popup_empty_menu)
        control.is_empty = True
        self._cur_control = control

        from traitsui.editors.list_editor import ListItemProxy
        proxy = ListItemProxy(self.object, self.name, -1, None, None)
        pcontrol = QtGui.QLabel('   (Empty List)')
        pcontrol.proxy = control.proxy = proxy

        layout = self._list_pane.layout()
        layout.addWidget(control, 0, 0)
        layout.addWidget(pcontrol, 0, 1)
Esempio n. 3
0
    def update_editor(self):
        """ Updates the editor when the object trait changes externally to the
            editor.
        """
        self.mapper = QtCore.QSignalMapper(self.control)
        # Disconnect the editor from any control about to be destroyed:
        self._dispose_items()

        layout = self.control.layout()

        # Create all of the list item trait editors:
        trait_handler = self._trait_handler
        resizable = ((trait_handler.minlen != trait_handler.maxlen)
                     and self.mutable)
        item_trait = trait_handler.item_trait

        is_fake = (resizable and (len(self.value) == 0))
        if is_fake:
            self.empty_list()
        else:
            # Asking the mapper to send the sender to the callback method
            self.mapper.mapped[QtCore.QObject].connect(self.popup_menu)

        editor = self._editor
        for index, value in enumerate(self.value):
            row, column = divmod(index, self.factory.columns)

            # Account for the fact that we have <columns> number of
            # pairs
            column = column * 2

            if resizable:
                # Connecting the new button to the mapper
                control = IconButton('list_editor.png', self.mapper.map)
                # Setting the mapping and asking it to send the index of the
                # sender to the callback method
                self.mapper.setMapping(control, control)

                layout.addWidget(control, row, column)

            proxy = ListItemProxy(self.object, self.name, index, item_trait,
                                  value)
            if resizable:
                control.proxy = proxy
            peditor = editor(self.ui, proxy, 'value', self.description,
                             self.control).set(object_name='')
            peditor.prepare(self.control)
            pcontrol = peditor.control
            pcontrol.proxy = proxy

            if isinstance(pcontrol, QtGui.QWidget):
                layout.addWidget(pcontrol, row, column + 1)
            else:
                layout.addLayout(pcontrol, row, column + 1)
Esempio n. 4
0
def qt4_editor_factory(parent, editor, use_dir=False, *args):
    from pyface.qt import QtCore, QtGui
    from traitsui.qt4.helper import IconButton

    editor.control = panel = QtGui.QWidget()
    layout = QtGui.QHBoxLayout(panel)
    layout.setContentsMargins(0, 0, 0, 0)

    editor.use_dir = use_dir

    editor.text_control = text_control = QtGui.QLineEdit()
    layout.addWidget(text_control)
    signal = QtCore.SIGNAL('editingFinished()')
    QtCore.QObject.connect(text_control, signal,
                           lambda: update_file_obj(editor))

    button = IconButton(QtGui.QStyle.SP_DirIcon, lambda: button_click(editor))
    layout.addWidget(button)

    return panel
Esempio n. 5
0
    def update_editor(self): 
        from pyface.qt import QtCore, QtGui
        self.mapper = QtCore.QSignalMapper(self.control)
        # Disconnect the editor from any control about to be destroyed:
        self._dispose_items()

        list_pane = self._list_pane
        layout = list_pane.layout()

        # Create all of the list item trait editors:
        trait_handler = self._trait_handler
        resizable     = ((trait_handler.minlen != trait_handler.maxlen) and
                         self.mutable)
        item_trait    = trait_handler.item_trait

        is_fake = (resizable and (len( self.value ) == 0))
        if is_fake:
            self.empty_list()
        else:
            # Asking the mapper to send the sender to the callback method
            self.mapper.mapped[QtCore.QObject].connect(self.popup_menu)

        editor = self._editor
        for index, value in enumerate(self.value):
            row, column = divmod(index, self.factory.columns)

            # Account for the fact that we have <columns> number of
            # pairs
            column = column * 2

            if resizable:
                # Connecting the new button to the mapper
                from traitsui.qt4.helper import IconButton

                from pyface.qt import qt_api

                # fix bug in pyqt, reverts back to traitsui 4.3 version
                if qt_api == 'pyside':
                    control = IconButton('list_editor.png', self.mapper.map)
                elif qt_api == 'pyqt':
                    control = IconButton('list_editor.png',
                        lambda : self.popup_menu(
                            self._list_pane.layout().sender() ))

                # Setting the mapping and asking it to send the index of the
                # sender to the callback method
                self.mapper.setMapping(control, control)

                layout.addWidget(control, row, column)

            from traitsui.editors.list_editor import ListItemProxy
            proxy = ListItemProxy( self.object, self.name, index, item_trait,
                                   value )
            if resizable:
                control.proxy = proxy
            peditor = editor( self.ui, proxy, 'value', self.description,
                              list_pane ).set( object_name = '' )
            peditor.prepare( list_pane )
            pcontrol = peditor.control
            pcontrol.proxy = proxy

            if isinstance(pcontrol, QtGui.QWidget):
                layout.addWidget(pcontrol, row, column+1)
            else:
                layout.addLayout(pcontrol, row, column+1)

        # QScrollArea can have problems if the widget being scrolled is set too
        # early (ie. before it contains something).
        if self.control.widget() is None:
            self.control.setWidget(list_pane)
Esempio n. 6
0
    def update_editor(self):
        from pyface.qt import QtCore, QtGui
        self.mapper = QtCore.QSignalMapper(self.control)
        # Disconnect the editor from any control about to be destroyed:
        self._dispose_items()

        list_pane = self._list_pane
        layout = list_pane.layout()

        # Create all of the list item trait editors:
        trait_handler = self._trait_handler
        resizable = ((trait_handler.minlen != trait_handler.maxlen)
                     and self.mutable)
        item_trait = trait_handler.item_trait

        is_fake = (resizable and (len(self.value) == 0))
        if is_fake:
            self.empty_list()
        else:
            # Asking the mapper to send the sender to the callback method
            self.mapper.mapped[QtCore.QObject].connect(self.popup_menu)

        editor = self._editor
        for index, value in enumerate(self.value):
            row, column = divmod(index, self.factory.columns)

            # Account for the fact that we have <columns> number of
            # pairs
            column = column * 2

            if resizable:
                # Connecting the new button to the mapper
                from traitsui.qt4.helper import IconButton

                from pyface.qt import qt_api

                # fix bug in pyqt, reverts back to traitsui 4.3 version
                if qt_api == 'pyside':
                    control = IconButton('list_editor.png', self.mapper.map)
                elif qt_api == 'pyqt':
                    control = IconButton(
                        'list_editor.png', lambda: self.popup_menu(
                            self._list_pane.layout().sender()))

                # Setting the mapping and asking it to send the index of the
                # sender to the callback method
                self.mapper.setMapping(control, control)

                layout.addWidget(control, row, column)

            from traitsui.editors.list_editor import ListItemProxy
            proxy = ListItemProxy(self.object, self.name, index, item_trait,
                                  value)
            if resizable:
                control.proxy = proxy
            peditor = editor(self.ui, proxy, 'value', self.description,
                             list_pane).set(object_name='')
            peditor.prepare(list_pane)
            pcontrol = peditor.control
            pcontrol.proxy = proxy

            if isinstance(pcontrol, QtGui.QWidget):
                layout.addWidget(pcontrol, row, column + 1)
            else:
                layout.addLayout(pcontrol, row, column + 1)

        # QScrollArea can have problems if the widget being scrolled is set too
        # early (ie. before it contains something).
        if self.control.widget() is None:
            self.control.setWidget(list_pane)