def createEditor(self, parent, option, index): """ Reimplemented to return the editor for a given index.""" model = index.model() index = model.mapToSource(index) table_editor = model._editor column = table_editor.columns[index.column()] obj = table_editor.items()[index.row()] factory = column.get_editor(obj) style = column.get_style(obj) if factory is None: return None target, name = column.target_name(obj) handler = default_handler() if table_editor.ui.context is None: ui = UI(handler=handler) else: context = table_editor.ui.context.copy() context['table_editor_object'] = context['object'] context['object'] = target ui = UI(handler=handler, context=context) # Create and initialize the editor factory_method = getattr(factory, style+'_editor') editor = factory_method(ui, target, name, '', parent) editor.prepare(parent) control = editor.control control.setParent(parent) # Required for QMouseEvents to propagate to the widget control.setFocusPolicy(QtCore.Qt.StrongFocus) # The table view's background will shine through unless the editor # paints its own background control.setAutoFillBackground(True) # Make sure that editors are disposed of correctly QtCore.QObject.connect(control, QtCore.SIGNAL('destroyed()'), lambda: editor.dispose()) return control
def createEditor(self, parent, option, index): """ Reimplemented to return the editor for a given index.""" model = index.model() index = model.mapToSource(index) table_editor = model._editor column = table_editor.columns[index.column()] obj = table_editor.items()[index.row()] factory = column.get_editor(obj) style = column.get_style(obj) if factory is None: return None target, name = column.target_name(obj) handler = default_handler() if table_editor.ui.context is None: ui = UI(handler=handler) else: context = table_editor.ui.context.copy() context['table_editor_object'] = context['object'] context['object'] = target ui = UI(handler=handler, context=context) # Create and initialize the editor factory_method = getattr(factory, style + '_editor') editor = factory_method(ui, target, name, '', parent) editor.prepare(parent) control = editor.control control.setParent(parent) # Required for QMouseEvents to propagate to the widget control.setFocusPolicy(QtCore.Qt.StrongFocus) # The table view's background will shine through unless the editor # paints its own background control.setAutoFillBackground(True) # Make sure that editors are disposed of correctly # will be disposed in closeEditor of the TableView control._editor = editor return control
def Create(self, parent, id, evtHandler): """ Called to create the control, which must derive from wxControl. """ from traitsui.api import UI, default_handler # If the editor has already been created, ignore the request: if hasattr(self, '_control'): return handler = self._handler if handler is None: handler = default_handler() if self._context is None: ui = UI(handler=handler) else: context = self._context.copy() context['table_editor_object'] = context['object'] context['object'] = self._obj ui = UI(handler=handler, context=context) # Link the editor's undo history in to the main ui undo history if the # UI object is available: factory = self._factory if factory._ui is not None: ui.history = factory._ui.history # make sure the factory knows this is a grid_cell editor factory.is_grid_cell = True factory_method = getattr(factory, self._style + '_editor') self._editor = factory_method(ui, self._obj, self._name, self._description, parent) # Tell the editor to actually build the editing widget: self._editor.prepare(parent) # Find the control to use as the editor: self._control = control = self._editor.control # Calculate and save the required editor height: grid, row, col = getattr(self, '_grid_info', (None, None, None)) width, height = control.GetBestSize() self_height = self._height if self_height > 1.0: height = int(self_height) elif (self_height >= 0.0) and (grid is not None): height = int(self_height * grid.GetSize()[1]) self_width = self._width if self_width > 1.0: width = int(self_width) elif (self_width >= 0.0) and (grid is not None): width = int(self_width * grid.GetSize()[0]) self._edit_width, self._edit_height = width, height # Set up the event handler for each window in the cell editor: push_control(control, grid) # Set up the first control found within the cell editor as the cell # editor control: control = get_control(control) if control is not None: self.SetControl(control)
def Create(self, parent, id, evtHandler): """ Called to create the control, which must derive from wxControl. """ # If the editor has already been created, ignore the request: if hasattr( self, '_control' ): return handler = self._handler if handler is None: handler = default_handler() if self._context is None: ui = UI(handler = handler) else: context = self._context.copy() context['table_editor_object'] = context['object'] context['object'] = self._obj ui = UI(handler = handler, context = context) # Link the editor's undo history in to the main ui undo history if the # UI object is available: factory = self._factory if factory._ui is not None: ui.history = factory._ui.history # make sure the factory knows this is a grid_cell editor factory.is_grid_cell = True factory_method = getattr(factory, self._style + '_editor') self._editor = factory_method(ui, self._obj, self._name, self._description, parent) # Tell the editor to actually build the editing widget: self._editor.prepare(parent) # Find the control to use as the editor: self._control = control = self._editor.control # Calculate and save the required editor height: grid, row, col = getattr(self, '_grid_info', (None, None, None)) width, height = control.GetBestSize() self_height = self._height if self_height > 1.0: height = int( self_height ) elif (self_height >= 0.0) and (grid is not None): height = int( self_height * grid.GetSize()[1] ) self_width = self._width if self_width > 1.0: width = int( self_width ) elif (self_width >= 0.0) and (grid is not None): width = int( self_width * grid.GetSize()[0] ) self._edit_width, self._edit_height = width, height # Set up the event handler for each window in the cell editor: push_control(control, grid) # Set up the first control found within the cell editor as the cell # editor control: control = get_control(control) if control is not None: self.SetControl(control)