def findTextPoint(node, offset): """ If the found range is not on a text node, this finds the cooresponding text node to where the selection is. If it is on a text node, just directly creates the endpoint from it. @param node node returned as an endpoint of a range @param offset offset returned to the endpoint of a range @return A range end point with a proper (or None) text node """ if DOM.getNodeType(node) == DOM.TEXT_NODE: res = RangeEndPoint(node, offset) else: # search backwards unless this is after the last node dirn = offset >= DOM.getChildCount(node) child = (DOM.getChildCount(node) == 0) and node or \ DOM.getChild(node, dirn and (offset - 1) or offset) # Get the previous/next text node text = RangeUtil.getAdjacentTextElement(child, dirn) if text is None: # If we didn't find a text node in the preferred direction, # try the other direction dirn = not dirn text = RangeUtil.getAdjacentTextElement(child, dirn) res = RangeEndPoint(text, dirn) return res
def findTextPoint(node, offset): """ If the found range is not on a text node, this finds the cooresponding text node to where the selection is. If it is on a text node, just directly creates the endpoint from it. @param node node returned as an endpoint of a range @param offset offset returned to the endpoint of a range @return A range end point with a proper (or None) text node """ if DOM.getNodeType(node) == DOM.TEXT_NODE: res = RangeEndPoint(node, offset) else: # search backwards unless this is after the last node dirn = offset >= DOM.getChildCount(node) child = (DOM.getChildCount(node) == 0) and node or DOM.getChild(node, dirn and (offset - 1) or offset) # Get the previous/next text node text = RangeUtil.getAdjacentTextElement(child, dirn) if text is None: # If we didn't find a text node in the preferred direction, # try the other direction dirn = not dirn text = RangeUtil.getAdjacentTextElement(child, dirn) res = RangeEndPoint(text, dirn) return res
def _checkVerticalContainer(self): """ use this to delay effect of self.vertical being set. self.setVertical can now be used, rather than self.vertical force-set in constructor """ if DOM.getChildCount(self.body) == 0: DOM.appendChild(self.body, DOM.createTR())
def findTextPoint(node, offset): if DOM.getNodeType(node) == DOM.TEXT_NODE: res = RangeEndPoint(node, offset) else: # search backwards unless this is after the last node dirn = offset >= DOM.getChildCount(node) child = (DOM.getChildCount(node) == 0) and node or DOM.getChild(node, dirn and (offset - 1) or offset) # Get the previous/next text node text = RangeUtil.getAdjacentTextElement(child, dirn) if text is None: # If we didn't find a text node in the preferred direction, # try the other direction dirn = not dirn text = RangeUtil.getAdjacentTextElement(child, dirn) res = RangeEndPoint(text, dirn) return res
def findTextPoint(node, offset): if DOM.getNodeType(node) == DOM.TEXT_NODE: res = RangeEndPoint(node, offset) else: # search backwards unless this is after the last node dirn = offset >= DOM.getChildCount(node) child = (DOM.getChildCount(node) == 0) and node or \ DOM.getChild(node, dirn and (offset - 1) or offset) # Get the previous/next text node text = RangeUtil.getAdjacentTextElement(child, dirn) if text is None: # If we didn't find a text node in the preferred direction, # try the other direction dirn = not dirn text = RangeUtil.getAdjacentTextElement(child, dirn) res = RangeEndPoint(text, dirn) return res
def clear(self): # as long as the canvas has children other than our <defs> element while DOM.getChildCount(self.canvas) > 1: # remove the second one (skip defs) DOM.removeChild(self.canvas, DOM.getChild(self.canvas, 1)) # # init styles context stack # self.ctx_stack = [] # # init current context # self._init_context() # also reset path self.beginPath()
def getTargetInChildren(element, x, y): """ x and y are absolute coordinates within the document. Return the last child of element that contains (x,y). Return None if not found. """ return_elt = None if DOM.getChildCount(element) > 0: for elt in DOM.IterWalkChildren(element): hit = isIn(elt, x, y) if hit: return_elt = elt return return_elt
def getAdjacentTextElement(current, topMostNode, forward=None, traversingUp=False): if forward is None: forward = topMostNode topMostNode = None res = None #print "getAdjacentTextElement", current, topMostNode, forward, traversingUp # If traversingUp, then the children have already been processed if not traversingUp: if DOM.getChildCount(current) > 0: if forward: node = DOM.getFirstChild(current) else: node = DOM.getLastChild(current) if DOM.getNodeType(node) == DOM.TEXT_NODE: res = node else: # Depth first traversal, the recursive call deals with # siblings res = getAdjacentTextElement(node, topMostNode, forward, False) if res is None: if forward: node = current.nextSibling else: node = current.previousSibling # Traverse siblings if node is not None: if DOM.getNodeType(node) == DOM.TEXT_NODE: res = node else: #print node, DOM.getNodeType(node), node.innerHTML # Depth first traversal, the recursive call deals with # siblings res = getAdjacentTextElement(node, topMostNode, forward, False) # Go up and over if still not found if (res is None) and (not DOM.compare(current, topMostNode)): node = current.parentNode # Stop at document (technically could stop at "html" tag) if (node is not None) and \ (DOM.getNodeType(node) != DOM.DOCUMENT_NODE): res = getAdjacentTextElement(node, topMostNode, forward, True) return res
def __init__(self, defs_elem, elem_type, width, height): # save defs self.defs_elem = defs_elem # save dimensions of canvas as floats self.canvas_width = float(width) self.canvas_height = float(height) # create the gradient element self.elem = self._createElementSVG(elem_type) # make a unique id self.id = "grad" + str(DOM.getChildCount(defs_elem) + 1) # set the element's id DOM.setElemAttribute(self.elem, "id", self.id) # set for canvas-based coordinates DOM.setElemAttribute(self.elem, "gradientUnits", "userSpaceOnUse") # add the new element to defs DOM.appendChild(defs_elem, self.elem)
def __init__(self, defs_elem, elem_type, width, height): # save defs self.defs_elem = defs_elem # save dimensions of canvas as floats self.canvas_width = float(width) self.canvas_height = float(height) # create the gradient element self.elem = self._createElementSVG(elem_type) # make a unique id self.id = "grad"+str(DOM.getChildCount(defs_elem) + 1) # set the element's id DOM.setElemAttribute(self.elem, "id", self.id) # set for canvas-based coordinates DOM.setElemAttribute(self.elem, "gradientUnits", "userSpaceOnUse") # add the new element to defs DOM.appendChild(defs_elem, self.elem)
def _apply_current_transforms(self): # if the current transform group already has elements if DOM.getChildCount(self.ctx["transform_group"]) > 0: # we create a new one group = self._createElementSVG("g") # add a new transform group to the canvas DOM.appendChild(self.canvas, group) # and make it the current tranform group self.ctx["transform_group"] = group # build the transform spec # just to make the next line shorter mx = self.ctx["matrix"] transform = "matrix("+str(mx[0])+","+str(mx[1])+","+str(mx[2])+","+str(mx[3])+","+str(mx[4])+","+str(mx[5])+") " # we need to update the transform attribute of the current group # print "Apply transform:",transform DOM.setElemAttribute(self.ctx["transform_group"], "transform", transform)
def clear(self): """ Clears the entire canvas. Also deletes the context stack and current path TODO: NEED TO RESET STYLES? TODO: NEED TO RESET STYLES? """ # as long as the canvas has children other than our <defs> element while DOM.getChildCount(self.canvas) > 1: # remove the second one (skip defs) DOM.removeChild(self.canvas, DOM.getChild(self.canvas, 1)) # # init styles context stack # self.ctx_stack = [] # # init current context # self._init_context() # also reset path self.beginPath()
def _apply_current_transforms(self): # if the current transform group already has elements if DOM.getChildCount(self.ctx["transform_group"]) > 0: # we create a new one group = self._createElementSVG("g") # add a new transform group to the canvas DOM.appendChild(self.canvas, group) # and make it the current tranform group self.ctx["transform_group"] = group # build the transform spec # just to make the next line shorter mx = self.ctx["matrix"] transform = "matrix(" + str(mx[0]) + "," + str(mx[1]) + "," + str( mx[2]) + "," + str(mx[3]) + "," + str(mx[4]) + "," + str( mx[5]) + ") " # we need to update the transform attribute of the current group # print "Apply transform:",transform DOM.setElemAttribute(self.ctx["transform_group"], "transform", transform)
def addItem(self, item, asHTML=None, popup=None): if not hasattr(item, "setSubMenu"): item = MenuItem(item, asHTML, popup) if self.vertical: tr = DOM.createTR() DOM.appendChild(self.body, tr) else: self._checkVerticalContainer() if len(self.items) == self.itemsPerRow: DOM.appendChild(self.body, DOM.createTR()) count = DOM.getChildCount(self.body) tr = DOM.getChild(self.body, count - 1) DOM.appendChild(tr, item.getElement()) item.setParentMenu(self) item.setSelectionStyle(False) self.items.append(item) return item
def addItem(self, item, asHTML=None, popup=None): if not hasattr(item, "setSubMenu"): item = MenuItem(item, asHTML, popup) if self.vertical: tr = DOM.createTR() DOM.appendChild(self.body, tr) else: self._checkVerticalContainer() if len(self.items) == self.itemsPerRow: DOM.appendChild(self.body, DOM.createTR()) count = DOM.getChildCount(self.body) tr = DOM.getChild(self.body, count-1) DOM.appendChild(tr, item.getElement()) item.setParentMenu(self) item.setSelectionStyle(False) self.items.append(item) return item
def clearItems(self): container = self.getItemContainerElement() while DOM.getChildCount(container) > 0: DOM.removeChild(container, DOM.getChild(container, 0)) self.items = []
def realizeTable(self, beingAdded): bodyElement = self.getBody() while DOM.getChildCount(bodyElement) > 0: DOM.removeChild(bodyElement, DOM.getChild(bodyElement, 0)) rowCount = 1 colCount = 1 for child in self.dock_children: dir = child.getLayoutData().direction if dir == self.NORTH or dir == self.SOUTH: rowCount += 1 elif dir == self.EAST or dir == self.WEST: colCount += 1 rows = [] for i in range(rowCount): rows.append(DockPanelTmpRow()) rows[i].tr = DOM.createTR() DOM.appendChild(bodyElement, rows[i].tr) westCol = 0 eastCol = colCount - 1 northRow = 0 southRow = rowCount - 1 centerTd = None for child in self.dock_children: layout = child.getLayoutData() td = DOM.createTD() layout.td = td DOM.setAttribute(layout.td, "align", layout.hAlign) DOM.setStyleAttribute(layout.td, "verticalAlign", layout.vAlign) DOM.setAttribute(layout.td, "width", layout.width) DOM.setAttribute(layout.td, "height", layout.height) if layout.direction == self.NORTH: DOM.insertChild(rows[northRow].tr, td, rows[northRow].center) self.appendAndMaybeAdopt(td, child.getElement(), beingAdded) DOM.setIntAttribute(td, "colSpan", eastCol - westCol + 1) northRow += 1 elif layout.direction == self.SOUTH: DOM.insertChild(rows[southRow].tr, td, rows[southRow].center) self.appendAndMaybeAdopt(td, child.getElement(), beingAdded) DOM.setIntAttribute(td, "colSpan", eastCol - westCol + 1) southRow -= 1 elif layout.direction == self.WEST: row = rows[northRow] DOM.insertChild(row.tr, td, row.center) row.center += 1 self.appendAndMaybeAdopt(td, child.getElement(), beingAdded) DOM.setIntAttribute(td, "rowSpan", southRow - northRow + 1) westCol += 1 elif layout.direction == self.EAST: row = rows[northRow] DOM.insertChild(row.tr, td, row.center) self.appendAndMaybeAdopt(td, child.getElement(), beingAdded) DOM.setIntAttribute(td, "rowSpan", southRow - northRow + 1) eastCol -= 1 elif layout.direction == self.CENTER: centerTd = td if self.center is not None: row = rows[northRow] DOM.insertChild(row.tr, centerTd, row.center) self.appendAndMaybeAdopt(centerTd, self.center.getElement(), beingAdded)
def getItemCount(self): return DOM.getChildCount(self.getElement())
def clear(self): h = self.getElement() while DOM.getChildCount(h) > 0: DOM.removeChild(h, DOM.getChild(h, 0))
def checkIndex(self, index): elem = self.getElement() if (index < 0) or (index >= DOM.getChildCount(elem)): #throw new IndexOutOfBoundsException(); pass