def _do ( self, key_names, controllers, args ): """ Process the specified key for the specified set of controllers for this KeyBindings object and all of its children. """ # Search through our own bindings for a match: for binding in self.bindings: if ((binding.binding in key_names) or (binding.alt_binding in key_names)): method_name = '%s%s%s' % ( self.prefix, binding.method, self.suffix ) for controller in (self.controllers + controllers): method = getattr( controller, method_name, None ) if method is not None: result = invoke( method, *args ) if result is not False: return True if binding.method == 'edit_bindings': self.edit() return True elif binding.rebinding in key_names: key_names = key_names + ( binding.binding, ) if binding.alt_binding != '': key_names = key_names + ( binding.alt_binding, ) # Continue searching through any children's bindings: for child in self.children: if child._do( key_names, controllers, args ): return True # Indicate no one processed the key: return False #-- EOF ------------------------------------------------------------------------
def _add_item ( self, item ): """ Adds a duplicate of the list view item specified by *item*. """ self._no_update = True # Create a copy of the item's data: is_empty = (item.item is empty_list) data = (None if is_empty else item.item) factory = self.factory.factory index = self.index_for( item ) copy_data = None try: if issubclass( factory, HasFacets ): copy_data = (factory() if data is None else self._default_factory( data )) except: pass if copy_data is None: if isinstance( factory, HasFacets ) or (not callable( factory )): copy_data = self._default_factory( factory if data is None else data ) elif factory is not None: copy_data = invoke( factory, data, index ) else: copy_data = self._default_factory( data ) # Update the editor's value with the new data: index += (not is_empty) self._add_index( index, copy_data ) # Create a new list view item for the copy of the data: copy_item = self.factory.adapter( copy_data ).set( owner = self ) copy_item.init() if is_empty: # We are replacing the empty list item with a new item, so dispose # of the empty list item and completely replace the items list: item.dispose() self.items = [ copy_item ] self._rebuild_list() else: # Make the new item the same size/position as the one it is copied # from: copy_item.set( size = item.size, position = item.position, control_offset = item.control_offset, min_height = item.min_height ).set( draw_position = item.draw_position ) copy_item.ui.control.size = item.ui.control.size # Update the editor's model with the copied item: self.items.insert( index, copy_item ) # Increase the virtual size by the height of the new item: self._adjust_size( item.size[1] ) # Rebuild the editor's view: self._rebuild() self._no_update = False