Ejemplo n.º 1
0
def rectanglepptx(shapes, offset, sx, sy, sw, sh, text):
    #print(f"x:{sx:.2f}|y:{sy-sh:.2f}|w:{sw:.2f}|h:{sh:.2f}")
    isx = Inches((sx + offset) / 2.54)
    isy = Inches((sy - sh) / 2.54)
    isw = Inches(sw / 2.54)
    ish = Inches(sh / 2.54)
    # isx,isy is the top left corner of the rectangle
    shape = shapes.add_shape(MSO_SHAPE.RECTANGLE, isx, isy, isw, ish)
    shape.shadow.inherit = False
    shape.fore_color = RGBColor(96, 96, 96)
    fill = shape.fill
    fill.solid()
    fill.fore_color.rgb = RGBColor(255, 255, 255)
    line = shape.line
    line.color.rgb = RGBColor(96, 96, 96)
    text_frame = shape.text_frame
    text_frame.margin_left = Inches(0.0)
    text_frame.margin_right = Inches(0.0)
    text_frame.margin_top = Inches(0.0)
    text_frame.margin_bottom = Inches(0.0)
    text_frame.word_wrap = True
    text_frame.auto_size = MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE
    p = text_frame.paragraphs[0]
    run = p.add_run()
    run.text = text
    font = run.font
    font.name = 'Calibri'
    font.size = Pt(8)
    font.bold = True
    font.italic = None  # cause value to be inherited from theme
    font.color.theme_color = MSO_THEME_COLOR.ACCENT_1
    font.color.rgb = RGBColor(96, 96, 96)
    return (run, font, fill)
def format_chart_3_properties(chart, y_axis, label_flag=None):
    chart.has_legend = False
    value_axis = chart.value_axis
    value_axis.major_tick_mark = XL_TICK_MARK.NONE
    value_axis.has_minor_gridlines = False
    value_axis.has_major_gridlines = False
    value_axis.tick_label_position = XL_TICK_LABEL_POSITION.HIGH
    tick_labels = chart.value_axis.tick_labels
    tick_labels.font.size = Pt(10)
    tick_labels.font.color.rgb = RGBColor(123, 123, 123)
    chart.value_axis.format.line.fill.background()
    category_axis = chart.category_axis
    category_axis.tick_label_position = XL_TICK_LABEL_POSITION.NONE
    chart.category_axis.format.line.fill.background()
    series_color = [(155, 187, 89), (247, 150, 70),
                    (193, 81, 78)]  # Green,Orange,Red
    for i in range(len(y_axis)):
        data_label = chart.series[i].data_labels
        if label_flag:
            show_label = label_flag[i]
        else:
            show_label = True
        data_label.show_value = show_label
        data_label.font.size = Pt(11)
        data_label.font.bold = True
        data_label.font.color.rgb = RGBColor(series_color[i][0],
                                             series_color[i][1],
                                             series_color[i][2])
        if i == 0:
            data_label.position = XL_LABEL_POSITION.BELOW
        elif i == 1:
            data_label.position = XL_LABEL_POSITION.ABOVE
        chart.series[i].format.line.color.rgb = RGBColor(
            series_color[i][0], series_color[i][1], series_color[i][2])
def make_presentation(slides_dir_path, presentation_title):

	full_slide_paths = [slides_dir_path + slide_path for slide_path in sorted(listdir(slides_dir_path))]
	height, width, channels = imread(full_slide_paths[0]).shape
	height_inch = 0.010416666666819 * height
	width_inch = 0.010416666666819 * width

	presentation = Presentation()
	presentation.slide_height = Inches(height_inch)
	presentation.slide_width = Inches(width_inch)

	first_slide = presentation.slides.add_slide(presentation.slide_layouts[6])
	first_slide.background.fill.solid()
	first_slide.background.fill.fore_color.rgb = RGBColor(224, 22, 120)
	preface = first_slide.shapes.add_textbox(left=Inches((width_inch - 3)/2), top=Inches((height_inch - 1.2)/2), height=Inches(1.2), width=Inches(3))
	title = preface.text_frame.add_paragraph()
	title.text = "Automation 101"
	title.alignment = PP_ALIGN.CENTER
	title.font.bold = True
	title.font.size = Pt(30)
	title.font.color.rgb = RGBColor(255, 255, 255)
	creds = preface.text_frame.add_paragraph()
	creds.text = "by bex on the beach"
	creds.alignment = PP_ALIGN.CENTER
	creds.font.color.rgb = RGBColor(209, 203, 207)

	for slide_path in full_slide_paths:

		curr_slide = presentation.slides.add_slide(presentation.slide_layouts[6])
		curr_slide.shapes.add_picture(slide_path, left=Inches(0), top=Inches(0), height=Inches(height_inch), width=Inches(width_inch))

	presentation.save('{0}{1}.pptx'.format(slides_dir_path, presentation_title))
Ejemplo n.º 4
0
 def lookup(self, colour_format):
     #===============================
     if colour_format.type == MSO_COLOR_TYPE.RGB:
         rgb = colour_format.rgb
     elif colour_format.type == MSO_COLOR_TYPE.SCHEME:
         key = MSO_THEME_COLOR.to_xml(colour_format.theme_color)
         rgb = self.__colour_defs[DML(key)]
     else:
         raise ValueError('Unsupported colour format: {}'.format(
             colour_format.type))
     lumMod = colour_format.lumMod
     lumOff = colour_format.lumOff
     satMod = colour_format.satMod
     if lumMod != 1.0 or lumOff != 0.0 or satMod != 1.0:
         hls = list(colorsys.rgb_to_hls(*(np.array(rgb) / 255.0)))
         hls[1] *= lumMod
         hls[1] += lumOff
         if hls[1] > 1.0:
             hls[1] = 1.0
         hls[2] *= satMod
         if hls[2] > 1.0:
             hls[2] = 1.0
         colour = np.uint8(255 * np.array(colorsys.hls_to_rgb(*hls)) + 0.5)
         rgb = RGBColor(*colour.tolist())
     tint = colour_format.tint
     if tint > 0.0:
         colour = np.array(rgb)
         tinted = np.uint8((colour + tint * (255 - colour)))
         rgb = RGBColor(*colour.tolist())
     shade = colour_format.shade
     if shade != 1.0:
         shaded = np.uint8(shade * np.array(rgb))
         rgb = RGBColor(*shaded.tolist())
     return '#{}'.format(str(rgb))
