def remove(self, child, index=None): if index is None: if isinstance(child, int): index = child child = self.getWidget(child) else: index = self.getWidgetIndex(child) if child.getParent() != self: return False if self.visibleStack == index: self.visibleStack = -1 elif self.visibleStack > index: self.visibleStack -= 1 rowIndex = 2 * index tr = DOM.getChild(self.body, rowIndex) DOM.removeChild(self.body, tr) tr = DOM.getChild(self.body, rowIndex) DOM.removeChild(self.body, tr) CellPanel.remove(self, child) rows = self.getWidgetCount() * 2 #for (int i = rowIndex; i < rows; i = i + 2) { for i in range(rowIndex, rows, 2): childTR = DOM.getChild(self.body, i) td = DOM.getFirstChild(childTR) curIndex = self._getIndex(td) self._setIndex(td, index) index += 1 return True
def setStackText(self, index, text, asHTML=False): if index >= self.getWidgetCount(): return td = DOM.getChild(DOM.getChild(self.body, index * 2), 0) if asHTML: DOM.setInnerHTML(td, text) else: DOM.setInnerText(td, text)
def getCellElement(self, row, cell) : """ Get a specific Element from the panel. @param row the row index @param cell the cell index @return the Element at the given row and cell """ tr = DOM.getChild(self.tbody, row) td = DOM.getChild(tr, cell) return DOM.getFirstChild(td)
def setStackVisible(self, index, visible): tr = DOM.getChild(self.body, (index * 2)) if tr is None: return td = DOM.getFirstChild(tr) self.setStyleName(td, "gwt-StackPanelItem-selected", visible) tr = DOM.getChild(self.body, (index * 2) + 1) self.setVisible(tr, visible) self.getWidget(index).setVisible(visible)
def inicia(self): global IMAGEREPO self.__form = f = DOM.getElementById('mainform') self.x = DOM.getChild(f,0).value #DOM.getElementByName('_xsrf').value g = DOM.getChild(f,1).value self.scored = DOM.getChild(f,2) self.housed = DOM.getChild(f,3) if g == '12de6b622cbfe4d8f5c8d3347e56ae8c': IMAGEREPO = 'imagens/' #self.talk(self.scored.value+self.housed.value+IMAGEREPO) self._socket = NullSocket() #WebSocket("ws://%s/chatsocket"%self.test()) self._socket.register_receiver(self.game.receive) obj = j_p.wdecode(self.housed.value) #self.text(400,85, str(obj) ,'darkbrown',10) #obj = [dict(body='nonono')] return obj
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 removeItem(self, item): try: idx = self.items.index(item) except ValueError: return container = self.getItemContainerElement() DOM.removeChild(container, DOM.getChild(container, idx)) del self.items[idx]
def getItemContainerElement(self, item): if self.vertical: return self.body else: self._checkVerticalContainer() if self.itemsPerRow: row = items / self.itemsPerRow else: row = 0 return DOM.getChild(self.body, row)
def insertItem(self, item, index): if self.vertical: tr = DOM.createTR() DOM.insertChild(self.body, tr, index) else: self._checkVerticalContainer() tr = DOM.getChild(self.body, 0) DOM.insertChild(tr, item.getElement(), index) item.setParentMenu(self) item.setSelectionStyle(False) self.items.insert(index, item)
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 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: tr = DOM.getChild(self.body, 0) DOM.appendChild(tr, item.getElement()) item.setParentMenu(self) item.setSelectionStyle(False) self.items.append(item) return item
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 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 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 __init__(self, rowStyles=None, containerIndex=1, **kwargs): """ Creates a new panel using the specified style names to apply to each row. Each row will contain three cells (Left, Center, and Right). The Center cell in the containerIndex row will contain the {@link Widget}. @param rowStyles an array of style names to apply to each row @param containerIndex the index of the container row """ if rowStyles is None: rowStyles = self.DEFAULT_ROW_STYLENAMES if kwargs.has_key('Element'): self.table = kwargs.pop('Element') fc = DOM.getFirstChild(self.table) if fc: self.tbody = fc else: self.tbody = DOM.createTBody() DOM.appendChild(self.table, self.tbody) else: # Add a tbody self.table = DOM.createTable() self.tbody = DOM.createTBody() DOM.appendChild(self.table, self.tbody) DOM.setAttribute(self.table, "cellSpacing", "0") DOM.setAttribute(self.table, "cellPadding", "0") if not kwargs.has_key('StyleName'): kwargs['StyleName']=self.DEFAULT_STYLENAME SimplePanel.__init__(self, self.table, **kwargs) # Add each row for i in range(len(rowStyles)): row = self.createTR(rowStyles[i]) DOM.appendChild(self.tbody, row) if i == containerIndex: self.containerElem = DOM.getFirstChild(DOM.getChild(row, 1))
def setItemSelected(self, index, selected): self.checkIndex(index) option = DOM.getChild(self.getElement(), index) DOM.setIntAttribute(option, "selected", selected and 1 or 0)
def clearItems(self): container = self.getItemContainerElement() while DOM.getChildCount(container) > 0: DOM.removeChild(container, DOM.getChild(container, 0)) self.items = []
def getItemContainerElement(self): if self.vertical: return self.body else: return DOM.getChild(self.body, 0)
def getElement(self, row, column): self.outer.checkCellBounds(row, column) return DOM.getChild(self.outer.rowFormatter.getRow(self.outer.bodyElem, row), column)
def ensureElement(self, row, column): self.outer.prepareCell(row, column) return DOM.getChild(self.outer.rowFormatter.ensureElement(row), column)
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 setValue(self, index, value): self.checkIndex(index) option = DOM.getChild(self.getElement(), index) DOM.setAttribute(option, "value", value)
def clear(self): h = self.getElement() while DOM.getChildCount(h) > 0: DOM.removeChild(h, DOM.getChild(h, 0))
def getItemText(self, index): child = DOM.getChild(self.getElement(), index) return DOM.getInnerText(child)
def removeItem(self, idx): child = DOM.getChild(self.getElement(), idx) DOM.removeChild(self.getElement(), child)
def isItemSelected(self, index): self.checkIndex(index) option = DOM.getChild(self.getElement(), index) return DOM.getBooleanAttribute(option, "selected")
def getValue(self, index): self.checkIndex(index) option = DOM.getChild(self.getElement(), index) return DOM.getAttribute(option, "value")