def given_an_unpopulated_placeholder_shape(context, placeholder_type): slide_idx = [ 'title', 'content', 'text', 'chart', 'table', 'smart art', 'media', 'clip art', 'picture', ].index(placeholder_type) prs = Presentation(test_pptx('ph-unpopulated-placeholders')) context.shape = prs.slides[slide_idx].shapes[0]
def given_a_chart_of_type_chart_type(context, chart_type): slide_idx, shape_idx = { 'Area': (0, 0), 'Stacked Area': (0, 1), '100% Stacked Area': (0, 2), '3-D Area': (0, 3), '3-D Stacked Area': (0, 4), '3-D 100% Stacked Area': (0, 5), 'Clustered Bar': (1, 0), 'Stacked Bar': (1, 1), '100% Stacked Bar': (1, 2), 'Clustered Column': (1, 3), 'Stacked Column': (1, 4), '100% Stacked Column': (1, 5), 'Line': (2, 0), 'Stacked Line': (2, 1), '100% Stacked Line': (2, 2), 'Marked Line': (2, 3), 'Stacked Marked Line': (2, 4), '100% Stacked Marked Line': (2, 5), 'Pie': (3, 0), 'Exploded Pie': (3, 1), 'XY (Scatter)': (4, 0), 'XY Lines': (4, 1), 'XY Lines No Markers': (4, 2), 'XY Smooth Lines': (4, 3), 'XY Smooth No Markers': (4, 4), 'Bubble': (5, 0), '3D-Bubble': (5, 1), 'Radar': (6, 0), 'Marked Radar': (6, 1), 'Filled Radar': (6, 2), }[chart_type] prs = Presentation(test_pptx('cht-chart-type')) context.chart = prs.slides[slide_idx].shapes[shape_idx].chart
def given_a_slide_with_a_type_ph_with_content(context, type_, content): slide_idx = [ 'picture', 'clip art', 'table', 'chart', 'title', 'content', 'text', 'smart art', 'media', ].index(type_) prs = Presentation(test_pptx('ph-populated-placeholders')) context.shape = prs.slides[slide_idx].shapes[0]
def given_a_chart_of_type_chart_type(context, chart_type): slide_idx, shape_idx = { 'Area': (0, 0), 'Stacked Area': (0, 1), '100% Stacked Area': (0, 2), '3-D Area': (0, 3), '3-D Stacked Area': (0, 4), '3-D 100% Stacked Area': (0, 5), 'Clustered Bar': (1, 0), 'Stacked Bar': (1, 1), '100% Stacked Bar': (1, 2), 'Clustered Column': (1, 3), 'Stacked Column': (1, 4), '100% Stacked Column': (1, 5), 'Line': (2, 0), 'Stacked Line': (2, 1), '100% Stacked Line': (2, 2), 'Marked Line': (2, 3), 'Stacked Marked Line': (2, 4), '100% Stacked Marked Line': (2, 5), 'Pie': (3, 0), 'Exploded Pie': (3, 1), }[chart_type] prs = Presentation(test_pptx('cht-chart-type')) context.chart = prs.slides[slide_idx].shapes[shape_idx].chart
def given_a_FillFormat_object_as_fill_having_pattern(context, pattern): shape_idx = {"no pattern": 0, "MSO_PATTERN.DIVOT": 1, "MSO_PATTERN.WAVE": 2}[ pattern ] slide = Presentation(test_pptx("dml-fill")).slides[1] fill = slide.shapes[shape_idx].fill context.fill = fill
def given_a_chart_having_or_not_a_legend(context, having_or_not): slide_idx = { 'having': 0, 'not having': 1, }[having_or_not] prs = Presentation(test_pptx('cht-legend')) context.chart = prs.slides[slide_idx].shapes[0].chart
def given_a_font_having_size_of_value(context, value): shape_idx = {"no explicit value": 0, "42pt": 1}[value] prs = Presentation(test_pptx("txt-font-props")) slide = prs.slides[1] textbox = slide.shapes[shape_idx] run = textbox.text_frame.paragraphs[0].runs[0] context.font = run.font
def given_a_bar_plot_having_or_not_data_labels(context, having_or_not): slide_idx = { 'having': 0, 'not having': 1, }[having_or_not] prs = Presentation(test_pptx('cht-plot-props')) context.plot = prs.slides[slide_idx].shapes[0].chart.plots[0]
def given_a_bar_series_with_values(context, values): prs = Presentation(test_pptx('cht-series-props')) series_idx = { '1.2, 2.3, 3.4': 0, '4.5, None, 6.7': 1, }[values] context.series = prs.slides[1].shapes[0].chart.plots[0].series[series_idx]
def given_run_with_underline_set_to_state(context, state): run_idx = [ 'on', 'off', 'to inherit', 'to DOUBLE_LINE', 'to WAVY_LINE' ].index(state) prs = Presentation(test_pptx('txt-font-props')) runs = prs.slides[3].shapes[0].text_frame.paragraphs[0].runs context.font = runs[run_idx].font
def given_a_axis_type_axis(context, axis_type): prs = Presentation(test_pptx('cht-axis-props')) chart = prs.slides[0].shapes[0].chart context.axis = { 'category': chart.category_axis, 'value': chart.value_axis, }[axis_type]
def given_tick_labels_having_an_offset_of_setting(context, setting): slide_idx = { 'no explicit setting': 0, '420': 1, }[setting] prs = Presentation(test_pptx('cht-ticklabels-props')) chart = prs.slides[slide_idx].shapes[0].chart context.tick_labels = chart.category_axis.tick_labels
def given_a_legend_with_overlay_setting_of_setting(context, setting): slide_idx = { 'no explicit setting': 0, 'True': 1, 'False': 2, }[setting] prs = Presentation(test_pptx('cht-legend-props')) context.legend = prs.slides[slide_idx].shapes[0].chart.legend
def given_a_legend_having_horizontal_offset_of_value(context, value): slide_idx = { 'none': 0, '-0.5': 1, '0.42': 2, }[value] prs = Presentation(test_pptx('cht-legend-props')) context.legend = prs.slides[slide_idx].shapes[0].chart.legend
def given_a_bar_series_having_width_line(context, width): series_idx = { 'no': 0, '1 point': 1, }[width] prs = Presentation(test_pptx('cht-series-props')) plot = prs.slides[0].shapes[0].chart.plots[0] context.series = plot.series[series_idx]
def given_a_paragraph_having_space_before_after_of_setting( context, before_after, setting ): slide_idx = {"before": 0, "after": 1}[before_after] paragraph_idx = {"no explicit setting": 0, "6 pt": 1}[setting] prs = Presentation(test_pptx("txt-paragraph-spacing")) text_frame = prs.slides[slide_idx].shapes[0].text_frame context.paragraph = text_frame.paragraphs[paragraph_idx]
def given_a_series_collection_for_chart_having_series(context, type_, count): slide_idx = { 'single-plot': 0, 'multi-plot': 1, }[type_] prs = Presentation(test_pptx('cht-series-access')) context.series_collection = prs.slides[slide_idx].shapes[0].chart.series context.series_count = int(count)
def given_a_legend_positioned_location_the_chart(context, location): slide_idx = { 'at an unspecified location of': 0, 'below': 1, 'to the right of': 2, }[location] prs = Presentation(test_pptx('cht-legend-props')) context.legend = prs.slides[slide_idx].shapes[0].chart.legend
def given_a_bar_plot_having_overlap_of_overlap(context, overlap): slide_idx = { 'no explicit value': 0, '42': 1, '-42': 2, }[overlap] prs = Presentation(test_pptx('cht-plot-props')) context.plot = prs.slides[slide_idx].shapes[0].chart.plots[0]
def given_a_bar_plot_having_vary_color_by_category_setting(context, setting): slide_idx = { 'no explicit setting': 0, 'True': 1, 'False': 2, }[setting] prs = Presentation(test_pptx('cht-plot-props')) context.plot = prs.slides[slide_idx].shapes[0].chart.plots[0]
def given_a_data_label_having_or_not_custom_text(context, having_or_not): point_idx = { 'having': 0, 'having no': 1, }[having_or_not] prs = Presentation(test_pptx('cht-point-props')) plot = prs.slides[0].shapes[0].chart.plots[0] context.data_label = plot.series[0].points[point_idx].data_label
def given_a_marker_having_style_of_case(context, case): series_idx = { 'no explicit value': 0, 'circle': 1, 'triangle': 2, }[case] prs = Presentation(test_pptx('cht-marker-props')) series = prs.slides[0].shapes[0].chart.series[series_idx] context.marker = series.marker
def given_a_Categories_obj_having_leafs_and_levels(context, leafs, levels): slide_idx = { (3, 1): 0, (8, 3): 1, (0, 0): 2, (4, 2): 3, }[(int(leafs), int(levels))] slide = Presentation(test_pptx('cht-category-access')).slides[slide_idx] context.categories = slide.shapes[0].chart.plots[0].categories
def given_a_bar_series_having_invert_if_negative_setting(context, setting): series_idx = { 'no explicit setting': 0, 'True': 1, 'False': 2, }[setting] prs = Presentation(test_pptx('cht-series-props')) plot = prs.slides[0].shapes[0].chart.plots[0] context.series = plot.series[series_idx]
def given_a_paragraph_having_line_spacing_of_setting(context, setting): paragraph_idx = { 'no explicit setting': 0, '1.5 lines': 1, '20 pt': 2, }[setting] prs = Presentation(test_pptx('txt-paragraph-spacing')) text_frame = prs.slides[2].shapes[0].text_frame context.paragraph = text_frame.paragraphs[paragraph_idx]
def given_bar_chart_data_labels_positioned_relation_to_their_data_point( context, relation_to): slide_idx = { 'in unspecified relation to': 0, 'inside, at the base of': 1, }[relation_to] prs = Presentation(test_pptx('cht-datalabels-props')) chart = prs.slides[slide_idx].shapes[0].chart context.data_labels = chart.plots[0].data_labels
def given_a_data_label_positioned_relation_its_data_point(context, relation): point_idx = { 'in unspecified relation to': 0, 'centered on': 1, 'below': 2, }[relation] prs = Presentation(test_pptx('cht-point-props')) plot = prs.slides[1].shapes[0].chart.plots[0] context.data_label = plot.series[0].points[point_idx].data_label
def given_a_points_type_object_containing_3_points(context, points_type): slide_idx = { 'XyPoints': 0, 'BubblePoints': 1, 'CategoryPoints': 2, }[points_type] prs = Presentation(test_pptx('cht-point-access')) series = prs.slides[slide_idx].shapes[0].chart.plots[0].series[0] context.points = series.points
def given_a_font_having_applied_size(context, applied_size): shape_idx = { 'no directly applied size': 0, 'a directly applied size of 42pt': 1, }[applied_size] prs = Presentation(test_pptx('txt-font-props')) slide = prs.slides[1] textbox = slide.shapes[shape_idx] run = textbox.text_frame.paragraphs[0].runs[0] context.font = run.font
def given_a_text_frame_having_auto_size_set_to_setting(context, setting): shape_idx = { 'None': 0, 'no auto-size': 1, 'fit shape to text': 2, 'fit text to shape': 3, }[setting] prs = Presentation(test_pptx('txt-text-frame-props')) shape = prs.slides[0].shapes[shape_idx] context.text_frame = shape.text_frame
def given_an_axis_having_major_or_minor_unit_of_value(context, major_or_minor, value): slide_idx = 0 if value == "Auto" else 1 prs = Presentation(test_pptx("cht-axis-props")) chart = prs.slides[slide_idx].shapes[0].chart context.axis = chart.value_axis
def given_slide_placeholder_with_directly_set_pos_and_size(context): prs = Presentation(test_pptx('ph-inherit-props')) context.placeholder = prs.slides[0].placeholders[10]
def given_a_picture(context): prs = Presentation(test_pptx('shp-common-props')) sld = prs.slides[0] context.shape = sld.shapes[1]
def given_a_FillFormat_object_as_fill(context): fill = Presentation(test_pptx('dml-fill')).slides[0].shapes[0].fill context.fill = fill
def given_a_2x2_Table_object_as_table(context): prs = Presentation(test_pptx("shp-shapes")) context.table_ = prs.slides[0].shapes[3].table
def given_a_shape_of_known_position_and_size(context): prs = Presentation(test_pptx('shp-pos-and-size')) context.shape = prs.slides[0].shapes[0]
def given_an_axis_title(context): prs = Presentation(test_pptx("cht-axis-props")) context.axis_title = prs.slides[7].shapes[0].chart.value_axis.axis_title
def given_an_autoshape_having_text(context): prs = Presentation(test_pptx('shp-autoshape-props')) context.shape = prs.slides[0].shapes[0]
def given_a_bar_plot_having_gap_width_of_width(context, width): slide_idx = {'no explicit value': 0, '300': 1}[width] prs = Presentation(test_pptx('cht-plot-props')) context.plot = prs.slides[slide_idx].shapes[0].chart.plots[0]
def given_a_chart_having_a_or_no_title(context, a_or_no): shape_idx = {'no': 0, 'a': 1}[a_or_no] prs = Presentation(test_pptx('cht-chart-props')) context.chart = prs.slides[0].shapes[shape_idx].chart
def given_a_chart(context): prs = Presentation(test_pptx('shp-common-props')) sld = prs.slides[0] context.chart = sld.shapes[6].chart
def given_a_graphic_frame_containing_a_table(context): prs = Presentation(test_pptx('shp-access-chart')) sld = prs.slides[1] context.shape = sld.shapes[0]
def given_an_axis_of_type_cls_name(context, cls_name): slide_idx = {"CategoryAxis": 0, "DateAxis": 6}[cls_name] prs = Presentation(test_pptx("cht-axis-props")) chart = prs.slides[slide_idx].shapes[0].chart context.axis = chart.category_axis
def given_a_point(context): prs = Presentation(test_pptx('cht-point-props')) chart = prs.slides[0].shapes[0].chart context.point = chart.plots[0].series[0].points[0]
def given_an_axis_not_having_major_or_minor_gridlines(context, major_or_minor): prs = Presentation(test_pptx("cht-axis-props")) chart = prs.slides[0].shapes[0].chart context.axis = chart.category_axis
def given_a_bubble_plot_having_bubble_scale_of_percent(context, percent): slide_idx = {'no explicit value': 3, '70%': 4}[percent] prs = Presentation(test_pptx('cht-plot-props')) context.bubble_plot = prs.slides[slide_idx].shapes[0].chart.plots[0]
def given_an_axis_title_having_a_or_no_text_frame(context, a_or_no): prs = Presentation(test_pptx("cht-axis-props")) chart = prs.slides[7].shapes[0].chart axis = {"a": chart.value_axis, "no": chart.category_axis}[a_or_no] context.axis_title = axis.axis_title
def given_a_category_plot(context): prs = Presentation(test_pptx('cht-plot-props')) context.plot = prs.slides[2].shapes[0].chart.plots[0]
def given_a_GradientStop_object_as_stop(context): shape = Presentation(test_pptx('dml-fill')).slides[0].shapes[4] context.stop = shape.fill.gradient_stops[0]
def given_a_series_collection_for_a_plot_having_count_series(context, count): prs = Presentation(test_pptx('cht-series-access')) plot = prs.slides[0].shapes[0].chart.plots[0] context.series_collection = plot.series context.series_count = int(count)
def given_a_marker(context): prs = Presentation(test_pptx('cht-marker-props')) series = prs.slides[0].shapes[0].chart.series[0] context.marker = series.marker
def given_slide_placeholder_with_no_direct_pos_or_size_settings(context): prs = Presentation(test_pptx('ph-inherit-props')) context.placeholder = prs.slides[0].placeholders[0]
def given_tick_labels_having_an_offset_of_setting(context, setting): slide_idx = {"no explicit setting": 0, "420": 1}[setting] prs = Presentation(test_pptx("cht-ticklabels-props")) chart = prs.slides[slide_idx].shapes[0].chart context.tick_labels = chart.category_axis.tick_labels
# encoding: utf-8 """ Gherkin step implementations for font color features """ from __future__ import absolute_import, print_function, unicode_literals from behave import given, then, when from pptx import Presentation from pptx.dml.color import RGBColor from pptx.enum.dml import MSO_COLOR_TYPE, MSO_THEME_COLOR from helpers import test_pptx font_color_pptx_path = test_pptx("font-color") # given =================================================== @given("a font with {color_type} color") def step_given_font_with_color_type(context, color_type): context.textbox_idx = {"no": 0, "an RGB": 1, "a theme": 2}[color_type] context.prs = Presentation(font_color_pptx_path) textbox = context.prs.slides[0].shapes[context.textbox_idx] context.font = textbox.text_frame.paragraphs[0].runs[0].font @given("a font with a color brightness setting of {setting}") def step_font_with_color_brightness(context, setting): textbox_idx = {
def given_a_series(context): prs = Presentation(test_pptx('cht-series-props')) context.series = prs.slides[0].shapes[0].chart.plots[0].series[0]
def given_a_major_gridlines(context): prs = Presentation(test_pptx("cht-gridlines-props")) axis = prs.slides[0].shapes[0].chart.value_axis context.gridlines = axis.major_gridlines
def given_an_axis(context): prs = Presentation(test_pptx("cht-axis-props")) chart = prs.slides[0].shapes[0].chart context.axis = chart.value_axis
def given_a_master_placeholder(context): prs = Presentation(test_pptx('ph-inherit-props')) context.master_placeholder = prs.slide_master.placeholders[1]
def given_a_chart_title(context): prs = Presentation(test_pptx('cht-chart-props')) context.chart_title = prs.slides[0].shapes[1].chart.chart_title
def given_a_chart_title_having_a_or_no_text_frame(context, a_or_no): prs = Presentation(test_pptx('cht-chart-props')) shape_idx = {'no': 0, 'a': 1}[a_or_no] context.chart_title = prs.slides[1].shapes[shape_idx].chart.chart_title