def updateHierarchicalWrapper(self): """Updates the wrapper's internal hierarchy data to include all Items in the underlying container. If the contents of the wrapped container change without the wrapper's knowledge, this method needs to be called to update the hierarchy information of the Items. """ if not self._hierarchical: # Recreate hierarchy and data structures if missing if (self._noChildrenAllowed is None or self._parent is None or self._children is None or self._roots is None): # Check that the hierarchy is up-to-date self._noChildrenAllowed = set() self._parent = dict() self._children = dict() self._roots = OrderedSet(self._container.getItemIds()) else: # ensure order of root and child lists is same as in wrapped # container itemIds = self._container.getItemIds() basedOnOrderFromWrappedContainer = \ ListedItemsFirstComparator(itemIds) # Calculate the set of all items in the hierarchy s = set() s = s.union(self._parent.keys()) s = s.union(self._children.keys()) s = s.union(self._roots) # Remove unnecessary items for idd in s: if not self._container.containsId(idd): self.removeFromHierarchyWrapper(idd) # Add all the missing items ids = self._container.getItemIds() for idd in ids: if not (idd in s): self.addToHierarchyWrapper(idd) s.add(idd) arry = list(self._roots) arry.sort(cmp=basedOnOrderFromWrappedContainer) self._roots = OrderedSet() for a in arry: self._roots.add(a) for obj in self._children.keys(): object2 = self._children[obj] object2.sort(cmp=basedOnOrderFromWrappedContainer)
def getPoints(cls, series, values): if len(values) > 0 and isinstance(values[0], (float, int)): points = OrderedSet() for value in values: points.add(DecimalPoint(series, value)) return points else: points = OrderedSet() for value in values: y = None if len(value) == 0: continue if len(value) == 2: x = value[0] y = value[1] else: x = value[0] points.add(DecimalPoint(series, x, y)) return points
def __init__(self): """Creates an AbsoluteLayout with full size.""" super(AbsoluteLayout, self).__init__() #: The components in the layout self._components = OrderedSet() #: Maps each component to a position self._componentToCoordinates = dict() self.setSizeFull()
def addListener(self, eventType, obj, method, arguments=None, eventArgIdx=None): # Registers a new listener with the specified activation method # to listen events generated by this component. if self._listenerList is None: self._listenerList = OrderedSet() lm = ListenerMethod(eventType, obj, method, arguments, eventArgIdx) self._listenerList.add(lm)
def doFilterContainer(self, hasFilters): if not hasFilters: # All filters removed self._filteredRoots = None self._filteredChildren = None self._filteredParent = None return super(HierarchicalContainer, self).doFilterContainer(hasFilters) # Reset data structures self._filteredRoots = list() self._filteredChildren = dict() self._filteredParent = dict() if self._includeParentsWhenFiltering: # Filter so that parents for items that match the filter are also # included includedItems = set() for rootId in self._roots: if self.filterIncludingParents(rootId, includedItems): self._filteredRoots.append(rootId) self.addFilteredChildrenRecursively(rootId, includedItems) # includedItemIds now contains all the item ids that should be # included. Filter IndexedContainer based on this self._filterOverride = includedItems super(HierarchicalContainer, self).doFilterContainer(hasFilters) self._filterOverride = None return True else: # Filter by including all items that pass the filter and make items # with no parent new root items # Filter IndexedContainer first so getItemIds return the items that # match super(HierarchicalContainer, self).doFilterContainer(hasFilters) filteredItemIds = OrderedSet(self.getItemIds()) for itemId in filteredItemIds: itemParent = self._parent.get(itemId) if (itemParent is None or itemParent not in filteredItemIds): # Parent is not included or this was a root, in both cases # this should be a filtered root self._filteredRoots.append(itemId) else: # Parent is included. Add this to the children list (create # it first if necessary) self.addFilteredChild(itemParent, itemId) return True
def __init__(self, caption=None, uploadReceiver=None): """Creates a new instance of Upload. The receiver must be set before performing an upload. """ super(Upload, self).__init__() #: Should the field be focused on next repaint? self._focus = False #: The tab order number of this field. self._tabIndex = 0 #: The output of the upload is redirected to this receiver. self._receiver = None self._isUploading = False self._contentLength = -1 self._totalBytes = None self._buttonCaption = 'Upload' #: ProgressListeners to which information about progress # is sent during upload self._progressListeners = OrderedSet() self._progressCallbacks = dict() self._interrupted = False self._notStarted = None self._nextid = 0 #: Flag to indicate that submitting file has been requested. self._forceSubmit = None if caption: self.setCaption(caption) if uploadReceiver is not None: self._receiver = uploadReceiver self._streamVariable = None
def __init__(self, toBeWrapped): """Constructs a new hierarchical wrapper for an existing Container. Works even if the to-be-wrapped container already implements the C{IHierarchical} interface. @param toBeWrapped: the container that needs to be accessed hierarchically @see: L{updateHierarchicalWrapper} """ super(ContainerHierarchicalWrapper, self).__init__() #: The wrapped container self._container = None #: Set of IDs of those contained Items that can't have children. self._noChildrenAllowed = None #: Mapping from Item ID to parent Item ID self._parent = None #: Mapping from Item ID to a list of child IDs self._children = None #: List that contains all root elements of the container. self._roots = None #: Is the wrapped container hierarchical by itself ? self._hierarchical = None self._container = toBeWrapped self._hierarchical = isinstance(self._container, IHierarchical) # Check arguments if self._container is None: raise ValueError, 'Null can not be wrapped' # Create initial order if needed if not self._hierarchical: self._noChildrenAllowed = OrderedSet() self._parent = dict() self._children = dict() self._roots = set(self._container.getItemIds()) self.updateHierarchicalWrapper()
def paintContent(self, target): """Paints any needed component-specific things to the given UIDL stream. @see: L{AbstractComponent.paintContent} """ self._initialPaint = False if self._partialUpdate: target.addAttribute('partialUpdate', True) target.addAttribute('rootKey', self.itemIdMapper.key(self._expandedItemId)) else: self.getCaptionChangeListener().clear() # The tab ordering number if self.getTabIndex() > 0: target.addAttribute('tabindex', self.getTabIndex()) # Paint tree attributes if self.isSelectable(): if self.isMultiSelect(): target.addAttribute('selectmode', 'multi') else: target.addAttribute('selectmode', 'single') if self.isMultiSelect(): try: idx = MultiSelectMode.values().index( self._multiSelectMode) except ValueError: idx = -1 target.addAttribute('multiselectmode', idx) else: target.addAttribute('selectmode', 'none') if self.isNewItemsAllowed(): target.addAttribute('allownewitem', True) if self.isNullSelectionAllowed(): target.addAttribute('nullselect', True) if self._dragMode != TreeDragMode.NONE: target.addAttribute('dragMode', TreeDragMode.ordinal(self._dragMode)) # Initialize variables actionSet = OrderedSet() # rendered selectedKeys selectedKeys = list() expandedKeys = list() # Iterates through hierarchical tree using a stack of iterators iteratorStack = deque() if self._partialUpdate: ids = self.getChildren(self._expandedItemId) else: ids = self.rootItemIds() if ids is not None: iteratorStack.append(iter(ids)) # Body actions - Actions which has the target null and can be invoked # by right clicking on the Tree body if self._actionHandlers is not None: keys = list() for ah in self._actionHandlers: # Getting action for the null item, which in this case # means the body item aa = ah.getActions(None, self) if aa is not None: for ai in range(len(aa)): akey = self._actionMapper.key(aa[ai]) actionSet.add(aa[ai]) keys.append(akey) target.addAttribute('alb', keys) while len(iteratorStack) > 0: # Gets the iterator for current tree level i = iteratorStack[-1] # peek try: # Adds the item on current level itemId = i.next() # Starts the item / node isNode = self.areChildrenAllowed(itemId) if isNode: target.startTag('node') else: target.startTag('leaf') if self._itemStyleGenerator is not None: stylename = self._itemStyleGenerator.getStyle(itemId) if stylename is not None: target.addAttribute('style', stylename) if self._itemDescriptionGenerator is not None: description = self._itemDescriptionGenerator\ .generateDescription(self, itemId, None) if description is not None and description != "": target.addAttribute("descr", description) # Adds the attributes target.addAttribute('caption', self.getItemCaption(itemId)) icon = self.getItemIcon(itemId) if icon is not None: target.addAttribute('icon', self.getItemIcon(itemId)) key = self.itemIdMapper.key(itemId) target.addAttribute('key', key) if self.isSelected(itemId): target.addAttribute('selected', True) selectedKeys.append(key) if self.areChildrenAllowed(itemId) and self.isExpanded(itemId): target.addAttribute('expanded', True) expandedKeys.append(key) # Add caption change listener self.getCaptionChangeListener().addNotifierForItem(itemId) # Actions if self._actionHandlers is not None: keys = list() ahi = iter(self._actionHandlers) while True: try: aa = ahi.next().getActions(itemId, self) if aa is not None: for ai in range(len(aa)): akey = self._actionMapper.key(aa[ai]) actionSet.add(aa[ai]) keys.append(akey) except StopIteration: break target.addAttribute('al', keys) # Adds the children if expanded, or close the tag if (self.isExpanded(itemId) and self.hasChildren(itemId) and self.areChildrenAllowed(itemId)): iteratorStack.append(iter(self.getChildren(itemId))) elif isNode: target.endTag('node') else: target.endTag('leaf') # If the level is finished, back to previous tree level except StopIteration: # Removes used iterator from the stack iteratorStack.pop() # Closes node if len(iteratorStack) > 0: target.endTag('node') # Actions if len(actionSet) > 0: target.addVariable(self, 'action', '') target.startTag('actions') i = actionSet for a in actionSet: target.startTag('action') if a.getCaption() is not None: target.addAttribute('caption', a.getCaption()) if a.getIcon() is not None: target.addAttribute('icon', a.getIcon()) target.addAttribute('key', self._actionMapper.key(a)) target.endTag('action') target.endTag('actions') if self._partialUpdate: self._partialUpdate = False else: # Selected target.addVariable(self, 'selected', selectedKeys) # Expand and collapse target.addVariable(self, 'expand', list()) target.addVariable(self, 'collapse', list()) # New items target.addVariable(self, 'newitem', list()) if self._dropHandler is not None: self._dropHandler.getAcceptCriterion().paint(target)