Ejemplo n.º 5
0
 def __init__(self, left, top, width, height):
     """
     :param left:
     :param top:
     :param width:
     :param height:
     """
     self.width = width
     self.height = height
     self.top = top
     self.left = left
     self.rgbTextColor = RGBColor(0, 0, 0)
     self.rgbFillColor = RGBColor(255, 255, 255)
     self.rgbFirstNameColor = self.rgbTextColor
     self.brightness = 0
     self.firstName = None
     self.nickName = None
     self.lastName = None
     self.title = None
     self.heading = None
     self.firstNameSize = 8
     self.headingSize = 9
     self.lastNameSize = 6
     self.titleSize = 5
     self.minFontSize = 5
def set_table_contents(dataframe, table):
    """
    This sets the color and other attributes
    """
    i_c = 0
    for col, row in dataframe.iteritems():
        i_r = 0
        cell = table.cell(i_r, i_c)
        cell.text = col
        i_r = i_r + 1
        for data in row:
            cell = table.cell(i_r, i_c)
            cell.text = str(data)
            if cell.text == "nan":
                cell.text = ""
            if cell.text in STATUS:
                cell.fill.solid()
                (r_1, c_1, b_1) = STATUS[cell.text]
                cell.fill.fore_color.rgb = RGBColor(r_1, c_1, b_1)
            if cell.text in MILESTONE:
                cell.fill.solid()
                (r_1, c_1, b_1) = MILESTONE[cell.text]
                cell.fill.fore_color.rgb = RGBColor(r_1, c_1, b_1)
            i_r = i_r + 1
        i_c = i_c + 1
    def addRectFormatting(self, aPerson, aPersonRect):
        aPersonRect.setBrightness(0)
        aPersonRect.setRGBFillColor(self.memberColor)
        aPersonRect.setRGBTextColor(RGBColor(255, 255, 255))
        aPersonRect.setRGBFirstNameColor(RGBColor(255, 255, 255))

        if aPerson.isLead():
            aPersonRect.setRGBFirstNameColor(RGBColor(127, 127, 127))

        if aPerson.isManager():
            aPersonRect.setRGBFirstNameColor(RGBColor(255, 238, 0))

        if aPerson.isTBH():
            if aPerson.isUnfunded():
                self.totalUnfundedTBH += 1
            else:
                self.totalTBH += 1

        if self.isFutureTBH(aPerson):
            aPersonRect.setBrightness(.4)

        if aPerson.isExpat():
            self.totalExpat += 1

        return aPersonRect
Ejemplo n.º 8
0
def add_slide(presentation, blank):
    newSlide = presentation.slides.add_slide(presentation.slide_layouts[6])

    left = top = Inches(0)
    width = Inches(10)
    height = Inches(7.5)

    backgroundShape = newSlide.shapes.add_shape(MSO_SHAPE.RECTANGLE, left, top,
                                                width, height)

    if blank: COLOR = RGBColor(0, 0, 0)
    else: COLOR = RGBColor(255, 252, 197)

    line = backgroundShape.line
    line.color.rgb = COLOR

    fill = backgroundShape.fill
    fill.solid()
    fill.fore_color.rgb = COLOR

    if not blank:
        textBox = newSlide.shapes.add_textbox(left, top, width, height)
        text_frame = textBox.text_frame
        text_frame.word_wrap = True
        text_frame.auto_size = MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT
        text_frame.vertical_anchor = MSO_ANCHOR.MIDDLE

        return text_frame
Ejemplo n.º 9
0
def add_gradient_legend(slide):
    width, height, top = Inches(1.35), Inches(0.33), Inches(0.47)
    legend_text = ['Low Index', 'High Index']
    left_loc = [10.13, 11.47]

    for text, loc in zip(legend_text, left_loc):
        left = Inches(loc)
        shape = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, left, top, width,
                                       height)
        text_frame = shape.text_frame
        p = text_frame.paragraphs[0]
        p.text = text
        p.font.name = 'Arial'
        p.font.size = Pt(11)
        text_frame.vertical_anchor = MSO_ANCHOR.MIDDLE

        shape.line.fill.background()
        shape.shadow.inherit = False
        fill = shape.fill
        fill.gradient()
        fill.gradient_angle = 0
        gradient_stops = fill.gradient_stops
        if 'Low' in text:
            gradient_stops[0].color.rgb = RGBColor(236, 124, 37)
            gradient_stops[0].position = 0.25
            gradient_stops[1].color.theme_color = MSO_THEME_COLOR.BACKGROUND_1
            p.alignment = PP_ALIGN.LEFT
        else:
            gradient_stops[0].color.theme_color = MSO_THEME_COLOR.BACKGROUND_1
            gradient_stops[1].color.rgb = RGBColor(163, 119, 182)
            gradient_stops[1].position = 0.25
            p.alignment = PP_ALIGN.RIGHT
