def test_XHTML(self): """Construct an XHTML page. Verify visually.""" htd = XHTML.new_document(dtds.XHTML) htd.title = "This is the title." htd.add_header(1, 'Main document & "stuff"') htd.new_para("This is a test. This is text.") htd.add_unordered_list(["List line one.", "list line two."]) BR = htd.get_new_element("Br") A = htd.get_new_element("A", href="somelink.html") A.add_text("some link") p = htd.get_para() p.append(A) p.add_text(" This is ") b = p.bold("bold") p.add_text(" text. using ") stb = htd.get_new_element("B") stb.add_text("bold tags") p.text(stb) p.add_text(" Dynamic Date: ") p.append(XHTML.DynamicNode(thedate)) rp = str(p) htd.append(POM.ASIS(rp)) # table methods t = htd.add_table(border=1) t.summary = "This is a test table." t.caption("table caption") h = t.set_heading(2, "heading col 2") h.set_attribute("class", "headerclass") t.set_heading(1, "heading col 1") t.set_cell(1, 1, "row 1, col 1") t.set_cell(1, 2, "row 2, col 1") t.set_cell(2, 1, "row 1, col 2") t.set_cell(2, 2, "row 2, col 2") # sections div = htd.get_section("section1") div.add_header(1, "Div heading.") div.new_para("First div para.") htd.append(div) div2 = div.get_section("section2") div2.new_para("Second div para") div.append(div2) dl = div.add_definition_list() dl.add_definitions({ "def1": "The definition of 1", "def2": "The definition of 2" }) # using the nodemaker object NM = htd.nodemaker ul = NM( "Ul", None, NM("Li", None, "line 1"), NM("Li", None, "line 2"), NM("Li", None, "Date: ", NM("code", None, thedate)), # another way to add dynamic node ) htd.append(ul) htd.append(NM("JS", None, 'var a = new Array(8);')) # using the creator object. creator = htd.creator parts = creator([("Just", "just/"), "How will this turn out?", ["It is hard to tell.", "Well, not too hard."]]) htd.add_comment( "the name attribute is required for all but submit & reset") htd.append(parts) f = htd.add_form(action="http://localhost:4001/cgi-bin/testing.py", method="post") f.add_textarea("mytextarea", """Default text in the textarea.""") f.append(BR) f.add_input(type="text", name="mytext", value="mytext text") f.append(BR) f.add_input(type="button", name="button1", src="button.png", value="Button") f.append(BR) f.add_input(type="submit", name="submit1", src="submit.png", value="Ok") f.append(BR) f.add_radiobuttons("radlist", ["one", "two", "three", "four"], vertical=False) f.append(BR) f.add_checkboxes("checks", ["one", "two", "three", "four"], vertical=True) f.append(BR) f.add_fileinput(name="myfile", default="/etc/hosts") f.append(BR) f.add_textinput(name="mytext", label="Enter text") f.append(BR) f.yes_no("What's it gonna be?") f.add_select([ "one", "two", ("three", True), "four", { "agroup": ["group1", "group2"] } ], name="myselect") f.append(BR) f.add_select( { "Group1": Enums("g1one", "g1two", "g1three") + [("g1four", True)], "Group2": Enums("g2one", "g2two", "g2three"), "Group3": Enums("g3one", "g3two", "g3three"), }, name="useenums") f.append(BR) f.add_select(["mone", "mtwo", ("mthree", True), ("mfour", True)], name="multiselect", multiple=True) f.append(BR) set = f.add_fieldset("afieldset") set.add_textinput(name="settext", label="Enter set text") set.add_textinput(name="settext2", label="Enter set text 2", default="Default text.") set.append(BR) tbl = htd.new_table([1, 2, 3, 4, 5], [NULL, NULL, NULL], ["col1", "col2", "col3"], width="100%", summary="autogenerated") gentable = table.GenericTable(["heading1", "heading2", "heading3"], title="Sample generic table") gentable.append([1, 2, 3]) gentable.append([4, 5, 6]) tbl2 = htd.new_table_from_GenericTable(gentable) # object subdoc = XHTML.new_document(dtds.XHTML) parts = subdoc.creator( ("Add a document object.", ["Some data.", "some more data.."])) subdoc.append(parts) sdfo = open("/tmp/subdoc.html", "w") subdoc.emit(sdfo) sdfo.close() htd.add_object(data="subdoc.html", type=subdoc.MIMETYPE, width="400px", height="600px") htd.emit(sys.stdout) print "-----" fo = open(XHTMLFILENAME, "w") bw = POM.BeautifulWriter(fo, XHTML.INLINE) htd.emit(bw) fo.close() print "----- Form values:" print f.fetch_form_values() print "----- Form elements:" felems = f.fetch_form_elements() for name, elemlist in felems.items(): print repr(name), ": ", repr(elemlist) print # visually verify the page. webbrowser.open("file://%s" % (XHTMLFILENAME, ))
def show(self, argv): """show Show current document object.""" bw = POM.BeautifulWriter(self._ui) self._obj.emit(bw)
self.set_dtd(DTD) def initialize(self): dtd = self.dtd root = XHTML.get_container(dtd, "Html", {"class_": FEATURE_CLASS}) self.set_root(root) head = XHTML.get_container(dtd, "Head", {}) body = XHTML.get_container(dtd, "Body", {}) head.append(dtd.Meta(charset="utf-8")) head.append( dtd.Meta(http_equiv="X-UA-Compatible", content="IE=edge,chrome=1")) root.append(head) root.append(body) root.head = head root.body = body def new_document(encoding=DEFAULT_ENCODING, language=DEFAULT_LANG): doc = HTML5Document(doctype=DOCTYPE, encoding=encoding, lang=language) doc.initialize() doc.root.lang = language return doc if __name__ == "__main__": import sys from pycopia import autodebug doc = new_document() writer = POM.BeautifulWriter(sys.stdout, XHTML.INLINE) doc.emit(writer)
def emit(self, fo): pp = POM.BeautifulWriter(fo) super(XFCE4Menu, self).emit(pp)