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
Пример #2
0
    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
Пример #3
0
 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
Пример #4
0
    def line(self):
        """|LineFormat| instance for this connector.

        Provides access to line properties such as line color, width, and
        line style.
        """
        return LineFormat(self)
Пример #5
0
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)
Пример #6
0
 def line(self):
     """
     |LineFormat| instance for this connector, providing access to line
     properties such as line color.
     """
     return LineFormat(self)
Пример #7
0
 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
Пример #8
0
 def line(self, shape_):
     return LineFormat(shape_)
Пример #9
0
 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
Пример #10
0
 def dash_style_get_fixture(self, request):
     spPr_cxml, expected_value = request.param
     spPr = element(spPr_cxml)
     line = LineFormat(spPr)
     return line, expected_value
Пример #11
0
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')
Пример #12
0
 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)