Ejemplo n.º 10
0
def model_5(prs, title, *content):
    slide = prs.slides.add_slide(prs.slide_layouts[6])
    slide.shapes.add_picture(ppt_bg_path, cm_to_in(0), cm_to_in(0),
                             cm_to_in(25.4), cm_to_in(14.288))
    title_box_1 = slide.shapes.add_textbox(cm_to_in(1.27), cm_to_in(0.20),
                                           cm_to_in(2.24), cm_to_in(1.00))
    paragraph_1 = title_box_1.text_frame.add_paragraph()
    paragraph_1.text = title
    paragraph_1.vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE
    paragraph_1.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
    paragraph_1.font.size = Pt(44)
    paragraph_1.font.name = '微软雅黑'
    paragraph_1.font.color.rgb = RGBColor(255, 255, 255)
    # 动态构建小标题
    module_width = (prs.slide_width - cm_to_in(1.27) * 2) / len(content)
    for i in range(0, 3):
        title_box = slide.shapes.add_textbox(
            cm_to_in(1.27),
            cm_to_in(4.4) + i * cm_to_in(2.39), module_width, cm_to_in(2.39))
        paragraph = title_box.text_frame.add_paragraph()
        paragraph.text = content[i]
        paragraph.vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE
        paragraph.alignment = PP_PARAGRAPH_ALIGNMENT.CENTER
        paragraph.font.size = Pt(32)
        paragraph.font.name = '微软雅黑'
        paragraph.font.color.rgb = RGBColor(255, 255, 255)
Ejemplo n.º 11
0
def add_shape(slide: Slide,
              left: float,
              top: float,
              width: float,
              height: float,
              rgb: Tuple[int, int, int],
              shape_type=MSO_SHAPE.RECTANGLE) -> Slide:
    """
    add a filled shape to a specified location on the slide
    Args:
        slide: pptx slide object
        left: horizontal position cm
        top: vertical position cm
        width: cm
        height: cm
        rgb: color of shape in rgb
        shape_type: pptx shape type object

    Returns:
        the slide
    """
    left, top, width, height = _get_cm(left, top, width, height)
    shape = slide.shapes
    box = shape.add_shape(shape_type, left, top, width, height)
    fill = box.fill
    line = box.line
    line.color.rgb = RGBColor(*rgb)
    fill.solid()
    fill.fore_color.rgb = RGBColor(*rgb)
    return slide
Ejemplo n.º 12
0
def create_slides(lines):
    slidecount = 0
    next_space = ""
    for count in lines:
        if " " != count[0]:
            slide = prs.slides.add_slide(bullet_slide)
            slidecount = slidecount + 1
            shapes = slide.shapes
            title_shape = shapes.title
            body_shape = shapes.placeholders[1]
            title_shape.text = titletext
            tf = body_shape.text_frame
            p = tf.paragraphs[0]
            space = ""
            for row in lines:
                line_color = RGBColor(0x00, 0x00, 0x00)
                next_space = ""
                if not ("।" in row[0] or "॥" in row[0]):
                    next_space = "    "
                if " " == row[0]:
                    next_space = ""
                if row[0].strip().endswith("वाच") or row[0].strip().endswith(
                        "ऊचुः"
                ) or "इति श्रीमद्भागवते महापुराणे पारमहंस्यां संहितायां" in row[
                        0]:
                    line_color = RGBColor(0xFF, 0x7F, 0x50)
                    next_space = ""
                if row == count:
                    line_color = RGBColor(0x00, 0x00, 0xFF)
                run = p.add_run()
                run.text = space + row[0] + "\n"
                font = run.font
                font.color.rgb = line_color
                space = next_space
    return slidecount
Ejemplo n.º 13
0
	def add_delivery_page(self, page_title, column_titles, column_widths):
		# add the page
		self.delivery_page = self.slides.add_slide(self.layouts[DELIVERY_PAGE_LAYOUT])
		self.delivery_page.name = "Delivery"

		# set page title
		shapes = self.delivery_page.shapes
		shapes.title.text= page_title 
		
		# create table
		num_row = 10 
		num_col = len(column_titles)
	
		left = Inches(1)
		top = Inches(1.3)
		width = Inches(7.0)
		height = Inches(0.8)
	
		table = shapes.add_table(num_row,num_col,left,top,width,height).table

		# set value for table titles
		i = 0
		for title in column_titles:
			table.cell(0,i).text = title
			table.cell(0,i).fill.solid()
			table.cell(0,i).fill.fore_color.rgb = RGBColor(0x0,0x0,0x5f)
			table.cell(0,i).text_frame.paragraphs[0].font.size = Pt(12)
			table.columns[i].width = Inches(column_widths[i])
			i += 1
		table.cell(1,len(column_titles)-2).fill.solid()
		table.cell(1,len(column_titles)-2).fill.fore_color.rgb = RGBColor(0xff,0x0,0x0)
Ejemplo n.º 14
0
def start3():
    slide = prs.slides.add_slide(blank_slide_layout)
    #设置背景图片和主标题
    img_path = 'backgrounds/3_1.jpg'
    left, top, width, height = Inches(0), Inches(0), Inches(13.5), Inches(7.5)
    pic = slide.shapes.add_picture(img_path, left, top, width, height)
    #主标题
    left, top, width, height = Inches(5), Inches(2.5), Inches(5), Inches(2)
    txBox = slide.shapes.add_textbox(left, top, width, height)
    tf = txBox.text_frame
    p = tf.add_paragraph()
    p.font.name = '黑体'
    p.font.bold = True
    p.text = "工作总结"
    p.font.color.rgb = RGBColor(255, 255, 0)
    p.font.size = Pt(80)
    #副标题1
    left = Inches(7)
    top = Inches(5)
    width = Inches(3)
    height = Inches(0.8)
    txBox = slide.shapes.add_textbox(left, top, width, height)
    tf = txBox.text_frame
    p = tf.add_paragraph()
    p.font.name = '黑体'
    p.font.color.rgb = RGBColor(255, 255, 0)
    p.text = "汇报人:XXXXX\n 日期:XXXXX"
    p.font.size = Pt(25)
    prs.save('test.pptx')
