def new_tbl(rows, cols, width, height, tableStyleId=None): """Return a new ``<p:tbl>`` element tree""" # working hypothesis is this is the default table style GUID if tableStyleId is None: tableStyleId = '{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}' xml = CT_Table._tbl_tmpl % (tableStyleId) tbl = parse_xml_bytes(xml) # add specified number of rows and columns rowheight = height/rows colwidth = width/cols for col in range(cols): # adjust width of last col to absorb any div error if col == cols-1: colwidth = width - ((cols-1) * colwidth) SubElement(tbl.tblGrid, 'a:gridCol', w=str(colwidth)) for row in range(rows): # adjust height of last row to absorb any div error if row == rows-1: rowheight = height - ((rows-1) * rowheight) tr = SubElement(tbl, 'a:tr', h=str(rowheight)) for col in range(cols): tr.append(CT_TableCell.new_tc()) objectify.deannotate(tbl, cleanup_namespaces=True) return tbl
def add_sldId(self, rId): """ Return a reference to a newly created <p:sldId> child element having its r:id attribute set to *rId*. """ sldId = SubElement(self, 'p:sldId', id=self._next_id) sldId.set(qn('r:id'), rId) return sldId
def new_placeholder_sp(id_, name, ph_type, orient, sz, idx): """ Return a new ``<p:sp>`` element tree configured as a placeholder shape. """ xml = CT_Shape._ph_sp_tmpl % (id_, name) sp = parse_xml_bytes(xml) # placeholder shapes get a "no group" lock SubElement(sp.nvSpPr.cNvSpPr, 'a:spLocks') sp.nvSpPr.cNvSpPr[qn('a:spLocks')].set('noGrp', '1') # placeholder (ph) element attributes values vary by type ph = SubElement(sp.nvSpPr.nvPr, 'p:ph') if ph_type != PH_TYPE_OBJ: ph.set('type', ph_type) if orient != PH_ORIENT_HORZ: ph.set('orient', orient) if sz != PH_SZ_FULL: ph.set('sz', sz) if idx != 0: ph.set('idx', str(idx)) placeholder_types_that_have_a_text_frame = ( PH_TYPE_TITLE, PH_TYPE_CTRTITLE, PH_TYPE_SUBTITLE, PH_TYPE_BODY, PH_TYPE_OBJ) if ph_type in placeholder_types_that_have_a_text_frame: sp.append(CT_TextBody.new_txBody()) objectify.deannotate(sp, cleanup_namespaces=True) return sp
def rewrite_guides(self, guides): """ Remove any ``<a:gd>`` element children of ``<a:avLst>`` and replace them with ones having (name, val) in *guides*. """ try: avLst = self.avLst except AttributeError: avLst = SubElement(self, 'a:avLst') if hasattr(self.avLst, 'gd'): for gd_elm in self.avLst.gd[:]: avLst.remove(gd_elm) for name, val in guides: gd = SubElement(avLst, 'a:gd') gd.set('name', name) gd.set('fmla', 'val %d' % val)
def it_can_set_element_attributes(self, parent_elm, nsptag_str): attr_dct = {'foo': 'f', 'bar': 'b'} elm = SubElement(parent_elm, nsptag_str, attrib=attr_dct, baz='1') assert elm.get('foo') == 'f' assert elm.get('bar') == 'b' assert elm.get('baz') == '1'
def it_returns_a_child_of_the_passed_parent_elm( self, parent_elm, nsptag_str): elm = SubElement(parent_elm, nsptag_str) assert elm.getparent() is parent_elm