def add_line(self, x1, y1, x2, y2, color, width, dasharray): connector = self.shapes.add_connector(MSO_CONNECTOR.STRAIGHT, Pt(x1), Pt(y1), Pt(x2), Pt(y2)) connector.ln = connector.get_or_add_ln() line = LineFormat(connector) line.width = Pt(width) line.fill.solid() line.fill.fore_color.rgb = RGBColor(*color) if dasharray == 1: line.dash_style = MSO_LINE.SQUARE_DOT elif dasharray == 2: line.dash_style = MSO_LINE.DASH
def add_line(self, x1, y1, x2, y2, color, width, dasharray): connector = self.shapes.add_connector(MSO_CONNECTOR.STRAIGHT, Pt(x1), Pt(y1), Pt(x2), Pt(y2)) connector.ln = connector.get_or_add_ln() line = LineFormat(connector) line.width = width line.fill.solid() if color == "black": line.fill.fore_color.rgb = RGBColor(0, 0, 0) elif color == "blue": line.fill.fore_color.rgb = RGBColor(0, 0, 255) if dasharray != "none": line.dash_style = MSO_LINE.DASH
def width_set_fixture(self, request, shape_): initial_width, width = request.param shape_.ln = shape_.get_or_add_ln.return_value = ( self.ln_bldr(initial_width).element) line = LineFormat(shape_) expected_xml = self.ln_bldr(width).xml() return line, width, expected_xml
def line(self): """|LineFormat| instance for this connector. Provides access to line properties such as line color, width, and line style. """ return LineFormat(self)
def get_line(color, connector, bright=None): try: colors_dict = { "Red": RGBColor(255, 0, 0), "Green": RGBColor(0, 255, 0), "Blue": RGBColor(0, 0, 255) } line = LineFormat(connector) line.fill.solid() line.fill.fore_color.rgb = colors_dict["{}".format(color)] if bright: line.color.brightness = 0.7 else: line.color.brightness = 0.5 line.width = Pt(7) return line.fill.fore_color.rgb except Exception as e: print(e)
def line(self): """ |LineFormat| instance for this connector, providing access to line properties such as line color. """ return LineFormat(self)
def width_get_fixture(self, request, shape_): w = expected_line_width = request.param shape_.ln = self.ln_bldr(w).element line = LineFormat(shape_) return line, expected_line_width
def line(self, shape_): return LineFormat(shape_)
def dash_style_set_fixture(self, request): spPr_cxml, dash_style, expected_cxml = request.param spPr = element(spPr_cxml) line = LineFormat(spPr) expected_xml = xml(expected_cxml) return line, dash_style, spPr, expected_xml
def dash_style_get_fixture(self, request): spPr_cxml, expected_value = request.param spPr = element(spPr_cxml) line = LineFormat(spPr) return line, expected_value
from pptx.util import Pt from pptx.dml.color import RGBColor from pptx.dml.line import LineFormat from pptx.shapes.connector import Connector LAYOUT_INDEX = 1 left = Pt(20) top = Pt(20) height = Pt(100) presentation = Presentation() slide_layout = presentation.slide_layouts[LAYOUT_INDEX] slide = presentation.slides.add_slide(slide_layout) # Patch the Connector class. def get_or_add_ln(self): return self._element.spPr.get_or_add_ln() Connector.get_or_add_ln = get_or_add_ln # Draw a black line. connector = slide.shapes.add_connector(MSO_CONNECTOR.STRAIGHT, left, top, left, top + height) # connector.ln = connector.get_or_add_ln() line = LineFormat(connector) line.fill.solid() line.fill.fore_color.rgb = RGBColor(255, 0, 0) presentation.save('./output.pptx')
def line(self): """ An instance of |LineFormat|, providing access to the properties of the outline bordering this shape, such as its color and width. """ return LineFormat(self)