Ejemplo n.º 15
0
def create():
    file = open('positive-words.txt',"r")
    wordList = []
    
    for line in file:
        for word in line.split():
            wordList.append(word)
            
    
    
    prs = Presentation()
    
    for x in range(5):
        blank_slide_layout = prs.slide_layouts[6]
        slide = prs.slides.add_slide(blank_slide_layout)
        background = slide.background
        fill = background.fill
        fill.solid()
        red = randrange(255)
        green = randrange(255)
        blue = randrange(255)
        fill.fore_color.rgb = RGBColor(red, green, blue)
        width= Inches(10)
        txBox = slide.shapes.add_textbox(Inches(0), Inches(2.5), width, Inches(2.5))
        tf = txBox.text_frame
        p = tf.add_paragraph()
        p.text = random.choice(wordList).upper()
        p.font.bold = True
        p.font.size = Pt(120)
        p.alignment = PP_ALIGN.CENTER
        t = complement(red, green, blue) 
        p.font.color.rgb = RGBColor(t[0], t[1], t[2])
    
    
    prs.save('base.pptx')
Ejemplo n.º 16
0
def build_deck(pages):
    """Returns the actual PowerPoint deck."""
    pres = Presentation()
    blank_slidelayout = pres.slide_layouts[6]

    for page in pages:
        slide = pres.slides.add_slide(blank_slidelayout)

        left = top = Inches(0)
        width = Inches(10)
        height = Inches(5.63)

        shape = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, left, top, width,
                                       height)
        shape.fill.solid()
        shape.fill.fore_color.rgb = RGBColor(0, 0, 0)

        textbox = slide.shapes.add_textbox(left, top, width, height)
        textframe = textbox.text_frame

        para = textframe.paragraphs[0]
        run = para.add_run()
        run.font.name = "Consolas"
        run.font.size = Pt(7)
        run.font.color.rgb = RGBColor(255, 255, 255)

        f = open(page)
        run.text = f.read()
        f.close()

    return pres
Ejemplo n.º 17
0
def create(filename, prs_content, background_color, text_color):
    if (not ('.pptx' in filename)):
        filename += '.pptx'

    prs = Presentation()

    content_slide_layout = prs.slide_layouts[0]
    slide = prs.slides.add_slide(content_slide_layout)

    background = slide.background
    fill = background.fill
    fill.solid()
    fill.fore_color.rgb = RGBColor(background_color[0], background_color[1],
                                   background_color[2])

    left = top = Inches(1)
    width = Inches(8)
    height = Inches(6)

    content = slide.shapes.add_textbox(left, top, width, height)
    content.text = prs_content

    # most of the shapes only contain one paragraph for this use case
    content.text_frame.paragraphs[0].font.color.rgb = RGBColor(
        text_color[0], text_color[1], text_color[2])

    pptx_path = tempfile.gettempdir() + '/' + filename
    prs.save(pptx_path)
    return pptx_path
Ejemplo n.º 18
0
def update_titles(prs, dlpx_engine_name, author_name):
    """
    Update title on each slide plus update a first slide
    :param1 prs: Presentaton object
    :param2 dlpx_engine_name: Engine name 
    :param3 author_name: name of enginner to show on 1st page
    """
    for slide in prs.slides:  # iterate over each slide
        # title_shape =  slide.shapes[0] # consider the zeroth indexed shape as the title
        # if title_shape.has_text_frame: # is this shape has textframe attribute true then
        slidenum = prs.slides.index(slide) + 1
        if slidenum == 1:
            slideNameDate = slide.shapes[0]
            slideHeading = slide.shapes[1]
            slideHeading.text_frame.paragraphs[0].runs[
                0].text = dlpx_engine_name
            if slideNameDate.has_text_frame:
                runs = slideNameDate.text_frame.paragraphs[0].runs
                runs[0].text = author_name
                runs[0].font.color.rgb = RGBColor(26, 214, 245)
                runs[7].text = time.strftime("%d %b %Y")
                runs[7].font.color.rgb = RGBColor(255, 255, 255)
        elif slidenum not in dxslideconfig.skip_title_update_slides:
            if slide.shapes.title:
                slide.shapes.title.text = dlpx_engine_name + " " + slide.shapes.title.text
