Esempio n. 1
0
    def create_combobox(self, parent, editable=False):
        """ Returns an adapted QComboBox control.
        """
        control = QComboBox(check_parent(parent))
        control.setEditable(editable)

        return control_adapter(control)
Esempio n. 2
0
    def as_toolkit_adapter(self, control):
        """ Returns the GUI toolkit specific control adapter associated with
            *control*.
        """
        if (control is None) or isinstance(control, Control):
            return control

        return control_adapter(control)
Esempio n. 3
0
    def edit_cell ( self, parent, row, column ):
        """ Returns the editor widget to use for editing a specified cell's
            value.
        """
        self.cell_row = self.data_row_for( row )

        # Get the editor factory to use. If none, exit (read-only cell):
        editor_factory = self.grid_adapter.get_editor( self.cell_row, column )
        if editor_factory is None:
            return None

        # Create the requested type of editor from the editor factory:
        # Note: We save the editor reference so that the editor doesn't get
        # garbage collected too soon.
        self.cell_column = column
        object, name     = self.grid_adapter.get_alias(  self.cell_row, column )
        editor           = editor_factory.simple_editor(
                               self.ui, object, name, '' ).set(
                               item        = self.item,
                               object_name = '' )

        # Tell the editor to actually build the editing widget:
        editor.prepare( control_adapter( parent ) )

        # Make sure that the editor is a control (and not a layout):
        self._editor = editor
        control      = editor.control
        if not isinstance( control, QWidget ):
            layout  = control
            control = QWidget( parent )
            control.setLayout( layout )
            layout.setContentsMargins( 5, 0, 5, 0 )

        control._editor = editor

        # Adjust the row height of the grid row to fit the editor control:
        height = control.height()
        if height > self.height:
            if (self.height - height) <= 4:
                # If the difference is not too great, then we will just adjust
                # the grid height to accomodate it:
                self.row_height( height )
            else:
                # Otherwise, just adjust the height of this row temporarily:
                control._row = row
                self.control.verticalHeader().resizeSection( row, height )

        # Resize the grid column width to fit the editor if necessary:
        width        = control.width()
        header       = self.control.horizontalHeader()
        column_width = header.sectionSize( column )
        if width > column_width:
            control._column = column
            control._width  = column_width
            header.resizeSection( column, width )

        # Return the editing widget as the result:
        return control
Esempio n. 4
0
def control_adapter_for(control):
    """ Returns the adapted form of the control.
    """
    # If the control has a parent already and is not a top-level window, then
    # make it visible, since the top-level caller assumes it is already visible.
    # If it does not have a parent, then it will eventually be added to a
    # layout, which will handle making it visible:
    if (control.parentWidget() is not None) and (not isinstance(control, TopLevelWindows)):
        control.setVisible(True)

    return control_adapter(control)
Esempio n. 5
0
    def addWidget ( self, widget, stretch = None ):
        from facets.ui.side.adapters.control import control_adapter

        self.items.append( QWidgetItem( widget ) )
        self._layout.add( control_adapter( widget ) )