def non_placeholder_shapes_(self, request): autoshape_sp_ = instance_mock( request, CT_Shape, name="autoshape_sp_", is_autoshape=True, is_textbox=False, has_custom_geometry=False, ) autoshape_shape_ = Shape(autoshape_sp_, None) textbox_sp_ = instance_mock( request, CT_Shape, name="textbox_sp_", is_autoshape=False, is_textbox=True, has_custom_geometry=False, ) textbox_shape_ = Shape(textbox_sp_, None) freeform_sp_ = instance_mock( request, CT_Shape, name="freeform_sp_", is_autoshape=True, is_textbox=False, has_custom_geometry=True, ) freeform_ = Shape(freeform_sp_, None) property_mock(request, Shape, "is_placeholder", return_value=False) return autoshape_shape_, textbox_shape_, freeform_
def it_can_change_its_text(self, text_frame_prop_, text_frame_): text_frame_prop_.return_value = text_frame_ shape = Shape(None, None) shape.text = "føøbår" assert text_frame_.text == "føøbår"
def iter_fixture(self, BaseShapeFactory_): spTree = element('p:spTree/(p:sp,p:sp)') sps = spTree.xpath('p:sp') shapes = _BaseShapes(spTree, None) expected_shapes = [Shape(None, None), Shape(None, None)] calls = [call(sps[0], shapes), call(sps[1], shapes)] BaseShapeFactory_.side_effect = iter(expected_shapes) return shapes, expected_shapes, BaseShapeFactory_, calls
def non_placeholder_shapes_(self, request): autoshape_sp_ = instance_mock( request, CT_Shape, name='autoshape_sp_', is_autoshape=True, is_textbox=False ) autoshape_shape_ = Shape(autoshape_sp_, None) textbox_sp_ = instance_mock( request, CT_Shape, name='textbox_sp_', is_autoshape=False, is_textbox=True ) textbox_shape_ = Shape(textbox_sp_, None) property_mock(request, Shape, 'is_placeholder', return_value=False) return autoshape_shape_, textbox_shape_
def it_calculates_its_effective_size_to_help_fit_text(self): sp_cxml = ( "p:sp/(p:spPr/a:xfrm/(a:off{x=914400,y=914400},a:ext{cx=914400,c" "y=914400}),p:txBody/(a:bodyPr,a:p))" ) text_frame = Shape(element(sp_cxml), None).text_frame assert text_frame._extents == (731520, 822960)
def it_knows_what_text_it_contains(self, text_frame_prop_, text_frame_): text_frame_prop_.return_value = text_frame_ text_frame_.text = "foobar" shape = Shape(None, None) text = shape.text assert text == "foobar"
def write_shape(self, shape: Shape) -> None: """Write attributes to table in given pptx.shapes.autoshape.Shape.""" if not shape.has_table: print( f"Warning: Could not write table style. {shape} has no table.") return if self.position is not None: shape.left, shape.top = self.position.tuple() self.write_table(shape.table)
def autoshape_type_fixture_(self, shape, prst): sp = ( an_sp().with_nsdecls().with_child( an_nvSpPr().with_child( a_cNvSpPr())).with_child( an_spPr().with_child( a_prstGeom().with_prst('chevron'))) ).element shape = Shape(sp, None) return shape, MSO_SHAPE.CHEVRON
def it_raises_when_shape_type_called_on_unrecognized_shape(self): xml = ( '<p:sp xmlns:p="http://schemas.openxmlformats.org/presentationml/' '2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/' '2006/main"><p:nvSpPr><p:cNvPr id="9" name="Unknown Shape Type 8"' '/><p:cNvSpPr/><p:nvPr/></p:nvSpPr><p:spPr/></p:sp>') sp = parse_xml(xml) shape = Shape(sp, None) # verify ----------------------- with pytest.raises(NotImplementedError): shape.shape_type
def copyShape(shape, idx): # pylint: disable=protected-access sp = shape._sp new_sp = None # ---duplicate original freeform--- new_sp = copy.deepcopy(sp) new_shape = Shape(new_sp, shape._parent) # ---create a unique id for it--- new_sp.nvSpPr.cNvPr.id = 1000 + idx # ---insert it after original--- sp.addnext(new_sp) return new_shape
def non_autoshape_shape_(self, request, sp_): sp_.is_autoshape = False return Shape(sp_, None)
def txBody_fixture(self, request): sp_cxml = 'p:sp' expected_cxml = 'p:txBody/(a:bodyPr,a:p)' shape = Shape(element(sp_cxml), None) expected_xml = xml(expected_cxml) return shape, expected_xml
def text_set_fixture(self, request): sp_cxml, new_value, expected_sp_cxml = request.param shape = Shape(element(sp_cxml), None) expected_xml = xml(expected_sp_cxml) return shape, new_value, expected_xml
def text_get_fixture(self, request): sp_cxml, expected_value = request.param shape = Shape(element(sp_cxml), None) return shape, expected_value
def text_frame_fixture(self, TextFrame_, text_frame_): sp = element('p:sp/p:txBody') txBody = sp[0] shape = Shape(sp, None) return shape, text_frame_, TextFrame_, txBody
def placeholder_shape_(self, request, sp_): placeholder_shape_ = Shape(sp_, None) property_mock(request, Shape, 'is_placeholder', return_value=True) return placeholder_shape_
def shape(self, request, sp_): return Shape(sp_, None)
def it_knows_it_has_a_text_frame(self): shape = Shape(None, None) assert shape.has_text_frame is True