Ejemplo n.º 19
0
def convert_pptx(filename, filePathName, outputpath):
    print("The output path is", outputpath)
    filePathName = os.path.join(filePathName, filename)
    prs = Presentation(filePathName)

    for slide in prs.slides:
        '''Changing background color'''
        background = slide.background
        fill = background.fill
        fill.solid()
        fill.fore_color.rgb = RGBColor(0, 0, 0)
        '''Adding Color to the text'''
        for shape in slide.shapes:
            if not shape.has_text_frame:
                continue
            text_frame = shape.text_frame
            try:
                i = 0
                while (text_frame.paragraphs[i]):
                    p = text_frame.paragraphs[i]
                    p.font.color.rgb = RGBColor(255, 255, 255)
                    i = i + 1
            except:
                pass
    '''Saving the File'''
    path_to_file = os.path.join(outputpath, 'DarkFile.pptx')
    print("PAth to file is ", path_to_file)
    prs.save(path_to_file)
    print("Done")
    def make_ppt(self):
        prs = Presentation()

        textdata = self.text.get(1.0, END)

        lines = textdata.splitlines()
        linesCount = len(textdata.splitlines())

        i = 0
        while i < linesCount:

            if not lines[i]:
                i = i + 1
                continue

            slide = prs.slides.add_slide(prs.slide_layouts[6])

            url = 'https://source.unsplash.com/1600x900/?landscape'
            response = requests.get(url, stream=True)
            with open('img.png', 'wb') as f:
                f.write(response.content)
            del response

            pic = slide.shapes.add_picture('img.png', Inches(0), Inches(0),
                                           prs.slide_width, prs.slide_height)
            slide.shapes._spTree.remove(pic._element)
            slide.shapes._spTree.insert(2, pic._element)

            txBox = slide.shapes.add_textbox(Inches(0), Inches(3),
                                             prs.slide_width, Inches(1.5))
            #txBox.vertical_anchor = MSO_ANCHOR.MIDDLE

            tf = txBox.text_frame
            p = tf.paragraphs[0]
            p.text = lines[i]
            p.alignment = PP_ALIGN.CENTER
            p.font.name = "BEBAS KAI"
            p.font.size = Pt(40)
            p.font.color.rgb = RGBColor(0xFF, 0xFF, 0xFF)

            if i < linesCount - 1 and lines[i + 1] != "":
                p = tf.add_paragraph()
                p.text = lines[i + 1]
                p.alignment = PP_ALIGN.CENTER
                p.font.name = "BEBAS KAI"
                p.font.size = Pt(40)
                p.font.color.rgb = RGBColor(0xFF, 0xFF, 0xFF)

            txBox.fill.solid()
            txBox.fill.fore_color.rgb = RGBColor(0x00, 0x00, 0x00)
            txBox.fill.fore_color.brightness = 0.4

            time.sleep(2.5)
            i = i + 2

        filename = lines[0].encode('utf-8') + '.pptx'
        prs.save(filename)
        os.rename(filename, lines[0] + '.pptx')
        App.show_message(self, "Done!")
Ejemplo n.º 21
0
def title_presentation(prs, year: str, VERSION: str, **kwargs):
    """Title Slide

    Arguments:
        prs {pptx-obj} -- powerpoint python object
        year {str} -- '2020', for exampe
        VERSION {str} -- '0.2.02', for example

    Returns:
        pptx-obj -- powerpoint object
    """
    height = prs.slide_height
    width = int(16 * height / 9)
    prs.slide_width = width
    slide = prs.slides.add_slide(prs.slide_layouts[BLANK_SLIDE])

    LEFT_INCHES = 6
    left = Inches(LEFT_INCHES)
    top = Inches(2.45)
    text = slide.shapes.add_textbox(left, top, Inches(1), Inches(1))
    text_frame = text.text_frame

    p = text_frame.paragraphs[0]
    p.alignment = PP_ALIGN.CENTER
    p.text = f'Securities Analysis'
    p.font.bold = True
    p.font.size = Pt(48)
    p.font.name = 'Arial'

    p4 = text_frame.add_paragraph()
    p4.alignment = PP_ALIGN.CENTER
    p4.text = f"A Technical Analysis of Financial Markets by 'nga-27'"
    p4.font.italic = True
    p4.font.size = Pt(14)
    p4.font.color.rgb = RGBColor(0x74, 0x3c, 0xe6)
    p4.font.name = 'Arial'

    left = Inches(LEFT_INCHES)
    top = Inches(4.0)
    text = slide.shapes.add_textbox(left, top, Inches(1), Inches(1))
    text_frame2 = text.text_frame

    p2 = text_frame2.paragraphs[0]
    p2.alignment = PP_ALIGN.CENTER
    p2.text = f'Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}'
    p2.font.bold = False
    p2.font.size = Pt(22)
    p2.font.color.rgb = RGBColor(0x30, 0x9c, 0x4f)
    p2.font.name = 'Arial'

    p3 = text_frame2.add_paragraph()
    p3.alignment = PP_ALIGN.CENTER
    p3.text = f'Software Version: {VERSION}'
    p3.font.bold = False
    p3.font.size = Pt(18)
    p3.font.color.rgb = RGBColor(0x30, 0x9c, 0x4f)
    p3.font.name = 'Arial'

    return prs
Ejemplo n.º 22
0
def generate_calendar_heading(calendar_col_dates, calendar_col_months, slide):
    # generate table for week date labels
    shapes = slide.shapes
    rows = 1
    cols = 11
    top = Inches(1.01)
    left = Inches(1.25)
    width = Inches(11.575)
    height = Inches(0.425)
    table2 = shapes.add_table(rows, cols, left, top, width, height).table

    # set table color by column
    for i in range(11):
        fill2 = table2.cell(0, i).fill
        fill2.solid()
        fill2.fore_color.rgb = RGBColor(228, 229, 227)
        fill2.fore_color.theme_color = MSO_THEME_COLOR.ACCENT_2

    # set font color and add text runs by column
    for i in range(11):
        text_frame = table2.cell(0, i).text_frame
        text_frame.vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE
        p = text_frame.paragraphs[0]
        p.alignment = PP_ALIGN.CENTER
        run = p.add_run()
        run.text = calendar_col_dates[i]
        run.font.name = 'NeueHaasGroteskText Std (Body)'
        run.font.size = Pt(11)
        run.font.color.rgb = RGBColor(0, 0, 0)

    month_row_amt, month_row_labels = month_cols_and_labels(
        calendar_col_months)

    # generate table for month labels
    rows = 1
    cols = len(month_row_amt)
    top = Inches(0.585)
    left = Inches(1.25)
    width = Inches(11.575)
    height = Inches(0.425)
    table1 = shapes.add_table(rows, cols, left, top, width, height).table

    for i in range(len(month_row_amt)):
        # by row
        table1.columns[i].width = Inches(1.05 * month_row_amt[i])
        fill1 = table1.cell(0, i).fill
        fill1.solid()
        fill1.fore_color.rgb = RGBColor(173, 175, 175)
        text_frame = table1.cell(0, i).text_frame
        text_frame.vertical_anchor = MSO_VERTICAL_ANCHOR.MIDDLE
        p = text_frame.paragraphs[0]
        p.alignment = PP_ALIGN.CENTER
        run = p.add_run()
        run.text = month_row_labels[i]
        run.font.italic = True
        run.font.bold = True
        run.font.name = 'NeueHaasGroteskText Std (Body)'
        run.font.size = Pt(11)
        run.font.color.rgb = RGBColor(0, 0, 0)
