本文整理汇总了Python中pyjamas.DOM.createSpan方法的典型用法代码示例。如果您正苦于以下问题:Python DOM.createSpan方法的具体用法?Python DOM.createSpan怎么用?Python DOM.createSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyjamas.DOM
的用法示例。
在下文中一共展示了DOM.createSpan方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getBoundingBox
# 需要导入模块: from pyjamas import DOM [as 别名]
# 或者: from pyjamas.DOM import createSpan [as 别名]
def getBoundingBox(self, textNode, offset1, offset2):
HtmlBBox res
String text = textNode.getData()
int len = text.length()
if (offset1 == 0) and (offset2 == len):
# Shortcut
return getBoundingBox(textNode)
if (offset2 > len) or (offset1 > offset2):
return None
# If this is a cursor, we still need to outline one character
boolean isCursor = (offset1 == offset2)
boolean posRight = False
if isCursor:
if offset1 == len:
offset1--
posRight = True
else:
offset2++
# Create 2 or 3 spans of this text, so we can measure
List<Element> nodes = ArrayList<Element>(3)
Element tmpSpan, measureSpan
if offset1 > 0:
# First
tmpSpan = DOM.createSpan()
tmpSpan.setInnerHTML(text.substring(0, offset1))
nodes.add(tmpSpan)
# Middle, the one we measure
measureSpan = DOM.createSpan()
measureSpan.setInnerHTML(text.substring(offset1, offset2))
nodes.add(measureSpan)
if offset2 < (len - 1):
# Last
tmpSpan = DOM.createSpan()
tmpSpan.setInnerHTML(text.substring(offset2 + 1))
nodes.add(tmpSpan)
Node parent = textNode.getParentNode()
for Node node : nodes:
parent.insertBefore(node, textNode)
示例2: replaceLinks
# 需要导入模块: from pyjamas import DOM [as 别名]
# 或者: from pyjamas.DOM import createSpan [as 别名]
def replaceLinks(self, tagname="a"):
""" replaces <tag href="#pagename">sometext</tag> with:
Hyperlink("sometext", "pagename")
"""
tags = self.findTags(tagname)
pageloc = Window.getLocation()
pagehref = pageloc.getPageHref()
for el in tags:
href = el.href
l = href.split("#")
if len(l) != 2:
continue
if l[0] != pagehref:
continue
token = l[1]
if not token:
continue
html = DOM.getInnerHTML(el)
parent = DOM.getParent(el)
index = DOM.getChildIndex(parent, el)
hl = Hyperlink(TargetHistoryToken=token,
HTML=html,
Element=DOM.createSpan())
DOM.insertChild(parent, hl.getElement(), index)
self.children.insert(index, hl)
parent.removeChild(el)
示例3: getBoundingBox
# 需要导入模块: from pyjamas import DOM [as 别名]
# 或者: from pyjamas.DOM import createSpan [as 别名]
def getBoundingBox(self, textNode):
"""
Create a bounding box the size of the given text node. Note that this
temporarily modifies the document to surround this node with a Span.
@param textNode Text to create bounding box around
@return a bounding box
"""
Element el = DOM.createSpan()
surround(textNode, el)
HtmlBBox res = HtmlBBox(el)
unSurround(el)
return res
示例4: initElement
# 需要导入模块: from pyjamas import DOM [as 别名]
# 或者: from pyjamas.DOM import createSpan [as 别名]
def initElement(self, element, **ka):
self.inputElem = element
self.labelElem = DOM.createLabel()
element = ka.pop('Element', None) or DOM.createSpan()
ButtonBase.__init__(self, element, **ka)
self.sinkEvents(Event.FOCUSEVENTS | Event.ONCLICK)
DOM.appendChild(self.getElement(), self.inputElem)
DOM.appendChild(self.getElement(), self.labelElem)
uid = "check%d" % self.getUniqueID()
DOM.setAttribute(self.inputElem, "id", uid)
DOM.setAttribute(self.labelElem, "htmlFor", uid)
示例5: __init__
# 需要导入模块: from pyjamas import DOM [as 别名]
# 或者: from pyjamas.DOM import createSpan [as 别名]
def __init__(self, worksheet, id):
SimplePanel.__init__(self)
MouseHandler.__init__(self)
self._id = id
self._worksheet = worksheet
insert_new_cell = HTML("", StyleName="insert_new_cell")
insert_new_cell.addClickListener(InsertListener(worksheet, self._id))
input_prompt = HTML("In [%d]:" % self._id, Element=DOM.createSpan(),
StyleName="input_prompt")
cell_input = InputArea(worksheet, self._id, StyleName='cell_input')
evaluate_button = HTML("evaluate", Element=DOM.createAnchor(),
StyleName="eval_button", Visible=False)
evaluate_button.getElement().setAttribute("href", "")
evaluate_button.addClickListener(EvaluateListener(self))
evaluate_button.addMouseListener(self)
output_delimiter = HTML("", StyleName="output_delimiter")
output_prompt = HTML("Out[%d]:" % self._id, Element=DOM.createSpan(),
StyleName="output_prompt")
cell_output = HTML("", Element=DOM.createSpan(),
StyleName="cell_output")
output_prompt.setVisible(False)
p = FlowPanel(StyleName="cell")
p.add(insert_new_cell)
p.add(input_prompt)
p.add(cell_input)
p.add(evaluate_button)
p.add(output_delimiter)
p.add(output_prompt)
p.add(cell_output)
self.add(p)
self._cell_input = cell_input
self._cell_output = cell_output
self._output_prompt = output_prompt
self._evaluate_button = evaluate_button
self._mouse_in = False
示例6: initElement
# 需要导入模块: from pyjamas import DOM [as 别名]
# 或者: from pyjamas.DOM import createSpan [as 别名]
def initElement(self, element, **kwargs):
self.inputElem = element
self.labelElem = DOM.createLabel()
if kwargs.has_key('Element'):
element = kwargs.pop('Element')
else:
element = DOM.createSpan()
ButtonBase.__init__(self, element, **kwargs)
self.unsinkEvents(Event.FOCUSEVENTS| Event.ONCLICK)
DOM.sinkEvents(self.inputElem, Event.FOCUSEVENTS | Event.ONCLICK | DOM.getEventsSunk(self.inputElem))
DOM.appendChild(self.getElement(), self.inputElem)
DOM.appendChild(self.getElement(), self.labelElem)
uid = "check%d" % self.getUniqueID()
DOM.setAttribute(self.inputElem, "id", uid)
DOM.setAttribute(self.labelElem, "htmlFor", uid)
示例7: __init__
# 需要导入模块: from pyjamas import DOM [as 别名]
# 或者: from pyjamas.DOM import createSpan [as 别名]
def __init__(self, html=None, wordWrap=True, **kwargs):
kwargs['StyleName'] = kwargs.get('StyleName', "gwt-InlineHTML")
kwargs['Element'] = DOM.createSpan()
HTML.__init__(self, html, wordWrap, **kwargs)
示例8: __init__
# 需要导入模块: from pyjamas import DOM [as 别名]
# 或者: from pyjamas.DOM import createSpan [as 别名]
def __init__(self, html=None, **ka):
self.children = []
self.attached = False
self.contentPanel = None
self.itemTable = None
self.contentElem = None
self.imgElem = None
self.childSpanElem = None
self.open = False
self.parent = None
self.selected = False
self.tree = None
self.userObject = None
element = ka.pop('Element', None) or DOM.createDiv()
self.setElement(element)
self.itemTable = DOM.createTable()
self.contentElem = DOM.createSpan()
self.childSpanElem = DOM.createSpan()
self.imgElem = DOM.createImg()
tbody = DOM.createTBody()
tr = DOM.createTR()
tdImg = DOM.createTD()
tdContent = DOM.createTD()
DOM.appendChild(self.itemTable, tbody)
DOM.appendChild(tbody, tr)
DOM.appendChild(tr, tdImg)
DOM.appendChild(tr, tdContent)
DOM.setStyleAttribute(tdImg, "verticalAlign", "middle")
DOM.setStyleAttribute(tdContent, "verticalAlign", "middle")
DOM.setStyleAttribute(self.getElement(), "cursor", "pointer")
DOM.appendChild(self.getElement(), self.itemTable)
DOM.appendChild(self.getElement(), self.childSpanElem)
DOM.appendChild(tdImg, self.imgElem)
DOM.appendChild(tdContent, self.contentElem)
# XXX - can't set pos relative on a div node,
# or white_space on an HTML Table..
try:
DOM.setAttribute(self.getElement(), "position", "relative")
except:
pass
DOM.setStyleAttribute(self.contentElem, "display", "inline")
DOM.setStyleAttribute(self.getElement(), "whiteSpace", "nowrap")
try:
DOM.setAttribute(self.itemTable, "whiteSpace", "nowrap")
except:
pass
DOM.setStyleAttribute(self.childSpanElem, "whiteSpace", "nowrap")
self.setStyleName(self.contentElem, "gwt-TreeItem", True)
#if not ka.has_key('StyleName'): ka['StyleName']="gwt-TreeItem"
if html is not None:
try:
# messy. pyjd can do unicode, pyjs can't
if isinstance(html, unicode):
ka['HTML'] = html
elif isinstance(html, basestring):
ka['HTML'] = html
else:
ka['Widget'] = html
except:
if isinstance(html, basestring):
ka['HTML'] = html
else:
ka['Widget'] = html
UIObject.__init__(self, **ka)
示例9: __init__
# 需要导入模块: from pyjamas import DOM [as 别名]
# 或者: from pyjamas.DOM import createSpan [as 别名]
def __init__(self, text=None, wordWrap=True, **kwargs):
kwargs['StyleName'] = kwargs.get('StyleName', "gwt-InlineLabel")
kwargs['Element'] = DOM.createSpan()
Label.__init__(self, text, wordWrap, **kwargs)
示例10: onClick
# 需要导入模块: from pyjamas import DOM [as 别名]
# 或者: from pyjamas.DOM import createSpan [as 别名]
def onClick(sender):
Window.alert('Make service request using %s'%sender.getID())
if __name__ == '__main__':
pyjd.setup("public/Anchor.html")
# EXAMPLE 1
a1 = Anchor(Widget = HTML('Test 1: Anchor to external site using HTML widget.'), Href='http://pyjs.org', Title = 'Test1')
RootPanel().add(a1)
# EXAMPLE 2
label = Label(text = 'Test 2: Click listener added to a label.')
label.addClickListener(onClick)
RootPanel().add(label)
# EXAMPLE 3
a2 = Hyperlink(text = 'Hyperlink', Element = DOM.createSpan())
a2.setID('param1')
a2.addClickListener(onClick)
html2=HTMLPanel("Test 3: <span id ='t3'></span> added to HTMLPanel with click listener.")
html2.add(a2, "t3")
RootPanel().add(html2)
# EXAMPLE 4
hpanel = HorizontalPanel()
hpanel.append(HTML('Test 4: Anchor to external site using Image widget'))
a3 = Anchor(Widget = Image('http://pyjs.org/assets/images/pyjs.128x128.png'), Href='http://pyjs.org', Title = 'Test4')
hpanel.append(a3)
RootPanel().add(hpanel)
# EXAMPLE 5
serverXml = \
"""
<html>