def create_combobox ( self, parent, editable = False ): """ Returns an adapted QComboBox control. """ control = QComboBox( check_parent( parent ) ) control.setEditable( editable ) return control_adapter( control )
def edit_cell(self, parent, row, column): """ Returns the editor widget to use for editing a specified cell's value. """ self.cell_row = cell_row = self.data_row_for(row) grid_adapter = self.grid_adapter # Get the editor factory to use. If none, exit (read-only cell): editor_factory = grid_adapter.get_editor(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 = grid_adapter.get_alias(cell_row, column) handler = None if grid_adapter.get_change_mode(cell_row, column) != "live": handler = DeferredEditHandler(target_object=object, defer_modified=True).set(target_name=name) object = handler.defer_object 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 control._handler = handler header = self.control.horizontalHeader() column_width = header.sectionSize(column) if self.factory.resize_cell_editor: control.setGeometry(0, 0, column_width, self.height) else: # Adjust the row height of the grid row to fit the editor control: height = control.height() if height > self.height: control._row = row self.control.verticalHeader().resizeSection(row, height) # Resize the grid column width to fit the editor if necessary: width = control.width() if width > column_width: control._column = column control._width = column_width header.resizeSection(column, width) # Return the editing widget as the result: return control
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 )
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 )
def addWidget(self, widget, stretch=None): from facets.ui.qt4.adapters.control import control_adapter self.items.append(QWidgetItem(widget)) self.layout.add(control_adapter(widget))