本文整理汇总了Python中pyjamas.DOM类的典型用法代码示例。如果您正苦于以下问题:Python DOM类的具体用法?Python DOM怎么用?Python DOM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DOM类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_main_frame
def set_main_frame(frame):
global main_frame
main_frame = frame
from pyjamas import DOM
# ok - now the main frame has been set we can initialise the
# signal handlers etc.
DOM.init()
示例2: setWidth
def setWidth(self, width):
self.fontsize = math.floor(width / self.cols)
AbsolutePanel.setWidth(self, "%dpx" % (self.cols*self.fontsize))
ratio = self.fontsize / self.fontheight
DOM.setStyleAttribute(self.getElement(), 'fontSizeAdjust', str(ratio))
示例3: onBrowserEvent
def onBrowserEvent(self, event):
etype = DOM.eventGetType(event)
if etype in MOUSE_EVENTS:
if self._mousePreventDefault:
DOM.eventPreventDefault(event)
return fireMouseEvent(self._mouseListeners, self, event)
return False
示例4: onreadystatechange
def onreadystatechange():
if xhtoj.readyState == 4:
jsnode = 0
if xhtoj.status == 200:
txt = xhtoj.responseText
jsnode = None
if idname:
jsnode = DOM.getElementById(idname)
if jsnode is None:
jsnode = DOM.createElement('script')
#tst = DOM.createElement('html')
#tst.innerHTML = str
activate_javascript(txt)
if not on_load_fn is None:
wnd().alert(on_load_fn)
# eval(on_load_fn)
test_fn()
return 1
else:
jsnode = DOM.getElementById(idname)
if not jsnode is None:
jsnode.innerHTML = xhtoj.status
示例5: setSplitPosition
def setSplitPosition(self, px):
splitElem = self.panel.getSplitElement()
rootElemHeight = DOM.getOffsetHeight(self.panel.container)
splitElemHeight = DOM.getOffsetHeight(splitElem)
# layout not settled, set height to what it _should_ be... yuk.
if splitElemHeight == 0:
splitElemHeight = 7
if rootElemHeight < splitElemHeight:
return
newBottomHeight = rootElemHeight - px - splitElemHeight
if px < 0:
px = 0
newBottomHeight = rootElemHeight - splitElemHeight
elif newBottomHeight < 0:
px = rootElemHeight - splitElemHeight
newBottomHeight = 0
self.updateElements(self.panel.getWidgetElement(0),
splitElem,
self.panel.getWidgetElement(1),
px, px + splitElemHeight, newBottomHeight)
示例6: validarParametrosMatriz
def validarParametrosMatriz():
lm1 = DOM.getElementById("lm1")
lm1 = lm1.value
cm1 = DOM.getElementById("cm1")
cm1 = cm1.value
lm2 = DOM.getElementById("lm2")
lm2 = lm2.value
cm2 = DOM.getElementById("cm2")
cm2 = cm2.value
if not lm1 or not lm2:
Window.alert("Informe o numero de linhas da matriz M1 e M2.")
return False
if lm1 != lm2:
Window.alert("A quantidade de linhas da matriz M1 deve ser igual a da matriz M2 para operação de soma.")
return False
if lm1 > "5" or lm2 > "5" or len(lm1) != 1 or len(lm2) != 1:
Window.alert("A quantidade de linhas da matriz M1 e da matriz M2, deve ser menor ou igual a 5.")
return False
if not cm1 or not cm2:
Window.alert("Informe o numero de colunas da matriz M1 e M2.")
return False
if cm1 != cm2:
Window.alert("A quantidade de colunas da matriz M1 deve ser igual a da matriz M2 para operação de soma.")
return False
if cm1 > "7" or cm2 > "7" or len(cm1) != 1 or len(cm2) != 1:
Window.alert("A quantidade de colunas da matriz M1 e da matriz M2, deve ser menor ou igual a 7.")
return False
return True
示例7: onDrop
def onDrop(self, event):
dt = event.dataTransfer
item = dt.getData("Text")
data = json.decode(item)
if 'name' in data and 'age' in data:
age = data['age']
name = data['name']
self.removeStyleName('dragover')
if self.age_is_ok(age):
self.addStudent(name, age)
dt.dropEffect = 'copy'
self.addStyleName('flash')
def removeFlash(timer):
self.removeStyleName('flash')
Timer(250, notify=removeFlash)
else:
dt.dropEffect = 'none'
self.addMessage('student could not be added')
# setting dropEffect to 'none' should be sufficient to notify
# that the drop failed, but
# we need to cheat a bit for now...
# this is the only reason for parent id in data
item_parent_id = data['parent']
item_parent = self.parent.containerFromId(item_parent_id)
item_parent.addStyleName('drop_fail')
# prevent default allows onDragEnd to see the dropEffect we set here
DOM.eventPreventDefault(event)
示例8: onClick
def onClick(self, sender=None):
"""
Called when the user finishes clicking on this button.
The default behavior is to fire the click event to
listeners. Subclasses that override onClickStart() should
override this method to restore the normal widget display.
"""
# Allow the click we're about to synthesize to pass through to the
# superclass and containing elements. Element.dispatchEvent() is
# synchronous, so we simply set and clear the flag within this method.
self.allowClick = True
# Mouse coordinates are not always available (e.g., when the click is
# caused by a keyboard event).
evt = None # we NEED to initialize evt, to be in the same namespace
# as the evt *inside* of JS block
# We disallow setting the button here, because IE doesn't provide the
# button property for click events.
# there is a good explanation about all the arguments of initMouseEvent
# at: https://developer.mozilla.org/En/DOM:event.initMouseEvent
DOM.buttonClick(self.getElement())
self.allowClick = False
示例9: onDragStart
def onDragStart(self, event):
dt = event.dataTransfer
target = DOM.eventGetTarget(event)
target = Widget(Element=target)
id = target.getID()
dt.setData("Text", "Dropped %s" % target.getID())
dt.effectAllowed = 'copy'
if id == 'imgdrag1':
parent = self.getParent()
while not hasattr(parent, 'h2'):
parent = parent.getParent()
dt.setDragImage(parent.h2.getElement(), 10, 10)
elif id == 'imgdrag2':
dt.setDragImage(doc().getElementById('logo'), 10, 10)
elif id == 'imgdrag3':
# OK, it's a bit of a cheat, but the following works on current
# Opera, IE, Firefox, Safari, Chrome.
ctx = GWTCanvas(50, 50)
self.makeCanvasImg(ctx)
try:
img = DOM.createImg()
DOM.setAttribute(img, 'src', ctx.canvas.toDataURL())
dt.setDragImage(img, 25, 25)
except:
dt.setDragImage(ctx.canvas, 25, 25)
示例10: addMessage
def addMessage(self, text):
d = datetime.now().strftime("%x %X")
li = DOM.createElement('li')
DOM.setInnerHTML(li,
'<dt class="time">%s</dt><dd class="txt">%s</dd>' % (
d, text))
DOM.insertChild(self.element, li, 0)
示例11: buildDOM
def buildDOM(self):
leftDiv = self.getWidgetElement(0)
rightDiv = self.getWidgetElement(1)
splitDiv = self.getSplitElement()
DOM.appendChild(self.getElement(), self.container)
DOM.appendChild(self.container, leftDiv)
DOM.appendChild(self.container, splitDiv)
DOM.appendChild(self.container, rightDiv)
# Sadly, this is the only way I've found to get vertical
# centering in this case. The usually CSS hacks (display:
# table-cell, vertical-align: middle) don't work in an
# absolute positioned DIV.
thumb_html = '<img src="splitPanelThumb.png" />'
DOM.setInnerHTML(splitDiv,
"<table class='hsplitter' height='100%' cellpadding='0' " +
"cellspacing='0'><tr><td align='center' valign='middle'>" +
thumb_html +
"</td></tr></table>")
self.addScrolling(leftDiv)
self.addScrolling(rightDiv)
示例12: setHTML
def setHTML(self, html):
"""Set the face's contents as html."""
self.face = DOM.createDiv()
UIObject.setStyleName(self.button, self.face, self.STYLENAME_HTML_FACE,
True)
DOM.setInnerHTML(self.face, html)
self.button.updateButtonFace()
示例13: findTextPoint
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
示例14: fillText
def fillText(self, text, startX, startY, maxWidth=None):
"""
Places text, at the specified start
coords, according to the current fillstyle.
@param startX x coord of the top left corner in the destination space
@param startY y coord of the top left corner in the destination space
@param maxWidth maximum width of text
"""
# create an SVG text element
text_elem = self._createElementSVG("text")
# integerize the coordinates
xy = self._integerize(startX, startY)
# add the size and position
DOM.setElemAttribute(text_elem, "x", str(xy[0]))
DOM.setElemAttribute(text_elem, "y", str(xy[1]))
if maxWidth is not None:
DOM.setElemAttribute(text_elem, "textLength", str(maxWidth))
# add the fill styles
style = "font:"+self.ctx["font"]+";fill:"+str(self.ctx["fill"])
DOM.setElemAttribute(text_elem, "style", style)
# now add the text
DOM.setInnerText(text_elem, text)
# add the rect element to the canvas
self._addElementSVG(text_elem)
示例15: moveControl
def moveControl(self, mouse_x, mouse_y, first_move=False):
handle_height = DOM.getIntAttribute(self.handle, "offsetHeight")
widget_height = self.getOffsetHeight()
height_range = widget_height - 10 # handle height is hard-coded
relative_y = mouse_y - (handle_height / 2)
if relative_y < 0:
relative_y = 0
if relative_y >= height_range:
relative_y = height_range
# turn round (bottom to top) for x
relative_y = height_range - relative_y
handle_width = DOM.getIntAttribute(self.handle, "offsetWidth")
widget_width = self.getOffsetWidth()
length_range = widget_width - 10 # handle width is hard-coded
relative_x = mouse_x - (handle_width / 2)
if relative_x < 0:
relative_x = 0
if relative_x >= length_range:
relative_x = length_range
val_diff_x = self.max_value_x - self.min_value_x
new_value_x = ((val_diff_x * relative_x) / length_range) + \
self.min_value_x
val_diff_y = self.max_value_y - self.min_value_y
new_value_y = ((val_diff_y * relative_y) / height_range) + \
self.min_value_y
new_value = [new_value_x, new_value_y]
new_value = self.processValue(new_value)
self.setControlPos(new_value)
self.setValue(new_value)