Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add Anchor widget

  • Loading branch information...
commit 64df13d8385d16e5518c27e87030897e834979fe 1 parent f83d3d1
Luke Kenneth Casson Leighton authored
View
13 examples/anchor/Anchor.html
@@ -0,0 +1,13 @@
+<html>
+ <!-- auto-generated html - you should consider editing and
+ adapting this to suit your requirements
+ -->
+ <head>
+ <meta name="pygwt:module" content="Anchor">
+ <link rel='stylesheet' href='Anchor.css'>
+ <title>my titlePyJamas Auto-Generated HTML file Anchor</title>
+ </head>
+ <body bgcolor="white">
+ <script language="javascript" src="bootstrap.js"></script>
+ </body>
+</html>
View
17 examples/anchor/Anchor.py
@@ -0,0 +1,17 @@
+import pyjd
+from pyjamas.ui.RootPanel import RootPanel
+from pyjamas.ui.Image import Image
+from pyjamas.ui.Anchor import Anchor
+
+if __name__ == '__main__':
+ pyjd.setup("Anchor.html")
+
+ root = RootPanel()
+ image_url = "http://www.dcuktec.com/static/images/logo.png"
+ image = Image(image_url)
+ anchor = Anchor(Widget=image)
+ anchor.href.set('http://www.dcuktec.com')
+ root.add(anchor)
+
+ pyjd.run()
+
View
89 library/pyjamas/ui/Anchor.py
@@ -0,0 +1,89 @@
+""" Anchor Widget, use this to create the equivalent of the <a></a> tag.
+
+Copyright(C) 2010, Martin Hellwig
+Copyright(C) 2010, Luke Leighton <lkcl@lkcl.net>
+
+License: Apache Software Foundation v2
+
+Here is an example for using it with an image:
+---------------------------------------------------------
+if __name__ == '__main__':
+ from pyjamas.ui.RootPanel import RootPanel
+ from pyjamas.ui.Image import Image
+ root = RootPanel()
+ image_url = "http://www.dcuktec.com/static/images/logo.png"
+ image = Image(image_url)
+ anchor = Anchor()
+ anchor.add(image)
+ anchor.href.set('http://www.dcuktec.com')
+ root.add(anchor)
+---------------------------------------------------------
+"""
+
+from pyjamas import DOM
+from pyjamas.ui.Widget import Widget
+
+class _Attribute(object):
+ "Attribute definition class with method set and remove"
+ def __init__(self, element, attribute,
+ attribute_type=None, type_restriction=None):
+ self.element = element
+ self.attribute = attribute
+ self._type = attribute_type
+ self._restriction = type_restriction
+
+ def get(self):
+ "Get the value"
+ return DOM.getAttribute(self.element, self.attribute)
+
+ def set(self, value):
+ "Set the value"
+ DOM.setAttribute(self.element, self.attribute, value)
+
+ def remove(self):
+ "Remove the attribute from the element"
+ DOM.removeAttribute(self.element, self.attribute)
+
+class _Attributes(object):
+ "Attribute container class"
+ def __init__(self, element):
+ self.name = _Attribute(element, 'name', 'cdata', 'cs')
+ self.href = _Attribute(element, 'href', 'uri', 'ct')
+ self.hreflang = _Attribute(element, 'hreflang', 'langcode', 'ci')
+ self.type = _Attribute(element, 'type', 'content-type', 'ci')
+ self.rel = _Attribute(element, 'rel', 'link-types' ,'ci')
+ self.rev = _Attribute(element, 'rev', 'link-types', 'ci')
+ self.charset = _Attribute(element, 'charset', 'charset', 'ci')
+
+class Anchor(Widget, _Attributes):
+ """Anchor attribute, use this to create the equivalent of the <a></a> tag.
+ The attributes: name, href. hreflang, type, rel, rev, charset are in the
+ namespace of the Anchor instance.
+ These attributes themselves have the functions 'set' and 'remove'
+ For example:
+ anchor = Anchor()
+ anchor.href.set('http://www.dcuktec.com')
+ """
+ def __init__(self, **kwargs):
+ element = kwargs.pop('Element', None) or DOM.createAnchor()
+ kwargs['StyleName'] = kwargs.pop('StyleName', 'gwt-Anchor')
+ _Attributes.__init__(self, element)
+ self.setElement(element)
+ self.widget = None
+ Widget.__init__(self, **kwargs)
+
+ def setWidget(self, widget):
+ """ Add child widget
+ """
+ widget.removeFromParent()
+ widget.setParent(self)
+ self.widget = widget
+ DOM.appendChild(self.getElement(), widget.getElement())
+
+ def removeWidget(self):
+ """ remove child widget
+ """
+ widget.removeFromParent()
+ DOM.removeChild(self.getElement(), self.widget.getElement())
+ self.widget = None
+
Please sign in to comment.
Something went wrong with that request. Please try again.