def getStyleAttribute(self, attribute): """ can be called with two forms: getStyleAttribute(self, attr) - returns value getStyleAttribute(self, (attr1,attr2,...)) - returns dictionary of attr:value pairs """ if isinstance(attribute, basestring): return DOM.getStyleAttribute(self.getElement(), attribute) # if attribute is not a string, assume it is iterable, # and return the multi-attribute form el = self.getElement() result = {} for attr in attribute: result[attr] = DOM.getStyleAttribute(el, attr) return result
def identify(self, element): if element.nodeType != 1: return False if str(string.lower(element.tagName)) != 'span': return False style = DOM.getStyleAttribute(element, "font-family") return style is not None
def hidePanelRight(self): if DOM.getStyleAttribute( self.mainPanel.getWidgetTd(self.cod), 'display') == '': # bug: "block" in <td> not work's on firefox DOM.setStyleAttribute(self.mainPanel.getWidgetTd(self.cod), "display", "none") self.showHideRight.setStyleName('control_bar open_left')
def showHidePanelRight(self): if DOM.getStyleAttribute(self.mainPanel.getWidgetTd(self.cod), 'display') == 'none': DOM.setStyleAttribute(self.mainPanel.getWidgetTd(self.cod), "display", "") self.showHideRight.setStyleName('control_bar close_right') else: DOM.setStyleAttribute(self.mainPanel.getWidgetTd(self.cod), "display", "none") self.showHideRight.setStyleName('control_bar open_left')
def setDragImage(self, element, x, y): position_absolute = DOM.getStyleAttribute(element, 'position') == 'absolute' if position_absolute: self.dragLeftOffset = x + DOM.getAbsoluteLeft(element.offsetParent) self.dragTopOffset = y + DOM.getAbsoluteTop(element.offsetParent) else: self.dragLeftOffset = x self.dragTopOffset = y if element.tagName.lower().endswith('img'): src = DOM.getAttribute(element, 'src') element = DOM.createElement('img') DOM.setAttribute(element, 'src', src) if not self.draggingImage: self.createDraggingImage(element) else: self.draggingImage.setImage(element)
def showHidePanelMonitor(self): if DOM.getStyleAttribute( DOM.getParent(self.center.getWidgetTd(self.serialMonitor)), 'display') == 'none': DOM.setStyleAttribute( DOM.getParent(self.center.getWidgetTd(self.serialMonitor)), "display", "") self.showHideMonitor.setStyleName('collapse open_down') #JS("""addCodeBenderPlugin();@{{!addCodeBenderPlugin}}();""") DOM.setStyleAttribute(self.resizeMonitor.getElement(), "display", "") else: DOM.setStyleAttribute( DOM.getParent(self.center.getWidgetTd(self.serialMonitor)), "display", "none") self.showHideMonitor.setStyleName('collapse close_up') DOM.setStyleAttribute(self.resizeMonitor.getElement(), "display", "none")
def setDragImage(self, element, x, y): position_absolute = DOM.getStyleAttribute(element, 'position') == 'absolute' if position_absolute: self.dragLeftOffset = x + DOM.getAbsoluteLeft( element.offsetParent) self.dragTopOffset = y + DOM.getAbsoluteTop( element.offsetParent) else: self.dragLeftOffset = x self.dragTopOffset = y if element.tagName.lower().endswith('img'): src = DOM.getAttribute(element,'src') element = DOM.createElement('img') DOM.setAttribute(element, 'src', src) if not self.draggingImage: self.createDraggingImage(element) else: self.draggingImage.setImage(element)
def copyStyles(elem1, elem2): """ Copy styles from one element to another, like in http://efreedom.com/Question/1-1848445/Duplicating-Element-Style-JavaScript """ element_style = getComputedStyle(elem1) if element_style: element_style = dict(element_style) else: return for style in element_style: try: value = element_style[style] if isinstance(value, str): if not style == 'cssText': DOM.setStyleAttribute(elem2, style, value) if value == 'font': DOM.setStyleAttribute(elem2, 'fontSize', DOM.getStyleAttribute(elem1, 'fontSize')) except: pass
def copyStyles(elem1, elem2): """ Copy styles from one element to another, like in http://efreedom.com/Question/1-1848445/Duplicating-Element-Style-JavaScript """ element_style = getComputedStyle(elem1) if element_style: element_style = dict(element_style) else: return for style in element_style: try: value = element_style[style] if isinstance(value, str): if not style == 'cssText': DOM.setStyleAttribute(elem2, style, value) if value == 'font': DOM.setStyleAttribute( elem2, 'fontSize', DOM.getStyleAttribute(elem1, 'fontSize')) except: pass
def onMouseMove(self, sender, x, y): event = DOM.eventGetCurrentEvent() self.mouseEvent = event button = DOM.eventGetButton(event) if not button == Event.BUTTON_LEFT: return ## The following commented code lets the native dnd happen in IE. sucks. ## But it may enable dragging our widgets out of IE into other apps. # else: # try: # self.dragWidget.getElement().dragDrop() # return # except: # pass # Adjust x and y to absolute coordinates. x, y = eventCoordinates(event) if self.dragging == DRAGGING_NO_MOVEMENT_YET: self.origMouseX = x self.origMouseY = y self.currentDragOperation = 'none' fromElement = self.dragWidget.getElement() # Is the widget itself draggable? try: draggable = fromElement.draggable except: draggable = False # if not, find the draggable element at (x, y) in the widget if not draggable: fromElement = findDraggable(sender.getElement(), self.origMouseX, self.origMouseY) # Nothing draggable found. return. if fromElement is None: self.dragging = NOT_DRAGGING return # Get the location for the dragging widget #self.absParent = None #self.absParent = self.dragWidget.getParent() #self.absLeft = DOM.getStyleAttribute(fromElement, 'left') #print self.absLeft #self.absTop = DOM.getStyleAttribute(fromElement, 'top') #print self.absTop #self.origTop = DOM.getAbsoluteTop(fromElement) + parent.getAbsoluteTop() #self.origLeft = DOM.getAbsoluteLeft(fromElement) + parent.getAbsoluteLeft() self.origTop = DOM.getAbsoluteTop(fromElement) self.origLeft = DOM.getAbsoluteLeft(fromElement) #self.glassTop = DOM.getAbsoluteTop(fromElement.offsetParent) #self.glassLeft = DOM.getAbsoluteTop(fromElement.offsetParent) position_absolute = DOM.getStyleAttribute(fromElement, 'position') == 'absolute' if position_absolute: self.dragLeftOffset = ( self.origMouseX - DOM.getAbsoluteLeft(fromElement.offsetParent)) self.dragTopOffset = ( self.origMouseY - DOM.getAbsoluteTop(fromElement.offsetParent)) else: self.dragLeftOffset = self.origMouseX - self.origLeft self.dragTopOffset = self.origMouseY - self.origTop # self.setDragImage(fromElement, # self.origMouseX - self.origLeft, # self.origMouseY - self.origTop) self.dragDataStore.elements = [fromElement] dragStartEvent = self.fireDNDEvent('dragstart', None, self.dragWidget) if not isCanceled(dragStartEvent): self.initFeedbackImage() RootPanel().add(self.draggingImage) self.setDragImageLocation(x, y) self.dragging = ACTIVELY_DRAGGING GlassWidget.show(self) elif self.dragging == ACTIVELY_DRAGGING: try: doc().selection.empty() except: wnd().getSelection().removeAllRanges() self.setDragImageLocation(x, y) # If we are still working on the previous iteration, or if we have # done this recently, we'll wait for the next event. if self.dragBusy or time.time() - self.drag_time < 0.25: return self.doDrag(event, x, y) self.drag_time = time.time()
def getWidgetTopPos(self, widget): self.checkWidgetParent(widget) return DOM.getStyleAttribute(widget.getElement(), "left")
def getWordWrap(self): ws = DOM.getStyleAttribute(self.getElement(), "whiteSpace") return ws != "nowrap"
def getWidth(self): return DOM.getStyleAttribute(self.element, "width")
def getWidgetPosition(self, widget): self.checkWidgetParent(widget) h = widget.getElement() return DOM.getStyleAttribute(h, "left"), DOM.getStyleAttribute(h, "top")
if info.initialDraggableParent instanceof AbsolutePanel: info.initialDraggableParentLocation = WidgetLocation(widget, info.initialDraggableParent) elif info.initialDraggableParent instanceof HorizontalPanel: info.initialDraggableIndex = ((HorizontalPanel) info.initialDraggableParent).getWidgetIndex(widget) elif info.initialDraggableParent instanceof VerticalPanel: info.initialDraggableIndex = ((VerticalPanel) info.initialDraggableParent).getWidgetIndex(widget) elif info.initialDraggableParent instanceof FlowPanel: info.initialDraggableIndex = ((FlowPanel) info.initialDraggableParent).getWidgetIndex(widget) elif info.initialDraggableParent instanceof SimplePanel: # save nothing else: raise RuntimeException( "Unable to handle 'initialDraggableParent instanceof " + GWT.getTypeName(info.initialDraggableParent) + "'; Please create your own DragController and override saveDraggableLocationAndStyle() and restoreDraggableLocation()") info.initialDraggableMargin = DOM.getStyleAttribute(widget.getElement(), "margin") DOM.setStyleAttribute(widget.getElement(), "margin", "0px") savedWidgetInfoMap.put(widget, info) def getIntersectDropController(self, x, y): DropController dropController = dropControllerCollection.getIntersectDropController(x, y) return dropController is not None ? dropController : boundaryDropController
def getTextAlignment(self, align): return DOM.getStyleAttribute(self.getElement(), "textAlign")
def getStyleAttr(self, row, column, attr): elem = self.getElement(row, column) return DOM.getStyleAttribute(elem, attr)
def onMouseMove(self, sender, x, y): event = DOM.eventGetCurrentEvent() self.mouseEvent = event button = DOM.eventGetButton(event) if not button == Event.BUTTON_LEFT: return ## The following commented code lets the native dnd happen in IE. sucks. ## But it may enable dragging our widgets out of IE into other apps. # else: # try: # self.dragWidget.getElement().dragDrop() # return # except: # pass # Adjust x and y to absolute coordinates. x, y = eventCoordinates(event) if self.dragging == DRAGGING_NO_MOVEMENT_YET: self.origMouseX = x self.origMouseY = y self.currentDragOperation = 'none' fromElement = self.dragWidget.getElement() # Is the widget itself draggable? try: draggable = fromElement.draggable except: draggable = False # if not, find the draggable element at (x, y) in the widget if not draggable: fromElement = findDraggable(sender.getElement(), self.origMouseX, self.origMouseY) # Nothing draggable found. return. if fromElement is None: self.dragging = NOT_DRAGGING return # Get the location for the dragging widget #self.absParent = None #self.absParent = self.dragWidget.getParent() #self.absLeft = DOM.getStyleAttribute(fromElement, 'left') #print self.absLeft #self.absTop = DOM.getStyleAttribute(fromElement, 'top') #print self.absTop #self.origTop = DOM.getAbsoluteTop(fromElement) + parent.getAbsoluteTop() #self.origLeft = DOM.getAbsoluteLeft(fromElement) + parent.getAbsoluteLeft() self.origTop = DOM.getAbsoluteTop(fromElement) self.origLeft = DOM.getAbsoluteLeft(fromElement) #self.glassTop = DOM.getAbsoluteTop(fromElement.offsetParent) #self.glassLeft = DOM.getAbsoluteTop(fromElement.offsetParent) position_absolute = DOM.getStyleAttribute(fromElement, 'position') == 'absolute' if position_absolute: self.dragLeftOffset = (self.origMouseX - DOM.getAbsoluteLeft(fromElement.offsetParent)) self.dragTopOffset = (self.origMouseY - DOM.getAbsoluteTop(fromElement.offsetParent)) else: self.dragLeftOffset = self.origMouseX - self.origLeft self.dragTopOffset = self.origMouseY - self.origTop # self.setDragImage(fromElement, # self.origMouseX - self.origLeft, # self.origMouseY - self.origTop) self.dragDataStore.elements = [fromElement] dragStartEvent = self.fireDNDEvent('dragstart', None, self.dragWidget) if not isCanceled(dragStartEvent): self.initFeedbackImage() RootPanel().add(self.draggingImage) self.setDragImageLocation(x, y) self.dragging = ACTIVELY_DRAGGING GlassWidget.show(self) elif self.dragging == ACTIVELY_DRAGGING: try: doc().selection.empty() except: wnd().getSelection().removeAllRanges() self.setDragImageLocation(x, y) # If we are still working on the previous iteration, or if we have # done this recently, we'll wait for the next event. if self.dragBusy or time.time() - self.drag_time < 0.25: return self.doDrag(event, x, y) self.drag_time = time.time()
def getWordWrap(self): return not (DOM.getStyleAttribute(self.getElement(), "whiteSpace") == "nowrap")
def getHeight(self): return DOM.getStyleAttribute(self.element, "height")
def getCellVerticalAlignment(self, widget): td = self.getWidgetTd(widget) if td is None: return None return DOM.getStyleAttribute(td, "verticalAlign")
def getCellWordWrap(self, widget): td = DOM.getParent(widget.getElement()) return DOM.getStyleAttribute(td, "whiteSpace") == "nowrap"