コード例 #1
0
ファイル: txt2ppt.py プロジェクト: ratodigital/txt2ppt
    def new(self, text):
        slide = self.prs.slides.add_slide(self.blank_slide_layout)
        
        left = Inches (0.5)
        top = Inches (2)
        width = Inches (9)
        height = Inches (3)
    
        txBox = slide.shapes.add_textbox(left, top, width, height)
        #Set background color
        self.slide_bg_color(slide, self.background_color)
        
        tf = txBox.text_frame
        tf.word_wrap = True
        tf.vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE

        p = tf.add_paragraph()
        p.font.size = self.font_size
        p.font.color.rgb = RGBColor.from_string(self.font_color)
        p.alignment = PP_ALIGN.CENTER
        
        for part in self.get_text_parts(text):
            run = p.add_run()
            run.text = part['text']
            if part['type'] == 'bold':
                run.font.bold = True
            if part['type'] == 'italic':
                run.font.italic = True
コード例 #2
0
def then_the_line_color_type_value_matches(context, color_type):
    line = context.line
    if color_type == 'RGB':
        assert line.color.rgb == RGBColor(0x12, 0x34, 0x56)
    else:
        assert line.color.theme_color == MSO_THEME_COLOR.DARK_1
コード例 #3
0
ファイル: test_color.py プロジェクト: CSberger/python-pptx
 def it_can_construct_from_a_hex_string_rgb_value(self):
     rgb = RGBColor.from_string('123456')
     assert rgb == RGBColor(0x12, 0x34, 0x56)