Ejemplo n.º 23
0
def setup(tab):
    for r in range(len(tab.rows)):
        for c in range(len(tab.columns)):
            tab.cell(r, c).fill.solid()
            tab.cell(r, c).fill.fore_color.rgb = RGBColor(255, 255, 255)
            tab.cell(r, c).text_frame.paragraphs[0].font.size = Pt(15)
            tab.cell(r, c).text_frame.paragraphs[0].font.color.rgb = RGBColor(
                49, 56, 64)
Ejemplo n.º 24
0
 def it_is_natively_constructed_using_three_ints_0_to_255(self):
     RGBColor(0x12, 0x34, 0x56)
     with pytest.raises(ValueError):
         RGBColor('12', '34', '56')
     with pytest.raises(ValueError):
         RGBColor(-1, 34, 56)
     with pytest.raises(ValueError):
         RGBColor(12, 256, 56)
Ejemplo n.º 25
0
def drawbar(shapes,
            df,
            title,
            left=Inches(0.5),
            top=Inches(1),
            width=Inches(6),
            height=Inches(6.5),
            sorted=True,
            fontsize=18):
    # values = df.values.tolist()
    columns = df.columns.values.tolist()  # 列名
    df = df.dropna()
    if sorted:  # 默认对数值排序
        sort_item = columns[1]
        df = df.sort_values(by=sort_item)
    df_labels = df.iloc[:, 0]  # 部门

    df_values = df.iloc[:, 1:]  # 数值
    labels = df_labels.values.tolist()
    chart_data = ChartData()
    for i in range(df_values.shape[1]):
        values = df_values.iloc[:, i].values.tolist()
        column = columns[i + 1]
        chart_data.add_series(column, values)
    chart_data.categories = labels
    # x, y, cx, cy = Inches(0.5), Inches(1), Inches(6), Inches(6.5)
    graphic_frame = shapes.add_chart(XL_CHART_TYPE.BAR_CLUSTERED, left, top,
                                     width, height, chart_data)
    graphic_frame.chart.has_title = True
    graphic_frame.chart.chart_title.text_frame.clear()
    new_title = graphic_frame.chart.chart_title.text_frame.add_paragraph()
    new_title.text = title
    new_title.font.size = Pt(24)
    new_title.font.bold = True
    series = graphic_frame.chart.series[0]
    series.invert_if_negative = False  # 没什么卵用
    for i in range(df_values.shape[0]):
        point = series.points[i]
        fill = point.format.fill
        fill.patterned()  # 此处不可用solid(),否则负值会被取反色
        fill.fore_color.rgb = RGBColor(210, 71, 38)  # orange
        fill.back_color.rgb = RGBColor(210, 71, 38)  # 背景色也被设置为橙色,背景色就是负值颜色
    plot = graphic_frame.chart.plots[0]  # 取图表中第一个plot
    plot.has_data_labels = True  # 是否显示数据标签
    data_labels = plot.data_labels  # 数据标签控制类
    data_labels.position = XL_DATA_LABEL_POSITION.OUTSIDE_END  # 字体位置
    data_labels.font.bold = True
    data_labels.number_format = '0.0%'
    data_labels.font.size = Pt(fontsize)
    category_axis = graphic_frame.chart.category_axis  # 纵轴标签控制类
    category_axis.tick_labels.font.bold = True
    category_axis.tick_label_position = XL_TICK_LABEL_POSITION.LOW
    category_axis.has_major_gridlines = False
    value_axis = graphic_frame.chart.value_axis  # 横轴值坐标标签控制类
    value_axis.tick_labels.number_format = '0%'
    value_axis.has_minor_gridlines = False
    value_axis.has_major_gridlines = False
    return graphic_frame
Ejemplo n.º 26
0
def add_wide_formation_and_defense_slide(play, slide, offense_library, defense_library, is_for_offense, college_hash_marks):
    #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
        if college_hash_marks:
            slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT, LEFT_HASH_COLLEGE, CENTER_Y_POS + num * FIVE_YARDS - HASH_SIZE, LEFT_HASH_COLLEGE, CENTER_Y_POS + num * FIVE_YARDS + HASH_SIZE)
            slide.shapes.add_connector(MSO_CONNECTOR_TYPE.STRAIGHT, RIGHT_HASH_COLLEGE, CENTER_Y_POS + num * FIVE_YARDS - HASH_SIZE, RIGHT_HASH_COLLEGE, CENTER_Y_POS + num * FIVE_YARDS + HASH_SIZE)
        else:
            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']

    if formation_name:
        subformation, error_message = offense_library.get_composite_subformation(play['Hash'], formation_name)
        if not subformation:
            return
        for tag, player in subformation.players.items():
            try:
                label = offense_library.label_mappers[play['Personnel']].get_label(tag)
            except KeyError:
                label = offense_library.label_mappers['default'].get_label(tag)
            x, y = player_coordinates_to_powerpoint(player.x, player.y, False, is_for_offense)
            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 = label
            shape.text_frame.paragraphs[0].font.size = Pt(12) if len(label) == 1 else Pt(9)
            shape.text_frame.word_wrap = False
            shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
            shape.text_frame.paragraphs[0].alignment = PP_PARAGRAPH_ALIGNMENT.CENTER

    if defense_name:
        composite_defense = defense_library.get_composite_defense(defense_name)
        composite_defense.place_defenders(subformation)
        for tag, defender in composite_defense.players.items():
            if (defender.placed_x, defender.placed_y) == INVALID_POSITION:
                continue
            label = defense_library.label_mappers['default'].get_label(tag)
            x, y = player_coordinates_to_powerpoint(defender.placed_x, defender.placed_y * -1, False, is_for_offense)
            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)
