def add(self, widget): if self.getWidget(0) == None: self.setWidget(0, widget) elif self.getWidget(1) == None: self.setWidget(1, widget) else: console.error("SimplePanel can only contain one child widget")
def setName(self, name): if name is None: #throw new NullPointerException("Name cannot be null"); console.error("Name cannot be null") elif len(name) == 0: #throw new IllegalArgumentException("Name cannot be an empty string."); console.error("Name cannot be an empty string.") DOM.setAttribute(self.getElement(), "name", name)
def setName(self, name): if name is None: raise ValueError("Name cannot be null") console.error("Name cannot be null") elif len(name) == 0: raise ValueError("Name cannot be an empty string.") console.error("Name cannot be an empty string.") DOM.setAttribute(self.getElement(), "name", name)
def disown(self, widget): if widget.getParent() != self: console.error("widget %o is not a child of this panel %o", widget, self) else: element = widget.getElement() widget.setParent(None) parentElement = DOM.getParent(element) if parentElement: DOM.removeChild(parentElement, element)
def setSelectionRange(self, pos, length): if length < 0: # throw new IndexOutOfBoundsException("Length must be a positive integer. Length: " + length); console.error("Length must be a positive integer. Length: " + length) if (pos < 0) or (length + pos > len(self.getText())): #throw new IndexOutOfBoundsException("From Index: " + pos + " To Index: " + (pos + length) + " Text Length: " + getText().length()); console.error("From Index: %d " % pos + " To Index: %d " % (pos + length) + " Text Length: %d " % len(self.getText())) element = self.getElement() element.setSelectionRange(pos, pos + length)
def setSelectionRange(self, pos, length): if length < 0: # throw new IndexOutOfBoundsException("Length must be a positive integer. Length: " + length); console.error("Length must be a positive integer. Length: " + length) if (pos < 0) or (length + pos > len(self.getText())): #throw new IndexOutOfBoundsException("From Index: " + pos + " To Index: " + (pos + length) + " Text Length: " + getText().length()); console.error("From Index: " + pos + " To Index: " + (pos + length) + " Text Length: " + len(self.getText())) element = self.getElement() element.setSelectionRange(pos, pos + length)
def add(self, widget, direction): if direction == self.CENTER: if self.center is not None: console.error("Only one CENTER widget may be added") self.center = widget layout = LayoutData(direction) widget.setLayoutData(layout) self.setCellHorizontalAlignment(widget, self.horzAlign) self.setCellVerticalAlignment(widget, self.vertAlign) self.dock_children.append(widget) self.realizeTable(widget)
def attach(self, id, widget): """ Attach a widget onto the element with the given id; the element currently associated with the widget is discarded. """ if not self.loaded: self.toAttach.append(PendingAttachOrInsert(id, widget)) else: element = self.getElementById(id) if element: self.attachToElement(element, widget) else: console.error("Page error: No such element " + id) return widget
def insert(self, id, widget): """ Insert a widget into the element with the given id, at the end of its children. """ if not self.loaded: self.toInsert.append(PendingAttachOrInsert(id, widget)) else: element = self.getElementById(id) if element: self.adopt(widget, element) self.children.append(widget) else: console.error("Page error: No such element " + id) return widget
def checkWidgetParent(self, widget): if widget.getParent() != self: # TODO: raise as exception instead console.error("Widget must be a child of this panel.")
def add(self): console.error("This panel does not support no-arg add()")
def setParent(self, widget): # throw new UnsupportedOperationException("Cannot directly setParent on a WidgetTreeItem's ContentPanel"); console.error( "Cannot directly setParent on a WidgetTreeItem's ContentPanel")
def add(self, widget, tabText=None, asHTML=False): if tabText is None: console.error("A tabText parameter must be specified with add().") self.insert(widget, tabText, asHTML, self.getWidgetCount())
def setItemText(self, index, text): self.checkIndex(index) if text is None: console.error("Cannot set an option to have null text") return DOM.setOptionText(self.getElement(), text, index)
def remove(self, widget): #throw new UnsupportedOperationException("Widgets should never be directly removed from a tree") console.error("Widgets should never be directly removed from a tree")
def setParent(self, widget): # throw new UnsupportedOperationException("Cannot directly setParent on a WidgetTreeItem's ContentPanel"); console.error("Cannot directly setParent on a WidgetTreeItem's ContentPanel")
def add(self, widget): if self.getWidget() is not None: console.error("SimplePanel can only contain one child widget") return self.setWidget(widget)