コード例 #4
0
def add_tight_formation_and_defense_slide(play, slide, library):
    formation_name = play['Card Maker Formation']
    defense_name = play['Card Maker Defense']

    formation = None
    try:
        x_min = -25
        x_max = 25
        y_max = 8
        offset = 0
        if formation_name:
            formation = library.get_composite_formation_variation(
                formation_name, play['Hash'])
            if formation.hash == 'lt':
                x_min -= 18
                x_max -= 18
                offset = 18
            elif formation.hash == 'rt':
                x_min += 18
                x_max += 18
                offset = -18
            pp_formation = variation_to_powerpoint(formation)
            for label, player in pp_formation.players.items():
                if player.x < x_min or player.x > x_max:
                    continue
                x, y = player_coordinates_to_powerpoint(player.x + offset,
                                                        player.y,
                                                        is_tight_view=True)
                shape = slide.shapes.add_shape(MSO_AUTO_SHAPE_TYPE.OVAL,
                                               x - TIGHT_PLAYER_WIDTH / 2,
                                               y - TIGHT_PLAYER_HEIGHT / 2,
                                               TIGHT_PLAYER_WIDTH,
                                               TIGHT_PLAYER_HEIGHT)
                shape.fill.solid()
                shape.fill.fore_color.rgb = RGBColor(255, 255, 255)
                shape.line.color.rgb = RGBColor(0, 0, 0)
                shape.line.width = Pt(1.0)
                shape.text_frame.text = player.label if len(
                    player.label) != 2 else player.label[1]
                shape.text_frame.paragraphs[0].font.size = Pt(24)
                shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(
                    0, 0, 0)
                shape.text_frame.paragraphs[
                    0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER

        if formation and defense_name:
            composite_defense = library.get_composite_defense(defense_name)
            placed_defense = composite_defense.get_affected_placed_defenders(
                variation_to_defense_compatible_formation(formation))
            for (tag, label, defender_x, defender_y) in placed_defense:
                if defender_x < x_min or defender_x > x_max or defender_y > y_max:
                    continue
                x, y = player_coordinates_to_powerpoint(defender_x + offset,
                                                        defender_y * -1,
                                                        is_tight_view=True)
                text_box = slide.shapes.add_textbox(
                    x - TIGHT_DEFENDER_WIDTH / 2,
                    y - TIGHT_DEFENDER_HEIGHT / 2, TIGHT_DEFENDER_WIDTH,
                    TIGHT_DEFENDER_HEIGHT)
                text_box.text_frame.text = label
                text_box.text_frame.paragraphs[0].font.size = Pt(36)
    except LibraryException:
        pass  #the only error that can occur is a formation or defense doesn't exist
コード例 #5
0
def add_wide_formation_and_defense_slide(play, slide, library):
    #draw sideline
    slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT, LEFT_SIDELINE,
                               CENTER_Y_POS - FIVE_YARDS * 3, LEFT_SIDELINE,
                               CENTER_Y_POS + FIVE_YARDS * 2)
    slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT, RIGHT_SIDELINE,
                               CENTER_Y_POS - FIVE_YARDS * 3, RIGHT_SIDELINE,
                               CENTER_Y_POS + FIVE_YARDS * 2)

    for num in range(-3, 3):
        #draw lines that go accross field at 5 yard intervals
        slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT, LEFT_SIDELINE,
                                   CENTER_Y_POS + FIVE_YARDS * num,
                                   RIGHT_SIDELINE,
                                   CENTER_Y_POS + FIVE_YARDS * num)
        #draw hash marks
        slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT, LEFT_HASH,
                                   CENTER_Y_POS + num * FIVE_YARDS - HASH_SIZE,
                                   LEFT_HASH,
                                   CENTER_Y_POS + num * FIVE_YARDS + HASH_SIZE)
        slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT, RIGHT_HASH,
                                   CENTER_Y_POS + num * FIVE_YARDS - HASH_SIZE,
                                   RIGHT_HASH,
                                   CENTER_Y_POS + num * FIVE_YARDS + HASH_SIZE)
        #draw ticks for the top of numbers and bottom of numbers
        slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT,
                                   LEFT_BOTTOM_OF_NUMBERS,
                                   CENTER_Y_POS + num * FIVE_YARDS - HASH_SIZE,
                                   LEFT_BOTTOM_OF_NUMBERS,
                                   CENTER_Y_POS + num * FIVE_YARDS + HASH_SIZE)
        slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT,
                                   LEFT_TOP_OF_NUMBERS,
                                   CENTER_Y_POS + num * FIVE_YARDS - HASH_SIZE,
                                   LEFT_TOP_OF_NUMBERS,
                                   CENTER_Y_POS + num * FIVE_YARDS + HASH_SIZE)
        slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT,
                                   RIGHT_BOTTOM_OF_NUMBERS,
                                   CENTER_Y_POS + num * FIVE_YARDS - HASH_SIZE,
                                   RIGHT_BOTTOM_OF_NUMBERS,
                                   CENTER_Y_POS + num * FIVE_YARDS + HASH_SIZE)
        slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT,
                                   RIGHT_TUP_OF_NUMBERS,
                                   CENTER_Y_POS + num * FIVE_YARDS - HASH_SIZE,
                                   RIGHT_TUP_OF_NUMBERS,
                                   CENTER_Y_POS + num * FIVE_YARDS + HASH_SIZE)

    formation_name = play['Card Maker Formation']
    defense_name = play['Card Maker Defense']

    formation = None
    try:
        if formation_name:
            formation = library.get_composite_formation_variation(
                formation_name, play['Hash'])
            pp_formation = variation_to_powerpoint(formation)
            for label, player in pp_formation.players.items():
                x, y = player_coordinates_to_powerpoint(player.x, player.y)
                shape = slide.shapes.add_shape(MSO_AUTO_SHAPE_TYPE.OVAL,
                                               x - PLAYER_WIDTH / 2,
                                               y - PLAYER_HEIGHT / 2,
                                               PLAYER_WIDTH, PLAYER_HEIGHT)
                shape.fill.solid()
                shape.fill.fore_color.rgb = RGBColor(255, 255, 255)
                shape.line.color.rgb = RGBColor(0, 0, 0)
                shape.line.width = Pt(1.0)
                shape.text_frame.text = player.label if len(
                    player.label) != 2 else player.label[1]
                shape.text_frame.paragraphs[0].font.size = Pt(12)
                shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(
                    0, 0, 0)
                shape.text_frame.paragraphs[
                    0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER

        if formation and defense_name:
            composite_defense = library.get_composite_defense(defense_name)
            placed_defense = composite_defense.get_affected_placed_defenders(
                variation_to_defense_compatible_formation(formation))
            for (tag, label, defender_x, defender_y) in placed_defense:
                x, y = player_coordinates_to_powerpoint(
                    defender_x, defender_y * -1)
                text_box = slide.shapes.add_textbox(x - DEFENDER_WIDTH / 2,
                                                    y - DEFENDER_HEIGHT / 2,
                                                    DEFENDER_WIDTH,
                                                    DEFENDER_HEIGHT)
                text_box.text_frame.text = label
                text_box.text_frame.paragraphs[0].font.size = Pt(24)
    except LibraryException:
        pass  #the only error that can a formation or defendse  doesn't exist
コード例 #6
0
pylogo = 'pypptlogo.png'
pptlogo = 'pypptlogo.png'
prs = Presentation()

# front page
#-----------------------------------------------------------------------------------------------------------------------
slide = prs.slides.add_slide(prs.slide_layouts[6])
prs.slide_width = Inches(16)
prs.slide_height = Inches(9)

shape = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, 0, Inches(9 / 1.5),
                               Inches(16), Inches(9 / 8.5))
shape.shadow.inherit = False
fill = shape.fill
fill.solid()
fill.fore_color.rgb = RGBColor(255, 0, 0)
shape.text = title
line = shape.line
line.color.rgb = RGBColor(255, 0, 0)
logo1 = slide.shapes.add_picture(pylogo,
                                 Inches(13.8),
                                 Inches(6.0),
                                 height=Inches(1.0),
                                 width=Inches(1.0))