Ejemplo n.º 27
0
def create_chart(chart_name, slide_name, placeholder_index, categories, series,
                 name_of_attribute):
    chart_data = ChartData()
    my_tuple = list(zip(categories, series))
    my_tuple.sort(key=lambda elem: elem[1])
    new_cat = [i[0] for i in my_tuple]
    new_series = [i[1] for i in my_tuple]
    if name_of_attribute == "Food taste and flavor":
        index = new_series.index(
            kpis[slugify(Chain)]["attributes"]["Food taste and flavor"])
    elif name_of_attribute == "Overall Rating":
        index = new_series.index(
            kpis[slugify(Chain)]["attributes"]["Overall Rating"])
    elif name_of_attribute == "Food quality":
        index = new_series.index(
            kpis[slugify(Chain)]["attributes"]["Food quality"])
    elif name_of_attribute == "Food quality takeout":
        index = new_series.index(
            kpis[slugify(Chain)]["attributes"]["Food quality takeout"])
    elif name_of_attribute == "Interior cleanliness":
        index = new_series.index(
            kpis[slugify(Chain)]["attributes"]["Interior cleanliness"])
    elif name_of_attribute == "Kitchen/food prep area cleanliness":
        index = new_series.index(kpis[slugify(Chain)]["attributes"]
                                 ["Kitchen/food prep area cleanliness"])
    elif name_of_attribute == "Order accuracy":
        index = new_series.index(
            kpis[slugify(Chain)]["attributes"]["Order accuracy"])
    else:
        index = new_series.index(kpis[slugify(Chain)]["attributes"]
                                 ["Dishware/glassware/silverware cleanliness"])

    # index = [name_of_attribute for name_of_attribute in new_series.index(kpis[slugify(Chain)]["attributes"][name_of_attribute]) if name_of_attribute == name_of_attribute]

    chart_data.categories = (new_cat)
    chart_data.add_series('Series1', (new_series))
    chart_name = slide_name.placeholders[placeholder_index].insert_chart(
        XL_CHART_TYPE.BAR_CLUSTERED, chart_data)
    chart_name.chart.plots[0].series[0].format.fill.solid()
    chart_name.chart.plots[0].series[0].format.fill.fore_color.rgb = RGBColor(
        192, 192, 192)
    chart_name.chart.plots[0].has_data_labels = True
    chart_name.chart.value_axis.has_major_gridlines = False
    chart_name.chart.value_axis.visible = False
    chart_name.chart.plots[0].data_labels.font.size = Pt(14)
    chart_name.chart.plots[0].data_labels.number_format = '#,##0.0%'
    chart_name.chart.plots[0].chart.value_axis.maximum_scale = .95
    chart_name.chart_part.chart.category_axis.major_tick_mark = XL_TICK_MARK.NONE
    point = chart_name.chart.plots[0].series[0].points[index]
    fill = point.format.fill
    fill.solid()
    fill.fore_color.rgb = RGBColor(225, 34, 34)
    chart_name.chart.plots[0].chart.category_axis.format.line.fill.solid()
    chart_name.chart.plots[
        0].chart.category_axis.format.line.fill.fore_color.rgb = RGBColor(
            255, 255, 255)
Ejemplo n.º 28
0
def addtext(slide, text, x, y, w, h, **kwargs):
    """Add text (box) to given slide."""
    # https://python-pptx.readthedocs.io/en/latest/api/enum/MsoAutoShapeType.html#msoautoshapetype
    # https://python-pptx.readthedocs.io/en/latest/user/autoshapes.html#adjusting-an-autoshape
    # https://stackoverflow.com/questions/40149992/python-pptx-align-image-to-center-of-slide
    verb = kwargs.get('verb', 0)
    tsize = kwargs.get('lsize', 12)  # legend font size
    tcolor = kwargs.get('lcolor', None)  # legend font color
    fcolor = kwargs.get('fill', (6, 46, 162))  # box fill color
    lcolor = kwargs.get('line', (1, 23, 81))  # box line color
    thick = kwargs.get('thick', 1.5)  # box line thickness (0 = no line)
    bold = kwargs.get('bold', True)
    shadow = kwargs.get('shadow', False)
    boxtype = kwargs.get('box', 'round')
    print(">>>   Add text at (x,y,w,h)=(%.2f cm,%.2f cm,%.2f cm,%.2f cm): %r" %
          (x, y, w, h, text))
    const = MSO_SHAPE.ROUNDED_RECTANGLE if 'round' in boxtype else MSO_SHAPE.RECTANGLE
    box = slide.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Cm(x), Cm(y),
                                 Cm(w), Cm(h))
    box.text = text
    paragraph = box.text_frame.paragraphs[0]
    paragraph.alignment = PP_ALIGN.CENTER
    box.text_frame.vertical_anchor = MSO_ANCHOR.MIDDLE
    box.text_frame.margin_top = 0  #Pt(0.5)
    box.text_frame.margin_bottom = 0  #Pt(0.5)
    if 'round' in boxtype:
        box.adjustments[0] = 0.15  # rounded corner
    ###if not tsize or tsize=='auto':
    ###  #box.text_frame.auto_size = MSO_AUTO_SIZE.SHAPE_TO_FIT_TEXT
    ###  box.text_frame.auto_size = MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE
    ###  #paragraph.font.size = Pt(12)
    ###  box.text_frame.fit_text(font_family='Arial') #autofit_text
    ###else:
    if tsize:
        paragraph.font.size = Pt(tsize)
    if tcolor:
        paragraph.font.color.rgb = RGBColor(*tcolor)
    if bold:
        paragraph.font.bold = True
    box.shadow.inherit = shadow  # turn on/off shadow
    fill = box.fill
    if fcolor:
        fill.solid()
        fill.fore_color.rgb = RGBColor(*fcolor)
    else:
        fill.background()  # no fill / transparant
    line = box.line
    if thick:
        line.width = Pt(thick)
        if lcolor:  # user color
            line.color.rgb = RGBColor(*lcolor)
        #line.color.brightness = 0.5  # 50% lighter
    else:
        line.fill.background()  # no line / transparant
    return box
