Skip to content
Newer
Older
100644 73 lines (70 sloc) 2.6 KB
64df13d add Anchor widget
Luke Kenneth Casson Leighton authored Jul 16, 2010
1 import pyjd
2 from pyjamas.ui.RootPanel import RootPanel
d9b16a6 @gpitel add: more extensive examples on linking
gpitel authored Feb 15, 2013
3 from pyjamas import DOM
64df13d add Anchor widget
Luke Kenneth Casson Leighton authored Jul 16, 2010
4 from pyjamas.ui.Anchor import Anchor
d9b16a6 @gpitel add: more extensive examples on linking
gpitel authored Feb 16, 2013
5 from pyjamas.ui.Hyperlink import Hyperlink
6 from pyjamas import Window
7 from pyjamas.ui.HTML import HTML
8 from pyjamas.ui.HTMLPanel import HTMLPanel
9 from pyjamas.ui.Label import Label
10 from pyjamas.ui.Image import Image
11 from pyjamas.ui.HorizontalPanel import HorizontalPanel
64df13d add Anchor widget
Luke Kenneth Casson Leighton authored Jul 16, 2010
12
ab0d6ea @gpitel add: server html example
gpitel authored Feb 17, 2013
13
d9b16a6 @gpitel add: more extensive examples on linking
gpitel authored Feb 16, 2013
14 def onClick(sender):
ab0d6ea @gpitel add: server html example
gpitel authored Feb 17, 2013
15 Window.alert('Make service request using %s'%sender.getID())
d9b16a6 @gpitel add: more extensive examples on linking
gpitel authored Feb 16, 2013
16
64df13d add Anchor widget
Luke Kenneth Casson Leighton authored Jul 16, 2010
17 if __name__ == '__main__':
6d55a05 @bittner Anchor example: fixed reference to public/ for pyjd
bittner authored Mar 11, 2012
18 pyjd.setup("public/Anchor.html")
d9b16a6 @gpitel add: more extensive examples on linking
gpitel authored Feb 16, 2013
19 # EXAMPLE 1
20 a1 = Anchor(Widget = HTML('Test 1: Anchor to external site using HTML widget.'), Href='http://pyjs.org', Title = 'Test1')
21 RootPanel().add(a1)
22 # EXAMPLE 2
23 label = Label(text = 'Test 2: Click listener added to a label.')
24 label.addClickListener(onClick)
25 RootPanel().add(label)
26 # EXAMPLE 3
27 a2 = Hyperlink(text = 'Hyperlink', Element = DOM.createSpan())
ab0d6ea @gpitel add: server html example
gpitel authored Feb 17, 2013
28 a2.setID('param1')
d9b16a6 @gpitel add: more extensive examples on linking
gpitel authored Feb 16, 2013
29 a2.addClickListener(onClick)
30 html2=HTMLPanel("Test 3: <span id ='t3'></span> added to HTMLPanel with click listener.")
31 html2.add(a2, "t3")
32 RootPanel().add(html2)
33 # EXAMPLE 4
34 hpanel = HorizontalPanel()
35 hpanel.append(HTML('Test 4: Anchor to external site using Image widget'))
36 a3 = Anchor(Widget = Image('http://pyjs.org/assets/images/pyjs.128x128.png'), Href='http://pyjs.org', Title = 'Test4')
37 hpanel.append(a3)
38 RootPanel().add(hpanel)
ab0d6ea @gpitel add: server html example
gpitel authored Feb 17, 2013
39 # EXAMPLE 5
40 serverXml = \
41 """
42 <html>
43 <head>
44 <title>Example 5</title>
45 </head>
46 <body>
47 <p>Test 5: Processes server html and insert click listeners into links:
48 <span id='link1' class = 'wikilink'>link 1</span> and <span id='link2' class = 'wikilink'>link 2</span>.
49 </p>
50 </body>
51 </html>
52 """
53 html3 = HTMLPanel(serverXml)
54 links = list()
55 for elem in html3.findTags('span'):
56 if DOM.getElemAttribute(elem, 'class') == 'wikilink':
57 linkClass = DOM.getElemAttribute(elem, 'class')
58 links.append(elem)
59 if len(links) > 0:
60 parent = DOM.getParent(links[0])
61 for link in links:
62 linkId = DOM.getElemAttribute(link, 'id')
63 linkClass = DOM.getElemAttribute(link, 'class')
64 linkInner = DOM.getInnerHTML(link)
65 a3 = Hyperlink(text = linkInner, Element = DOM.createSpan())
66 a3.addClickListener(onClick)
67 a3.setID('param2')
68 #todo: modify HTMLPanel to replace an element instead of add
69 #html3.replace(a3, linkId)
70 DOM.setInnerHTML(link, '') # clear existing text
71 html3.add(a3, linkId)
72 RootPanel().add(html3)
d9b16a6 @gpitel add: more extensive examples on linking
gpitel authored Feb 16, 2013
73 pyjd.run()
Something went wrong with that request. Please try again.