logo2 = slide.shapes.add_picture(pptlogo,
                                 Inches(14.5),
                                 Inches(5.8),
                                 height=Inches(1.5),
                                 width=Inches(1.5))
#-----------------------------------------------------------------------------------------------------------------------
コード例 #7
0
def marimekkopptx(ssmarkets, ccsss, lowshare, drawshare, marketshare, height,
                  width, showther, marketsize, name):
    prs = Presentation()
    title_only_slide_layout = prs.slide_layouts[5]
    slide = prs.slides.add_slide(title_only_slide_layout)
    shapes = slide.shapes

    shapes.title.text = f"Market Size = {float(marketsize):,.0f}"

    x0 = 1.0
    y0 = 17.0
    owidth = 3.0

    x = 0
    y = 0
    marketcount = 0

    for market in ssmarkets.index:
        h = float(ssmarkets.loc[market])
        #print(f"height'{market}':{h:.0f}")
        competitors = ccsss.loc[market].sort_values(by=['Share'],
                                                    ascending=False)
        x = 0
        other = 0.0
        count = 0
        first = True
        ccompetitor = 0
        for competitor in competitors.index:
            if ccompetitor == 0:
                # print market label
                sx = (x * width + x0)
                sy = (y0 - (y * height))
                sw = owidth
                sh = (h * height)
                run, font, fill = rectanglepptx(shapes, 0, sx, sy, sw, sh,
                                                f"{market} ({h*100:.0f}%)")
                fill.fore_color.rgb = RGBColor(192, 192, 192)
                font.color.rgb = RGBColor(255, 255, 255)
            if competitor != 'Other':
                w = float(ccsss.loc[market].loc[competitor])
                if (w >= lowshare):
                    #print(f"  width {competitor}:{w:.0f}")
                    #print(f"({w},{h})")
                    # create the rectangle
                    sx = (x * width + x0)
                    sy = (y0 - (y * height))
                    sw = (w * width)
                    sh = (h * height)
                    run, font, fill = rectanglepptx(shapes, owidth, sx, sy, sw,
                                                    sh, "")
                    label = competitor.lower()
                    if name.lower() in label:
                        fill.fore_color.rgb = RGBColor(0, 204, 102)
                    if w <= drawshare:
                        run.text = f"{competitor.replace('Machine: ','')[:5]} ({w*100:.0f}%)"
                        #run.text = f"{competitor} ({w*100:.0f}%)"
                        if h >= marketshare:
                            font.size = Pt(6)
                        else:
                            font.size = Pt(4)
                    else:
                        run.text = f"{competitor} ({w*100:.0f}%)"
                        if h >= marketshare:
                            font.size = Pt(8)
                        else:
                            font.size = Pt(6)
                    x += w
                else:
                    other += w
            else:
                other += float(ccsss.loc[market].loc['Other'])
            ccompetitor += 1

        #print(x,y)
        w = other
        if w > 0:
            sx = (x * width + x0)
            sy = (y0 - (y * height))
            sw = (w * width)
            sh = (h * height)
            run, font, fill = rectanglepptx(shapes, owidth, sx, sy, sw, sh, "")
            if w <= drawshare:
                run.text = f"({w*100:.0f}%)"
                if h >= marketshare:
                    font.size = Pt(6)
                else:
                    font.size = Pt(4)
            else:
                run.text = f"({w*100:.0f}%)"
                if h >= marketshare:
                    font.size = Pt(8)
                else:
                    font.size = Pt(6)
        y += h
        marketcount += 1

    return prs
コード例 #8
0
count2 = 0

for line in textfile1:
    slide = prs.slides.add_slide(blank_slide_layout)
    #print("go")
    txBox = slide.shapes.add_textbox(Inches(0), Inches(1.34), width,
                                     Inches(0.64))
    tf = txBox.text_frame
    p = tf.paragraphs[0]
    p.alignment = PP_ALIGN.CENTER
    run = p.add_run()
    run.text = line
    font = run.font
    font.name = '210 Hayanbunpil Light Bold'
    font.size = Pt(26)
    font.color.rgb = RGBColor(255, 255, 255)

    txBox2 = slide.shapes.add_textbox(Inches(0), Inches(1.98), width,
                                      Inches(0.64))
    tf2 = txBox2.text_frame
    p2 = tf2.paragraphs[0]
    p2.alignment = PP_ALIGN.CENTER
    run2 = p2.add_run()
    run2.text = textfile2[count]
    count += 1
    font2 = run2.font
    font2.name = 'Arial'
    font2.size = Pt(18)
    font2.bold = True
    font2.italic = True
    font2.color.rgb = RGBColor(255, 255, 255)
コード例 #9
0
def then_fore_color_is_RGB_value_I_set(context):
    assert context.shape.fill.fore_color.rgb == RGBColor(0x12, 0x34, 0x56)
コード例 #10
0
def when_set_fore_color_to_RGB_value(context):
    context.shape.fill.fore_color.rgb = RGBColor(0x12, 0x34, 0x56)