Ejemplo n.º 29
0
def apresentacao(texto):  #texto , quantidade

    texto = texto.split('\n')
    musica = []

    for linha in texto:
        musica = texto

    #num = 0
    #for x in musica:
    #    print(musica[num].strip())
    #    num = num + 1

    y = 0
    n_slides = 0
    quantidadePorSlide = 5
    calculoTamanhoTexto = len(musica) / quantidadePorSlide
    restanteTexto = len(musica) % quantidadePorSlide
    total = int(calculoTamanhoTexto) + restanteTexto
    prs = Presentation()
    #print(len(musica))
    for x in range(total):

        page_slide = prs.slide_layouts[n_slides]
        slide = prs.slides.add_slide(page_slide)
        background = slide.background
        fill = background.fill
        fill.solid()
        fill.fore_color.rgb = RGBColor(0, 0, 0)

        top = width = height = Inches(2)
        left = Inches(1)
        txBox = slide.shapes.add_textbox(left, top, width, height)

        tf = txBox.text_frame

        for i in range(quantidadePorSlide + 1):
            if (y < len(musica)):

                p = tf.add_paragraph()
                p.text = musica[y]
                p.font.size = Pt(40)
                p.font.bold = True
                p.font.color.rgb = RGBColor(255, 255, 255)

                #print(musica[y]+'linha:'+str(y))
                y = y + 1
            else:
                prs.save(nome_musica + ".pptx")
                #x = input('Parou no ELSE aqui')
                return
        print('')
        n_slides = n_slides + 1

    prs.save(nome_musica + ".pptx")
Ejemplo n.º 30
0
    def do_inner_proc(self, dt, slide):
        lst_fig_title = self.category_conf['lst_fig_title']
        for i, fig_type in enumerate(self.category_conf['lst_fig_type']):
            self.fig_dir = self.category_conf['lst_fig_dir'][i]
            self.prefix = self.category_conf['lst_prefix'][i]
            self.str_suffix = self.category_conf['lst_suffix'][i]
            icol = i % self.ncols
            irow = i / self.ncols

            if self.str_suffix == '{0:04d}{1:02d}{2:02d}{3:02d}.png':
                self.suffix = self.str_suffix.format(dt.year, dt.month, dt.day,
                                                     dt.hour)
            elif self.str_suffix == '{3:02d}Z{2:02d}{1}{0:04d}.png':
                self.suffix = self.str_suffix.format(dt.year,
                                                     dt.strftime("%b").upper(),
                                                     dt.day, dt.hour)
            elif self.str_suffix == '{0:02d}{1:02d}{2:02d}.png':
                dt_tmp = dt + datetime.timedelta(hours=11)
                self.suffix = self.str_suffix.format(dt_tmp.month, dt_tmp.day,
                                                     dt_tmp.hour)

            if self.special_care(fig_type, icol, irow, dt, slide):
                continue

            if fig_type == "-":
                continue

            left = Inches(self.col_sta + self.col_int * icol)
            top = Inches(self.row_sta + self.row_int * irow)
            width = Inches(self.sizex)
            height = Inches(self.sizey)
            img_path = self.get_filepath(self.fig_dir, fig_type, self.suffix)
            slide.shapes.add_picture(img_path, left, top, height, width)

            top_figtitle = top - Inches(0.080)
            height_figtitle = Inches(0.4)
            txBox_figtitle = slide.shapes.add_textbox(left, top_figtitle,
                                                      width, height_figtitle)
            txBox_figtitle.fill.solid()
            txBox_figtitle.fill.fore_color.rgb = RGBColor(0xFF, 0xFF, 0xFF)
            tf_figtitle = txBox_figtitle.text_frame
            tf_figtitle.auto_size = MSO_AUTO_SIZE.TEXT_TO_FIT_SHAPE
            tf_figtitle.text = lst_fig_title[i]
            p = tf_figtitle.paragraphs[0]
            p.alignment = PP_ALIGN.CENTER
            p.font.size = Pt(14)

            left_ = Inches(9.45 - len(self.section_title) * 0.09225)
            top_ = Inches(0.1)
            width_ = Inches(0.45 + len(self.section_title) * 0.0925)
            height_ = Inches(0.4)
            txBox = slide.shapes.add_textbox(left_, top_, width_, height_)
            txBox.line.color.rgb = RGBColor(0x00, 0x00, 0x00)
            tf = txBox.text_frame
            tf.text = self.section_title