code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def gap_width(self): """ Width of gap between bar(s) of each category, as an integer percentage of the bar width. The default value for a new bar chart is 150, representing 150% or 1.5 times the width of a single bar. """ gapWidth = self._element.gapWidth if gapWidth is None: return 150 return gapWidth.val
Width of gap between bar(s) of each category, as an integer percentage of the bar width. The default value for a new bar chart is 150, representing 150% or 1.5 times the width of a single bar.
gap_width
python
scanny/python-pptx
src/pptx/chart/plot.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/plot.py
MIT
def overlap(self): """ Read/write int value in range -100..100 specifying a percentage of the bar width by which to overlap adjacent bars in a multi-series bar chart. Default is 0. A setting of -100 creates a gap of a full bar width and a setting of 100 causes all the bars in a category to be superimposed. A stacked bar plot has overlap of 100 by default. """ overlap = self._element.overlap if overlap is None: return 0 return overlap.val
Read/write int value in range -100..100 specifying a percentage of the bar width by which to overlap adjacent bars in a multi-series bar chart. Default is 0. A setting of -100 creates a gap of a full bar width and a setting of 100 causes all the bars in a category to be superimposed. A stacked bar plot has overlap of 100 by default.
overlap
python
scanny/python-pptx
src/pptx/chart/plot.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/plot.py
MIT
def overlap(self, value): """ Set the value of the ``<c:overlap>`` child element to *int_value*, or remove the overlap element if *int_value* is 0. """ if value == 0: self._element._remove_overlap() return self._element.get_or_add_overlap().val = value
Set the value of the ``<c:overlap>`` child element to *int_value*, or remove the overlap element if *int_value* is 0.
overlap
python
scanny/python-pptx
src/pptx/chart/plot.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/plot.py
MIT
def bubble_scale(self): """ An integer between 0 and 300 inclusive indicating the percentage of the default size at which bubbles should be displayed. Assigning |None| produces the same behavior as assigning `100`. """ bubbleScale = self._element.bubbleScale if bubbleScale is None: return 100 return bubbleScale.val
An integer between 0 and 300 inclusive indicating the percentage of the default size at which bubbles should be displayed. Assigning |None| produces the same behavior as assigning `100`.
bubble_scale
python
scanny/python-pptx
src/pptx/chart/plot.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/plot.py
MIT
def PlotFactory(xChart, chart): """ Return an instance of the appropriate subclass of _BasePlot based on the tagname of *xChart*. """ try: PlotCls = { qn("c:areaChart"): AreaPlot, qn("c:area3DChart"): Area3DPlot, qn("c:barChart"): BarPlot, qn("c:bubbleChart"): BubblePlot, qn("c:doughnutChart"): DoughnutPlot, qn("c:lineChart"): LinePlot, qn("c:pieChart"): PiePlot, qn("c:radarChart"): RadarPlot, qn("c:scatterChart"): XyPlot, }[xChart.tag] except KeyError: raise ValueError("unsupported plot type %s" % xChart.tag) return PlotCls(xChart, chart)
Return an instance of the appropriate subclass of _BasePlot based on the tagname of *xChart*.
PlotFactory
python
scanny/python-pptx
src/pptx/chart/plot.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/plot.py
MIT
def chart_type(cls, plot): """ Return the member of :ref:`XlChartType` that corresponds to the chart type of *plot*. """ try: chart_type_method = { "AreaPlot": cls._differentiate_area_chart_type, "Area3DPlot": cls._differentiate_area_3d_chart_type, "BarPlot": cls._differentiate_bar_chart_type, "BubblePlot": cls._differentiate_bubble_chart_type, "DoughnutPlot": cls._differentiate_doughnut_chart_type, "LinePlot": cls._differentiate_line_chart_type, "PiePlot": cls._differentiate_pie_chart_type, "RadarPlot": cls._differentiate_radar_chart_type, "XyPlot": cls._differentiate_xy_chart_type, }[plot.__class__.__name__] except KeyError: raise NotImplementedError( "chart_type() not implemented for %s" % plot.__class__.__name__ ) return chart_type_method(plot)
Return the member of :ref:`XlChartType` that corresponds to the chart type of *plot*.
chart_type
python
scanny/python-pptx
src/pptx/chart/plot.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/plot.py
MIT
def name(self): """ The string label given to this series, appears as the title of the column for this series in the Excel worksheet. It also appears as the label for this series in the legend. """ names = self._element.xpath("./c:tx//c:pt/c:v/text()") name = names[0] if names else "" return name
The string label given to this series, appears as the title of the column for this series in the Excel worksheet. It also appears as the label for this series in the legend.
name
python
scanny/python-pptx
src/pptx/chart/series.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/series.py
MIT
def values(self): """ Read-only. A sequence containing the float values for this series, in the order they appear on the chart. """ def iter_values(): val = self._element.val if val is None: return for idx in range(val.ptCount_val): yield val.pt_v(idx) return tuple(iter_values())
Read-only. A sequence containing the float values for this series, in the order they appear on the chart.
values
python
scanny/python-pptx
src/pptx/chart/series.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/series.py
MIT
def invert_if_negative(self): """ |True| if a point having a value less than zero should appear with a fill different than those with a positive value. |False| if the fill should be the same regardless of the bar's value. When |True|, a bar with a solid fill appears with white fill; in a bar with gradient fill, the direction of the gradient is reversed, e.g. dark -> light instead of light -> dark. The term "invert" here should be understood to mean "invert the *direction* of the *fill gradient*". """ invertIfNegative = self._element.invertIfNegative if invertIfNegative is None: return True return invertIfNegative.val
|True| if a point having a value less than zero should appear with a fill different than those with a positive value. |False| if the fill should be the same regardless of the bar's value. When |True|, a bar with a solid fill appears with white fill; in a bar with gradient fill, the direction of the gradient is reversed, e.g. dark -> light instead of light -> dark. The term "invert" here should be understood to mean "invert the *direction* of the *fill gradient*".
invert_if_negative
python
scanny/python-pptx
src/pptx/chart/series.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/series.py
MIT
def smooth(self): """ Read/write boolean specifying whether to use curve smoothing to form the line connecting the data points in this series into a continuous curve. If |False|, a series of straight line segments are used to connect the points. """ smooth = self._element.smooth if smooth is None: return True return smooth.val
Read/write boolean specifying whether to use curve smoothing to form the line connecting the data points in this series into a continuous curve. If |False|, a series of straight line segments are used to connect the points.
smooth
python
scanny/python-pptx
src/pptx/chart/series.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/series.py
MIT
def iter_values(self): """ Generate each float Y value in this series, in the order they appear on the chart. A value of `None` represents a missing Y value (corresponding to a blank Excel cell). """ yVal = self._element.yVal if yVal is None: return for idx in range(yVal.ptCount_val): yield yVal.pt_v(idx)
Generate each float Y value in this series, in the order they appear on the chart. A value of `None` represents a missing Y value (corresponding to a blank Excel cell).
iter_values
python
scanny/python-pptx
src/pptx/chart/series.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/series.py
MIT
def _SeriesFactory(ser): """ Return an instance of the appropriate subclass of _BaseSeries based on the xChart element *ser* appears in. """ xChart_tag = ser.getparent().tag try: SeriesCls = { qn("c:areaChart"): AreaSeries, qn("c:barChart"): BarSeries, qn("c:bubbleChart"): BubbleSeries, qn("c:doughnutChart"): PieSeries, qn("c:lineChart"): LineSeries, qn("c:pieChart"): PieSeries, qn("c:radarChart"): RadarSeries, qn("c:scatterChart"): XySeries, }[xChart_tag] except KeyError: raise NotImplementedError("series class for %s not yet implemented" % xChart_tag) return SeriesCls(ser)
Return an instance of the appropriate subclass of _BaseSeries based on the xChart element *ser* appears in.
_SeriesFactory
python
scanny/python-pptx
src/pptx/chart/series.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/series.py
MIT
def _open_worksheet(self, xlsx_file): """ Enable XlsxWriter Worksheet object to be opened, operated on, and then automatically closed within a `with` statement. A filename or stream object (such as an `io.BytesIO` instance) is expected as *xlsx_file*. """ workbook = Workbook(xlsx_file, {"in_memory": True}) worksheet = workbook.add_worksheet() yield workbook, worksheet workbook.close()
Enable XlsxWriter Worksheet object to be opened, operated on, and then automatically closed within a `with` statement. A filename or stream object (such as an `io.BytesIO` instance) is expected as *xlsx_file*.
_open_worksheet
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def categories_ref(self): """ The Excel worksheet reference to the categories for this chart (not including the column heading). """ categories = self._chart_data.categories if categories.depth == 0: raise ValueError("chart data contains no categories") right_col = chr(ord("A") + categories.depth - 1) bottom_row = categories.leaf_count + 1 return "Sheet1!$A$2:$%s$%d" % (right_col, bottom_row)
The Excel worksheet reference to the categories for this chart (not including the column heading).
categories_ref
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def values_ref(self, series): """ The Excel worksheet reference to the values for this series (not including the column heading). """ return "Sheet1!${col_letter}$2:${col_letter}${bottom_row}".format( **{ "col_letter": self._series_col_letter(series), "bottom_row": len(series) + 1, } )
The Excel worksheet reference to the values for this series (not including the column heading).
values_ref
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def _column_reference(column_number): """Return str Excel column reference like 'BQ' for *column_number*. *column_number* is an int in the range 1-16384 inclusive, where 1 maps to column 'A'. """ if column_number < 1 or column_number > 16384: raise ValueError("column_number must be in range 1-16384") # ---Work right-to-left, one order of magnitude at a time. Note there # is no zero representation in Excel address scheme, so this is # not just a conversion to base-26--- col_ref = "" while column_number: remainder = column_number % 26 if remainder == 0: remainder = 26 col_letter = chr(ord("A") + remainder - 1) col_ref = col_letter + col_ref # ---Advance to next order of magnitude or terminate loop. The # minus-one in this expression reflects the fact the next lower # order of magnitude has a minumum value of 1 (not zero). This is # essentially the complement to the "if it's 0 make it 26' step # above.--- column_number = (column_number - 1) // 26 return col_ref
Return str Excel column reference like 'BQ' for *column_number*. *column_number* is an int in the range 1-16384 inclusive, where 1 maps to column 'A'.
_column_reference
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def _write_categories(self, workbook, worksheet): """ Write the categories column(s) to *worksheet*. Categories start in the first column starting in the second row, and proceeding one column per category level (for charts having multi-level categories). A date category is formatted as a date. All others are formatted `General`. """ categories = self._chart_data.categories num_format = workbook.add_format({"num_format": categories.number_format}) depth = categories.depth for idx, level in enumerate(categories.levels): col = depth - idx - 1 self._write_cat_column(worksheet, col, level, num_format)
Write the categories column(s) to *worksheet*. Categories start in the first column starting in the second row, and proceeding one column per category level (for charts having multi-level categories). A date category is formatted as a date. All others are formatted `General`.
_write_categories
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def _write_cat_column(self, worksheet, col, level, num_format): """ Write a category column defined by *level* to *worksheet* at offset *col* and formatted with *num_format*. """ worksheet.set_column(col, col, 10) # wide enough for a date for off, name in level: row = off + 1 worksheet.write(row, col, name, num_format)
Write a category column defined by *level* to *worksheet* at offset *col* and formatted with *num_format*.
_write_cat_column
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def _write_series(self, workbook, worksheet): """ Write the series column(s) to *worksheet*. Series start in the column following the last categories column, placing the series title in the first cell. """ col_offset = self._chart_data.categories.depth for idx, series in enumerate(self._chart_data): num_format = workbook.add_format({"num_format": series.number_format}) series_col = idx + col_offset worksheet.write(0, series_col, series.name) worksheet.write_column(1, series_col, series.values, num_format)
Write the series column(s) to *worksheet*. Series start in the column following the last categories column, placing the series title in the first cell.
_write_series
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def series_name_ref(self, series): """ Return the Excel worksheet reference to the cell containing the name for *series*. This also serves as the column heading for the series Y values. """ row = self.series_table_row_offset(series) + 1 return "Sheet1!$B$%d" % row
Return the Excel worksheet reference to the cell containing the name for *series*. This also serves as the column heading for the series Y values.
series_name_ref
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def series_table_row_offset(self, series): """ Return the number of rows preceding the data table for *series* in the Excel worksheet. """ title_and_spacer_rows = series.index * 2 data_point_rows = series.data_point_offset return title_and_spacer_rows + data_point_rows
Return the number of rows preceding the data table for *series* in the Excel worksheet.
series_table_row_offset
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def x_values_ref(self, series): """ The Excel worksheet reference to the X values for this chart (not including the column label). """ top_row = self.series_table_row_offset(series) + 2 bottom_row = top_row + len(series) - 1 return "Sheet1!$A$%d:$A$%d" % (top_row, bottom_row)
The Excel worksheet reference to the X values for this chart (not including the column label).
x_values_ref
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def y_values_ref(self, series): """ The Excel worksheet reference to the Y values for this chart (not including the column label). """ top_row = self.series_table_row_offset(series) + 2 bottom_row = top_row + len(series) - 1 return "Sheet1!$B$%d:$B$%d" % (top_row, bottom_row)
The Excel worksheet reference to the Y values for this chart (not including the column label).
y_values_ref
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def _populate_worksheet(self, workbook, worksheet): """ Write chart data contents to *worksheet* in the standard XY chart layout. Write the data for each series to a separate two-column table, X values in column A and Y values in column B. Place the series label in the first (heading) cell of the column. """ chart_num_format = workbook.add_format({"num_format": self._chart_data.number_format}) for series in self._chart_data: series_num_format = workbook.add_format({"num_format": series.number_format}) offset = self.series_table_row_offset(series) # write X values worksheet.write_column(offset + 1, 0, series.x_values, chart_num_format) # write Y values worksheet.write(offset, 1, series.name) worksheet.write_column(offset + 1, 1, series.y_values, series_num_format)
Write chart data contents to *worksheet* in the standard XY chart layout. Write the data for each series to a separate two-column table, X values in column A and Y values in column B. Place the series label in the first (heading) cell of the column.
_populate_worksheet
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def bubble_sizes_ref(self, series): """ The Excel worksheet reference to the range containing the bubble sizes for *series* (not including the column heading cell). """ top_row = self.series_table_row_offset(series) + 2 bottom_row = top_row + len(series) - 1 return "Sheet1!$C$%d:$C$%d" % (top_row, bottom_row)
The Excel worksheet reference to the range containing the bubble sizes for *series* (not including the column heading cell).
bubble_sizes_ref
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def _populate_worksheet(self, workbook, worksheet): """ Write chart data contents to *worksheet* in the bubble chart layout. Write the data for each series to a separate three-column table with X values in column A, Y values in column B, and bubble sizes in column C. Place the series label in the first (heading) cell of the values column. """ chart_num_format = workbook.add_format({"num_format": self._chart_data.number_format}) for series in self._chart_data: series_num_format = workbook.add_format({"num_format": series.number_format}) offset = self.series_table_row_offset(series) # write X values worksheet.write_column(offset + 1, 0, series.x_values, chart_num_format) # write Y values worksheet.write(offset, 1, series.name) worksheet.write_column(offset + 1, 1, series.y_values, series_num_format) # write bubble sizes worksheet.write(offset, 2, "Size") worksheet.write_column(offset + 1, 2, series.bubble_sizes, chart_num_format)
Write chart data contents to *worksheet* in the bubble chart layout. Write the data for each series to a separate three-column table with X values in column A, Y values in column B, and bubble sizes in column C. Place the series label in the first (heading) cell of the values column.
_populate_worksheet
python
scanny/python-pptx
src/pptx/chart/xlsx.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xlsx.py
MIT
def ChartXmlWriter(chart_type, chart_data): """ Factory function returning appropriate XML writer object for *chart_type*, loaded with *chart_type* and *chart_data*. """ XL_CT = XL_CHART_TYPE try: BuilderCls = { XL_CT.AREA: _AreaChartXmlWriter, XL_CT.AREA_STACKED: _AreaChartXmlWriter, XL_CT.AREA_STACKED_100: _AreaChartXmlWriter, XL_CT.BAR_CLUSTERED: _BarChartXmlWriter, XL_CT.BAR_STACKED: _BarChartXmlWriter, XL_CT.BAR_STACKED_100: _BarChartXmlWriter, XL_CT.BUBBLE: _BubbleChartXmlWriter, XL_CT.BUBBLE_THREE_D_EFFECT: _BubbleChartXmlWriter, XL_CT.COLUMN_CLUSTERED: _BarChartXmlWriter, XL_CT.COLUMN_STACKED: _BarChartXmlWriter, XL_CT.COLUMN_STACKED_100: _BarChartXmlWriter, XL_CT.DOUGHNUT: _DoughnutChartXmlWriter, XL_CT.DOUGHNUT_EXPLODED: _DoughnutChartXmlWriter, XL_CT.LINE: _LineChartXmlWriter, XL_CT.LINE_MARKERS: _LineChartXmlWriter, XL_CT.LINE_MARKERS_STACKED: _LineChartXmlWriter, XL_CT.LINE_MARKERS_STACKED_100: _LineChartXmlWriter, XL_CT.LINE_STACKED: _LineChartXmlWriter, XL_CT.LINE_STACKED_100: _LineChartXmlWriter, XL_CT.PIE: _PieChartXmlWriter, XL_CT.PIE_EXPLODED: _PieChartXmlWriter, XL_CT.RADAR: _RadarChartXmlWriter, XL_CT.RADAR_FILLED: _RadarChartXmlWriter, XL_CT.RADAR_MARKERS: _RadarChartXmlWriter, XL_CT.XY_SCATTER: _XyChartXmlWriter, XL_CT.XY_SCATTER_LINES: _XyChartXmlWriter, XL_CT.XY_SCATTER_LINES_NO_MARKERS: _XyChartXmlWriter, XL_CT.XY_SCATTER_SMOOTH: _XyChartXmlWriter, XL_CT.XY_SCATTER_SMOOTH_NO_MARKERS: _XyChartXmlWriter, }[chart_type] except KeyError: raise NotImplementedError("XML writer for chart type %s not yet implemented" % chart_type) return BuilderCls(chart_type, chart_data)
Factory function returning appropriate XML writer object for *chart_type*, loaded with *chart_type* and *chart_data*.
ChartXmlWriter
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def numRef_xml(self, wksht_ref, number_format, values): """ Return the ``<c:numRef>`` element specified by the parameters as unicode text. """ pt_xml = self.pt_xml(values) return ( " <c:numRef>\n" " <c:f>{wksht_ref}</c:f>\n" " <c:numCache>\n" " <c:formatCode>{number_format}</c:formatCode>\n" "{pt_xml}" " </c:numCache>\n" " </c:numRef>\n" ).format(**{"wksht_ref": wksht_ref, "number_format": number_format, "pt_xml": pt_xml})
Return the ``<c:numRef>`` element specified by the parameters as unicode text.
numRef_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def pt_xml(self, values): """ Return the ``<c:ptCount>`` and sequence of ``<c:pt>`` elements corresponding to *values* as a single unicode text string. `c:ptCount` refers to the number of `c:pt` elements in this sequence. The `idx` attribute value for `c:pt` elements locates the data point in the overall data point sequence of the chart and is started at *offset*. """ xml = (' <c:ptCount val="{pt_count}"/>\n').format(pt_count=len(values)) pt_tmpl = ( ' <c:pt idx="{idx}">\n' " <c:v>{value}</c:v>\n" " </c:pt>\n" ) for idx, value in enumerate(values): if value is None: continue xml += pt_tmpl.format(idx=idx, value=value) return xml
Return the ``<c:ptCount>`` and sequence of ``<c:pt>`` elements corresponding to *values* as a single unicode text string. `c:ptCount` refers to the number of `c:pt` elements in this sequence. The `idx` attribute value for `c:pt` elements locates the data point in the overall data point sequence of the chart and is started at *offset*.
pt_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def tx(self): """ Return a ``<c:tx>`` oxml element for this series, containing the series name. """ xml = self._tx_tmpl.format( **{ "wksht_ref": self._series.name_ref, "series_name": self.name, "nsdecls": " %s" % nsdecls("c"), } ) return parse_xml(xml)
Return a ``<c:tx>`` oxml element for this series, containing the series name.
tx
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def tx_xml(self): """ Return the ``<c:tx>`` (tx is short for 'text') element for this series as unicode text. This element contains the series name. """ return self._tx_tmpl.format( **{ "wksht_ref": self._series.name_ref, "series_name": self.name, "nsdecls": "", } )
Return the ``<c:tx>`` (tx is short for 'text') element for this series as unicode text. This element contains the series name.
tx_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _tx_tmpl(self): """ The string formatting template for the ``<c:tx>`` element for this series, containing the series title and spreadsheet range reference. """ return ( " <c:tx{nsdecls}>\n" " <c:strRef>\n" " <c:f>{wksht_ref}</c:f>\n" " <c:strCache>\n" ' <c:ptCount val="1"/>\n' ' <c:pt idx="0">\n' " <c:v>{series_name}</c:v>\n" " </c:pt>\n" " </c:strCache>\n" " </c:strRef>\n" " </c:tx>\n" )
The string formatting template for the ``<c:tx>`` element for this series, containing the series title and spreadsheet range reference.
_tx_tmpl
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def replace_series_data(self, chartSpace): """ Rewrite the series data under *chartSpace* using the chart data contents. All series-level formatting is left undisturbed. If the chart data contains fewer series than *chartSpace*, the extra series in *chartSpace* are deleted. If *chart_data* contains more series than the *chartSpace* element, new series are added to the last plot in the chart and series formatting is "cloned" from the last series in that plot. """ plotArea, date_1904 = chartSpace.plotArea, chartSpace.date_1904 chart_data = self._chart_data self._adjust_ser_count(plotArea, len(chart_data)) for ser, series_data in zip(plotArea.sers, chart_data): self._rewrite_ser_data(ser, series_data, date_1904)
Rewrite the series data under *chartSpace* using the chart data contents. All series-level formatting is left undisturbed. If the chart data contains fewer series than *chartSpace*, the extra series in *chartSpace* are deleted. If *chart_data* contains more series than the *chartSpace* element, new series are added to the last plot in the chart and series formatting is "cloned" from the last series in that plot.
replace_series_data
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _add_cloned_sers(self, plotArea, count): """ Add `c:ser` elements to the last xChart element in *plotArea*, cloned from the last `c:ser` child of that last xChart. """ def clone_ser(ser): new_ser = deepcopy(ser) new_ser.idx.val = plotArea.next_idx new_ser.order.val = plotArea.next_order ser.addnext(new_ser) return new_ser last_ser = plotArea.last_ser for _ in range(count): last_ser = clone_ser(last_ser)
Add `c:ser` elements to the last xChart element in *plotArea*, cloned from the last `c:ser` child of that last xChart.
_add_cloned_sers
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _adjust_ser_count(self, plotArea, new_ser_count): """ Adjust the number of c:ser elements in *plotArea* to *new_ser_count*. Excess c:ser elements are deleted from the end, along with any xChart elements that are left empty as a result. Series elements are considered in xChart + series order. Any new c:ser elements required are added to the last xChart element and cloned from the last c:ser element in that xChart. """ ser_count_diff = new_ser_count - len(plotArea.sers) if ser_count_diff > 0: self._add_cloned_sers(plotArea, ser_count_diff) elif ser_count_diff < 0: self._trim_ser_count_by(plotArea, abs(ser_count_diff))
Adjust the number of c:ser elements in *plotArea* to *new_ser_count*. Excess c:ser elements are deleted from the end, along with any xChart elements that are left empty as a result. Series elements are considered in xChart + series order. Any new c:ser elements required are added to the last xChart element and cloned from the last c:ser element in that xChart.
_adjust_ser_count
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _trim_ser_count_by(self, plotArea, count): """ Remove the last *count* ser elements from *plotArea*. Any xChart elements having no ser child elements after trimming are also removed. """ extra_sers = plotArea.sers[-count:] for ser in extra_sers: parent = ser.getparent() parent.remove(ser) extra_xCharts = [xChart for xChart in plotArea.iter_xCharts() if len(xChart.sers) == 0] for xChart in extra_xCharts: parent = xChart.getparent() parent.remove(xChart)
Remove the last *count* ser elements from *plotArea*. Any xChart elements having no ser child elements after trimming are also removed.
_trim_ser_count_by
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def cat(self): """ Return the ``<c:cat>`` element XML for this series, as an oxml element. """ categories = self._series.categories if categories.are_numeric: return parse_xml( self._numRef_cat_tmpl.format( **{ "wksht_ref": self._series.categories_ref, "number_format": categories.number_format, "cat_count": categories.leaf_count, "cat_pt_xml": self._cat_num_pt_xml, "nsdecls": " %s" % nsdecls("c"), } ) ) if categories.depth == 1: return parse_xml( self._cat_tmpl.format( **{ "wksht_ref": self._series.categories_ref, "cat_count": categories.leaf_count, "cat_pt_xml": self._cat_pt_xml, "nsdecls": " %s" % nsdecls("c"), } ) ) return parse_xml( self._multiLvl_cat_tmpl.format( **{ "wksht_ref": self._series.categories_ref, "cat_count": categories.leaf_count, "lvl_xml": self._lvl_xml(categories), "nsdecls": " %s" % nsdecls("c"), } ) )
Return the ``<c:cat>`` element XML for this series, as an oxml element.
cat
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def cat_xml(self): """ The unicode XML snippet for the ``<c:cat>`` element for this series, containing the category labels and spreadsheet reference. """ categories = self._series.categories if categories.are_numeric: return self._numRef_cat_tmpl.format( **{ "wksht_ref": self._series.categories_ref, "number_format": categories.number_format, "cat_count": categories.leaf_count, "cat_pt_xml": self._cat_num_pt_xml, "nsdecls": "", } ) if categories.depth == 1: return self._cat_tmpl.format( **{ "wksht_ref": self._series.categories_ref, "cat_count": categories.leaf_count, "cat_pt_xml": self._cat_pt_xml, "nsdecls": "", } ) return self._multiLvl_cat_tmpl.format( **{ "wksht_ref": self._series.categories_ref, "cat_count": categories.leaf_count, "lvl_xml": self._lvl_xml(categories), "nsdecls": "", } )
The unicode XML snippet for the ``<c:cat>`` element for this series, containing the category labels and spreadsheet reference.
cat_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def val(self): """ The ``<c:val>`` XML for this series, as an oxml element. """ xml = self._val_tmpl.format( **{ "nsdecls": " %s" % nsdecls("c"), "values_ref": self._series.values_ref, "number_format": self._series.number_format, "val_count": len(self._series), "val_pt_xml": self._val_pt_xml, } ) return parse_xml(xml)
The ``<c:val>`` XML for this series, as an oxml element.
val
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def val_xml(self): """ Return the unicode XML snippet for the ``<c:val>`` element describing this series, containing the series values and their spreadsheet range reference. """ return self._val_tmpl.format( **{ "nsdecls": "", "values_ref": self._series.values_ref, "number_format": self._series.number_format, "val_count": len(self._series), "val_pt_xml": self._val_pt_xml, } )
Return the unicode XML snippet for the ``<c:val>`` element describing this series, containing the series values and their spreadsheet range reference.
val_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _cat_num_pt_xml(self): """ The unicode XML snippet for the ``<c:pt>`` elements when category labels are numeric (including date type). """ xml = "" for idx, category in enumerate(self._series.categories): xml += ( ' <c:pt idx="{cat_idx}">\n' " <c:v>{cat_lbl_str}</c:v>\n" " </c:pt>\n" ).format( **{ "cat_idx": idx, "cat_lbl_str": category.numeric_str_val(self._date_1904), } ) return xml
The unicode XML snippet for the ``<c:pt>`` elements when category labels are numeric (including date type).
_cat_num_pt_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _cat_pt_xml(self): """ The unicode XML snippet for the ``<c:pt>`` elements containing the category names for this series. """ xml = "" for idx, category in enumerate(self._series.categories): xml += ( ' <c:pt idx="{cat_idx}">\n' " <c:v>{cat_label}</c:v>\n" " </c:pt>\n" ).format(**{"cat_idx": idx, "cat_label": escape(str(category.label))}) return xml
The unicode XML snippet for the ``<c:pt>`` elements containing the category names for this series.
_cat_pt_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _cat_tmpl(self): """ The template for the ``<c:cat>`` element for this series, containing the category labels and spreadsheet reference. """ return ( " <c:cat{nsdecls}>\n" " <c:strRef>\n" " <c:f>{wksht_ref}</c:f>\n" " <c:strCache>\n" ' <c:ptCount val="{cat_count}"/>\n' "{cat_pt_xml}" " </c:strCache>\n" " </c:strRef>\n" " </c:cat>\n" )
The template for the ``<c:cat>`` element for this series, containing the category labels and spreadsheet reference.
_cat_tmpl
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _lvl_xml(self, categories): """ The unicode XML snippet for the ``<c:lvl>`` elements containing multi-level category names. """ def lvl_pt_xml(level): xml = "" for idx, name in level: xml += ( ' <c:pt idx="%d">\n' " <c:v>%s</c:v>\n" " </c:pt>\n" ) % (idx, escape("%s" % name)) return xml xml = "" for level in categories.levels: xml += (" <c:lvl>\n" "{lvl_pt_xml}" " </c:lvl>\n").format( **{"lvl_pt_xml": lvl_pt_xml(level)} ) return xml
The unicode XML snippet for the ``<c:lvl>`` elements containing multi-level category names.
_lvl_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _multiLvl_cat_tmpl(self): """ The template for the ``<c:cat>`` element for this series when there are multi-level (nested) categories. """ return ( " <c:cat{nsdecls}>\n" " <c:multiLvlStrRef>\n" " <c:f>{wksht_ref}</c:f>\n" " <c:multiLvlStrCache>\n" ' <c:ptCount val="{cat_count}"/>\n' "{lvl_xml}" " </c:multiLvlStrCache>\n" " </c:multiLvlStrRef>\n" " </c:cat>\n" )
The template for the ``<c:cat>`` element for this series when there are multi-level (nested) categories.
_multiLvl_cat_tmpl
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _numRef_cat_tmpl(self): """ The template for the ``<c:cat>`` element for this series when the labels are numeric (or date) values. """ return ( " <c:cat{nsdecls}>\n" " <c:numRef>\n" " <c:f>{wksht_ref}</c:f>\n" " <c:numCache>\n" " <c:formatCode>{number_format}</c:formatCode>\n" ' <c:ptCount val="{cat_count}"/>\n' "{cat_pt_xml}" " </c:numCache>\n" " </c:numRef>\n" " </c:cat>\n" )
The template for the ``<c:cat>`` element for this series when the labels are numeric (or date) values.
_numRef_cat_tmpl
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _val_pt_xml(self): """ The unicode XML snippet containing the ``<c:pt>`` elements containing the values for this series. """ xml = "" for idx, value in enumerate(self._series.values): if value is None: continue xml += ( ' <c:pt idx="{val_idx:d}">\n' " <c:v>{value}</c:v>\n" " </c:pt>\n" ).format(**{"val_idx": idx, "value": value}) return xml
The unicode XML snippet containing the ``<c:pt>`` elements containing the values for this series.
_val_pt_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _val_tmpl(self): """ The template for the ``<c:val>`` element for this series, containing the series values and their spreadsheet range reference. """ return ( " <c:val{nsdecls}>\n" " <c:numRef>\n" " <c:f>{values_ref}</c:f>\n" " <c:numCache>\n" " <c:formatCode>{number_format}</c:formatCode>\n" ' <c:ptCount val="{val_count}"/>\n' "{val_pt_xml}" " </c:numCache>\n" " </c:numRef>\n" " </c:val>\n" )
The template for the ``<c:val>`` element for this series, containing the series values and their spreadsheet range reference.
_val_tmpl
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def xVal(self): """ Return the ``<c:xVal>`` element for this series as an oxml element. This element contains the X values for this series. """ xml = self._xVal_tmpl.format( **{ "nsdecls": " %s" % nsdecls("c"), "numRef_xml": self.numRef_xml( self._series.x_values_ref, self._series.number_format, self._series.x_values, ), } ) return parse_xml(xml)
Return the ``<c:xVal>`` element for this series as an oxml element. This element contains the X values for this series.
xVal
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def xVal_xml(self): """ Return the ``<c:xVal>`` element for this series as unicode text. This element contains the X values for this series. """ return self._xVal_tmpl.format( **{ "nsdecls": "", "numRef_xml": self.numRef_xml( self._series.x_values_ref, self._series.number_format, self._series.x_values, ), } )
Return the ``<c:xVal>`` element for this series as unicode text. This element contains the X values for this series.
xVal_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def yVal(self): """ Return the ``<c:yVal>`` element for this series as an oxml element. This element contains the Y values for this series. """ xml = self._yVal_tmpl.format( **{ "nsdecls": " %s" % nsdecls("c"), "numRef_xml": self.numRef_xml( self._series.y_values_ref, self._series.number_format, self._series.y_values, ), } ) return parse_xml(xml)
Return the ``<c:yVal>`` element for this series as an oxml element. This element contains the Y values for this series.
yVal
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def yVal_xml(self): """ Return the ``<c:yVal>`` element for this series as unicode text. This element contains the Y values for this series. """ return self._yVal_tmpl.format( **{ "nsdecls": "", "numRef_xml": self.numRef_xml( self._series.y_values_ref, self._series.number_format, self._series.y_values, ), } )
Return the ``<c:yVal>`` element for this series as unicode text. This element contains the Y values for this series.
yVal_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def bubbleSize(self): """ Return the ``<c:bubbleSize>`` element for this series as an oxml element. This element contains the bubble size values for this series. """ xml = self._bubbleSize_tmpl.format( **{ "nsdecls": " %s" % nsdecls("c"), "numRef_xml": self.numRef_xml( self._series.bubble_sizes_ref, self._series.number_format, self._series.bubble_sizes, ), } ) return parse_xml(xml)
Return the ``<c:bubbleSize>`` element for this series as an oxml element. This element contains the bubble size values for this series.
bubbleSize
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def bubbleSize_xml(self): """ Return the ``<c:bubbleSize>`` element for this series as unicode text. This element contains the bubble size values for all the data points in the chart. """ return self._bubbleSize_tmpl.format( **{ "nsdecls": "", "numRef_xml": self.numRef_xml( self._series.bubble_sizes_ref, self._series.number_format, self._series.bubble_sizes, ), } )
Return the ``<c:bubbleSize>`` element for this series as unicode text. This element contains the bubble size values for all the data points in the chart.
bubbleSize_xml
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _rewrite_ser_data(self, ser, series_data, date_1904): """ Rewrite the ``<c:tx>``, ``<c:cat>`` and ``<c:val>`` child elements of *ser* based on the values in *series_data*. """ ser._remove_tx() ser._remove_xVal() ser._remove_yVal() ser._remove_bubbleSize() xml_writer = _BubbleSeriesXmlWriter(series_data) ser._insert_tx(xml_writer.tx) ser._insert_xVal(xml_writer.xVal) ser._insert_yVal(xml_writer.yVal) ser._insert_bubbleSize(xml_writer.bubbleSize)
Rewrite the ``<c:tx>``, ``<c:cat>`` and ``<c:val>`` child elements of *ser* based on the values in *series_data*.
_rewrite_ser_data
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _rewrite_ser_data(self, ser, series_data, date_1904): """ Rewrite the ``<c:tx>``, ``<c:cat>`` and ``<c:val>`` child elements of *ser* based on the values in *series_data*. """ ser._remove_tx() ser._remove_cat() ser._remove_val() xml_writer = _CategorySeriesXmlWriter(series_data, date_1904) ser._insert_tx(xml_writer.tx) ser._insert_cat(xml_writer.cat) ser._insert_val(xml_writer.val)
Rewrite the ``<c:tx>``, ``<c:cat>`` and ``<c:val>`` child elements of *ser* based on the values in *series_data*.
_rewrite_ser_data
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def _rewrite_ser_data(self, ser, series_data, date_1904): """ Rewrite the ``<c:tx>``, ``<c:xVal>`` and ``<c:yVal>`` child elements of *ser* based on the values in *series_data*. """ ser._remove_tx() ser._remove_xVal() ser._remove_yVal() xml_writer = _XySeriesXmlWriter(series_data) ser._insert_tx(xml_writer.tx) ser._insert_xVal(xml_writer.xVal) ser._insert_yVal(xml_writer.yVal)
Rewrite the ``<c:tx>``, ``<c:xVal>`` and ``<c:yVal>`` child elements of *ser* based on the values in *series_data*.
_rewrite_ser_data
python
scanny/python-pptx
src/pptx/chart/xmlwriter.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/chart/xmlwriter.py
MIT
def rgb(self): """ Raises TypeError on access unless overridden by subclass. """ tmpl = "no .rgb property on color type '%s'" raise AttributeError(tmpl % self.__class__.__name__)
Raises TypeError on access unless overridden by subclass.
rgb
python
scanny/python-pptx
src/pptx/dml/color.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/color.py
MIT
def theme_color(self): """ Raise TypeError on attempt to access .theme_color when no color choice is present. """ tmpl = "no .theme_color property on color type '%s'" raise AttributeError(tmpl % self.__class__.__name__)
Raise TypeError on attempt to access .theme_color when no color choice is present.
theme_color
python
scanny/python-pptx
src/pptx/dml/color.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/color.py
MIT
def from_string(cls, rgb_hex_str): """ Return a new instance from an RGB color hex string like ``'3C2F80'``. """ r = int(rgb_hex_str[:2], 16) g = int(rgb_hex_str[2:4], 16) b = int(rgb_hex_str[4:], 16) return cls(r, g, b)
Return a new instance from an RGB color hex string like ``'3C2F80'``.
from_string
python
scanny/python-pptx
src/pptx/dml/color.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/color.py
MIT
def inherit(self): """True if shape inherits shadow settings. Read/write. An explicitly-defined shadow setting on a shape causes this property to return |False|. A shape with no explicitly-defined shadow setting inherits its shadow settings from the style hierarchy (and so returns |True|). Assigning |True| causes any explicitly-defined shadow setting to be removed and inheritance is restored. Note this has the side-effect of removing **all** explicitly-defined effects, such as glow and reflection, and restoring inheritance for all effects on the shape. Assigning |False| causes the inheritance link to be broken and **no** effects to appear on the shape. """ if self._element.effectLst is None: return True return False
True if shape inherits shadow settings. Read/write. An explicitly-defined shadow setting on a shape causes this property to return |False|. A shape with no explicitly-defined shadow setting inherits its shadow settings from the style hierarchy (and so returns |True|). Assigning |True| causes any explicitly-defined shadow setting to be removed and inheritance is restored. Note this has the side-effect of removing **all** explicitly-defined effects, such as glow and reflection, and restoring inheritance for all effects on the shape. Assigning |False| causes the inheritance link to be broken and **no** effects to appear on the shape.
inherit
python
scanny/python-pptx
src/pptx/dml/effect.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/effect.py
MIT
def from_fill_parent(cls, eg_fillProperties_parent: BaseOxmlElement) -> FillFormat: """ Return a |FillFormat| instance initialized to the settings contained in *eg_fillProperties_parent*, which must be an element having EG_FillProperties in its child element sequence in the XML schema. """ fill_elm = eg_fillProperties_parent.eg_fillProperties fill = _Fill(fill_elm) fill_format = cls(eg_fillProperties_parent, fill) return fill_format
Return a |FillFormat| instance initialized to the settings contained in *eg_fillProperties_parent*, which must be an element having EG_FillProperties in its child element sequence in the XML schema.
from_fill_parent
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def background(self): """ Sets the fill type to noFill, i.e. transparent. """ noFill = self._xPr.get_or_change_to_noFill() self._fill = _NoFill(noFill)
Sets the fill type to noFill, i.e. transparent.
background
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def gradient(self): """Sets the fill type to gradient. If the fill is not already a gradient, a default gradient is added. The default gradient corresponds to the default in the built-in PowerPoint "White" template. This gradient is linear at angle 90-degrees (upward), with two stops. The first stop is Accent-1 with tint 100%, shade 100%, and satMod 130%. The second stop is Accent-1 with tint 50%, shade 100%, and satMod 350%. """ gradFill = self._xPr.get_or_change_to_gradFill() self._fill = _GradFill(gradFill)
Sets the fill type to gradient. If the fill is not already a gradient, a default gradient is added. The default gradient corresponds to the default in the built-in PowerPoint "White" template. This gradient is linear at angle 90-degrees (upward), with two stops. The first stop is Accent-1 with tint 100%, shade 100%, and satMod 130%. The second stop is Accent-1 with tint 50%, shade 100%, and satMod 350%.
gradient
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def gradient_angle(self): """Angle in float degrees of line of a linear gradient. Read/Write. May be |None|, indicating the angle should be inherited from the style hierarchy. An angle of 0.0 corresponds to a left-to-right gradient. Increasing angles represent counter-clockwise rotation of the line, for example 90.0 represents a bottom-to-top gradient. Raises |TypeError| when the fill type is not MSO_FILL_TYPE.GRADIENT. Raises |ValueError| for a non-linear gradient (e.g. a radial gradient). """ if self.type != MSO_FILL.GRADIENT: raise TypeError("Fill is not of type MSO_FILL_TYPE.GRADIENT") return self._fill.gradient_angle
Angle in float degrees of line of a linear gradient. Read/Write. May be |None|, indicating the angle should be inherited from the style hierarchy. An angle of 0.0 corresponds to a left-to-right gradient. Increasing angles represent counter-clockwise rotation of the line, for example 90.0 represents a bottom-to-top gradient. Raises |TypeError| when the fill type is not MSO_FILL_TYPE.GRADIENT. Raises |ValueError| for a non-linear gradient (e.g. a radial gradient).
gradient_angle
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def gradient_stops(self): """|GradientStops| object providing access to stops of this gradient. Raises |TypeError| when fill is not gradient (call `fill.gradient()` first). Each stop represents a color between which the gradient smoothly transitions. """ if self.type != MSO_FILL.GRADIENT: raise TypeError("Fill is not of type MSO_FILL_TYPE.GRADIENT") return self._fill.gradient_stops
|GradientStops| object providing access to stops of this gradient. Raises |TypeError| when fill is not gradient (call `fill.gradient()` first). Each stop represents a color between which the gradient smoothly transitions.
gradient_stops
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def patterned(self): """Selects the pattern fill type. Note that calling this method does not by itself set a foreground or background color of the pattern. Rather it enables subsequent assignments to properties like fore_color to set the pattern and colors. """ pattFill = self._xPr.get_or_change_to_pattFill() self._fill = _PattFill(pattFill)
Selects the pattern fill type. Note that calling this method does not by itself set a foreground or background color of the pattern. Rather it enables subsequent assignments to properties like fore_color to set the pattern and colors.
patterned
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def solid(self): """ Sets the fill type to solid, i.e. a solid color. Note that calling this method does not set a color or by itself cause the shape to appear with a solid color fill; rather it enables subsequent assignments to properties like fore_color to set the color. """ solidFill = self._xPr.get_or_change_to_solidFill() self._fill = _SolidFill(solidFill)
Sets the fill type to solid, i.e. a solid color. Note that calling this method does not set a color or by itself cause the shape to appear with a solid color fill; rather it enables subsequent assignments to properties like fore_color to set the color.
solid
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def back_color(self): """Raise TypeError for types that do not override this property.""" tmpl = "fill type %s has no background color, call .patterned() first" raise TypeError(tmpl % self.__class__.__name__)
Raise TypeError for types that do not override this property.
back_color
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def fore_color(self): """Raise TypeError for types that do not override this property.""" tmpl = "fill type %s has no foreground color, call .solid() or .pattern" "ed() first" raise TypeError(tmpl % self.__class__.__name__)
Raise TypeError for types that do not override this property.
fore_color
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def pattern(self): """Raise TypeError for fills that do not override this property.""" tmpl = "fill type %s has no pattern, call .patterned() first" raise TypeError(tmpl % self.__class__.__name__)
Raise TypeError for fills that do not override this property.
pattern
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def gradient_angle(self): """Angle in float degrees of line of a linear gradient. Read/Write. May be |None|, indicating the angle is inherited from the style hierarchy. An angle of 0.0 corresponds to a left-to-right gradient. Increasing angles represent clockwise rotation of the line, for example 90.0 represents a top-to-bottom gradient. Raises |TypeError| when the fill type is not MSO_FILL_TYPE.GRADIENT. Raises |ValueError| for a non-linear gradient (e.g. a radial gradient). """ # ---case 1: gradient path is explicit, but not linear--- path = self._gradFill.path if path is not None: raise ValueError("not a linear gradient") # ---case 2: gradient path is inherited (no a:lin OR a:path)--- lin = self._gradFill.lin if lin is None: return None # ---case 3: gradient path is explicitly linear--- # angle is stored in XML as a clockwise angle, whereas the UI # reports it as counter-clockwise from horizontal-pointing-right. # Since the UI is consistent with trigonometry conventions, we # respect that in the API. clockwise_angle = lin.ang counter_clockwise_angle = 0.0 if clockwise_angle == 0.0 else (360.0 - clockwise_angle) return counter_clockwise_angle
Angle in float degrees of line of a linear gradient. Read/Write. May be |None|, indicating the angle is inherited from the style hierarchy. An angle of 0.0 corresponds to a left-to-right gradient. Increasing angles represent clockwise rotation of the line, for example 90.0 represents a top-to-bottom gradient. Raises |TypeError| when the fill type is not MSO_FILL_TYPE.GRADIENT. Raises |ValueError| for a non-linear gradient (e.g. a radial gradient).
gradient_angle
python
scanny/python-pptx
src/pptx/dml/fill.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/fill.py
MIT
def color(self): """ The |ColorFormat| instance that provides access to the color settings for this line. Essentially a shortcut for ``line.fill.fore_color``. As a side-effect, accessing this property causes the line fill type to be set to ``MSO_FILL.SOLID``. If this sounds risky for your use case, use ``line.fill.type`` to non-destructively discover the existing fill type. """ if self.fill.type != MSO_FILL.SOLID: self.fill.solid() return self.fill.fore_color
The |ColorFormat| instance that provides access to the color settings for this line. Essentially a shortcut for ``line.fill.fore_color``. As a side-effect, accessing this property causes the line fill type to be set to ``MSO_FILL.SOLID``. If this sounds risky for your use case, use ``line.fill.type`` to non-destructively discover the existing fill type.
color
python
scanny/python-pptx
src/pptx/dml/line.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/line.py
MIT
def dash_style(self): """Return value indicating line style. Returns a member of :ref:`MsoLineDashStyle` indicating line style, or |None| if no explicit value has been set. When no explicit value has been set, the line dash style is inherited from the style hierarchy. Assigning |None| removes any existing explicitly-defined dash style. """ ln = self._ln if ln is None: return None return ln.prstDash_val
Return value indicating line style. Returns a member of :ref:`MsoLineDashStyle` indicating line style, or |None| if no explicit value has been set. When no explicit value has been set, the line dash style is inherited from the style hierarchy. Assigning |None| removes any existing explicitly-defined dash style.
dash_style
python
scanny/python-pptx
src/pptx/dml/line.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/line.py
MIT
def width(self): """ The width of the line expressed as an integer number of :ref:`English Metric Units <EMU>`. The returned value is an instance of |Length|, a value class having properties such as `.inches`, `.cm`, and `.pt` for converting the value into convenient units. """ ln = self._ln if ln is None: return Emu(0) return ln.w
The width of the line expressed as an integer number of :ref:`English Metric Units <EMU>`. The returned value is an instance of |Length|, a value class having properties such as `.inches`, `.cm`, and `.pt` for converting the value into convenient units.
width
python
scanny/python-pptx
src/pptx/dml/line.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/dml/line.py
MIT
def from_xml(cls, xml_value: str) -> Self: """Enumeration member corresponding to XML attribute value `xml_value`. Raises `ValueError` if `xml_value` is the empty string ("") or is not an XML attribute value registered on the enumeration. Note that enum members that do not correspond to one of the defined values for an XML attribute have `xml_value == ""`. These "return-value only" members cannot be automatically mapped from an XML attribute value and must be selected explicitly by code, based on the appropriate conditions. Example:: >>> WD_PARAGRAPH_ALIGNMENT.from_xml("center") WD_PARAGRAPH_ALIGNMENT.CENTER """ # -- the empty string never maps to a member -- member = ( next((member for member in cls if member.xml_value == xml_value), None) if xml_value else None ) if member is None: raise ValueError(f"{cls.__name__} has no XML mapping for {repr(xml_value)}") return member
Enumeration member corresponding to XML attribute value `xml_value`. Raises `ValueError` if `xml_value` is the empty string ("") or is not an XML attribute value registered on the enumeration. Note that enum members that do not correspond to one of the defined values for an XML attribute have `xml_value == ""`. These "return-value only" members cannot be automatically mapped from an XML attribute value and must be selected explicitly by code, based on the appropriate conditions. Example:: >>> WD_PARAGRAPH_ALIGNMENT.from_xml("center") WD_PARAGRAPH_ALIGNMENT.CENTER
from_xml
python
scanny/python-pptx
src/pptx/enum/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/enum/base.py
MIT
def to_xml(cls: Type[_T], value: int | _T) -> str: """XML value of this enum member, generally an XML attribute value.""" # -- presence of multi-arg `__new__()` method fools type-checker, but getting a # -- member by its value using EnumCls(val) works as usual. member = cls(value) xml_value = member.xml_value if not xml_value: raise ValueError(f"{cls.__name__}.{member.name} has no XML representation") return xml_value
XML value of this enum member, generally an XML attribute value.
to_xml
python
scanny/python-pptx
src/pptx/enum/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/enum/base.py
MIT
def validate(cls: Type[_T], value: _T): """Raise |ValueError| if `value` is not an assignable value.""" if value not in cls: raise ValueError(f"{value} not a member of {cls.__name__} enumeration")
Raise |ValueError| if `value` is not an assignable value.
validate
python
scanny/python-pptx
src/pptx/enum/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/enum/base.py
MIT
def page_str(self): """ The RestructuredText documentation page for the enumeration. This is the only API member for the class. """ tmpl = ".. _%s:\n\n%s\n\n%s\n\n----\n\n%s" components = ( self._ms_name, self._page_title, self._intro_text, self._member_defs, ) return tmpl % components
The RestructuredText documentation page for the enumeration. This is the only API member for the class.
page_str
python
scanny/python-pptx
src/pptx/enum/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/enum/base.py
MIT
def _intro_text(self): """ The docstring of the enumeration, formatted for use at the top of the documentation page """ try: cls_docstring = self._clsdict["__doc__"] except KeyError: cls_docstring = "" if cls_docstring is None: return "" return textwrap.dedent(cls_docstring).strip()
The docstring of the enumeration, formatted for use at the top of the documentation page
_intro_text
python
scanny/python-pptx
src/pptx/enum/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/enum/base.py
MIT
def _member_def(self, member: BaseEnum | BaseXmlEnum): """Return an individual member definition formatted as an RST glossary entry. Output is wrapped to fit within 78 columns. """ member_docstring = textwrap.dedent(member.__doc__ or "").strip() member_docstring = textwrap.fill( member_docstring, width=78, initial_indent=" " * 4, subsequent_indent=" " * 4, ) return "%s\n%s\n" % (member.name, member_docstring)
Return an individual member definition formatted as an RST glossary entry. Output is wrapped to fit within 78 columns.
_member_def
python
scanny/python-pptx
src/pptx/enum/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/enum/base.py
MIT
def _member_defs(self): """ A single string containing the aggregated member definitions section of the documentation page """ members = self._clsdict["__members__"] member_defs = [self._member_def(member) for member in members if member.name is not None] return "\n".join(member_defs)
A single string containing the aggregated member definitions section of the documentation page
_member_defs
python
scanny/python-pptx
src/pptx/enum/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/enum/base.py
MIT
def _page_title(self): """ The title for the documentation page, formatted as code (surrounded in double-backtics) and underlined with '=' characters """ title_underscore = "=" * (len(self._clsname) + 4) return "``%s``\n%s" % (self._clsname, title_underscore)
The title for the documentation page, formatted as code (surrounded in double-backtics) and underlined with '=' characters
_page_title
python
scanny/python-pptx
src/pptx/enum/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/enum/base.py
MIT
def new( cls, rId: str, reltype: str, target_ref: str, target_mode: str = RTM.INTERNAL ) -> CT_Relationship: """Return a new `<Relationship>` element. `target_ref` is either a partname or a URI. """ relationship = cast(CT_Relationship, parse_xml(f'<Relationship xmlns="{nsmap["pr"]}"/>')) relationship.rId = rId relationship.reltype = reltype relationship.target_ref = target_ref relationship.targetMode = target_mode return relationship
Return a new `<Relationship>` element. `target_ref` is either a partname or a URI.
new
python
scanny/python-pptx
src/pptx/opc/oxml.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/oxml.py
MIT
def add_rel( self, rId: str, reltype: str, target: str, is_external: bool = False ) -> CT_Relationship: """Add a child `<Relationship>` element with attributes set as specified.""" target_mode = RTM.EXTERNAL if is_external else RTM.INTERNAL relationship = CT_Relationship.new(rId, reltype, target, target_mode) return self._insert_relationship(relationship)
Add a child `<Relationship>` element with attributes set as specified.
add_rel
python
scanny/python-pptx
src/pptx/opc/oxml.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/oxml.py
MIT
def relate_to(self, target: Part | str, reltype: str, is_external: bool = False) -> str: """Return rId key of relationship of `reltype` to `target`. If such a relationship already exists, its rId is returned. Otherwise the relationship is added and its new rId returned. """ if isinstance(target, str): assert is_external return self._rels.get_or_add_ext_rel(reltype, target) return self._rels.get_or_add(reltype, target)
Return rId key of relationship of `reltype` to `target`. If such a relationship already exists, its rId is returned. Otherwise the relationship is added and its new rId returned.
relate_to
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def _rels(self) -> _Relationships: """|_Relationships| object containing relationships from this part to others.""" raise NotImplementedError( # pragma: no cover "`%s` must implement `.rels`" % type(self).__name__ )
|_Relationships| object containing relationships from this part to others.
_rels
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def iter_parts(self) -> Iterator[Part]: """Generate exactly one reference to each part in the package.""" visited: Set[Part] = set() for rel in self.iter_rels(): if rel.is_external: continue part = rel.target_part if part in visited: continue yield part visited.add(part)
Generate exactly one reference to each part in the package.
iter_parts
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def iter_rels(self) -> Iterator[_Relationship]: """Generate exactly one reference to each relationship in package. Performs a depth-first traversal of the rels graph. """ visited: Set[Part] = set() def walk_rels(rels: _Relationships) -> Iterator[_Relationship]: for rel in rels.values(): yield rel # --- external items can have no relationships --- if rel.is_external: continue # -- all relationships other than those for the package belong to a part. Once # -- that part has been processed, processing it again would lead to the same # -- relationships appearing more than once. part = rel.target_part if part in visited: continue visited.add(part) # --- recurse into relationships of each unvisited target-part --- yield from walk_rels(part.rels) yield from walk_rels(self._rels)
Generate exactly one reference to each relationship in package. Performs a depth-first traversal of the rels graph.
iter_rels
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def next_partname(self, tmpl: str) -> PackURI: """Return |PackURI| next available partname matching `tmpl`. `tmpl` is a printf (%)-style template string containing a single replacement item, a '%d' to be used to insert the integer portion of the partname. Example: '/ppt/slides/slide%d.xml' """ # --- expected next partname is tmpl % n where n is one greater than the number # --- of existing partnames that match tmpl. Speed up finding the next one # --- (maybe) by searching from the end downward rather than from 1 upward. prefix = tmpl[: (tmpl % 42).find("42")] partnames = {p.partname for p in self.iter_parts() if p.partname.startswith(prefix)} for n in range(len(partnames) + 1, 0, -1): candidate_partname = tmpl % n if candidate_partname not in partnames: return PackURI(candidate_partname) raise Exception("ProgrammingError: ran out of candidate_partnames") # pragma: no cover
Return |PackURI| next available partname matching `tmpl`. `tmpl` is a printf (%)-style template string containing a single replacement item, a '%d' to be used to insert the integer portion of the partname. Example: '/ppt/slides/slide%d.xml'
next_partname
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def _load(self) -> Self: """Return the package after loading all parts and relationships.""" pkg_xml_rels, parts = _PackageLoader.load(self._pkg_file, cast("Package", self)) self._rels.load_from_xml(PACKAGE_URI, pkg_xml_rels, parts) return self
Return the package after loading all parts and relationships.
_load
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def load( cls, pkg_file: str | IO[bytes], package: Package ) -> tuple[CT_Relationships, dict[PackURI, Part]]: """Return (pkg_xml_rels, parts) pair resulting from loading `pkg_file`. The returned `parts` value is a {partname: part} mapping with each part in the package included and constructed complete with its relationships to other parts in the package. The returned `pkg_xml_rels` value is a `CT_Relationships` object containing the parsed package relationships. It is the caller's responsibility (the package object) to load those relationships into its |_Relationships| object. """ return cls(pkg_file, package)._load()
Return (pkg_xml_rels, parts) pair resulting from loading `pkg_file`. The returned `parts` value is a {partname: part} mapping with each part in the package included and constructed complete with its relationships to other parts in the package. The returned `pkg_xml_rels` value is a `CT_Relationships` object containing the parsed package relationships. It is the caller's responsibility (the package object) to load those relationships into its |_Relationships| object.
load
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def _load(self) -> tuple[CT_Relationships, dict[PackURI, Part]]: """Return (pkg_xml_rels, parts) pair resulting from loading pkg_file.""" parts, xml_rels = self._parts, self._xml_rels for partname, part in parts.items(): part.load_rels_from_xml(xml_rels[partname], parts) return xml_rels[PACKAGE_URI], parts
Return (pkg_xml_rels, parts) pair resulting from loading pkg_file.
_load
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def _parts(self) -> dict[PackURI, Part]: """dict {partname: Part} populated with parts loading from package. Among other duties, this collection is passed to each relationships collection so each relationship can resolve a reference to its target part when required. This reference can only be reliably carried out once the all parts have been loaded. """ content_types = self._content_types package = self._package package_reader = self._package_reader return { partname: PartFactory( partname, content_types[partname], package, blob=package_reader[partname], ) for partname in (p for p in self._xml_rels if p != "/") # -- invalid partnames can arise in some packages; ignore those rather than raise an # -- exception. if partname in package_reader }
dict {partname: Part} populated with parts loading from package. Among other duties, this collection is passed to each relationships collection so each relationship can resolve a reference to its target part when required. This reference can only be reliably carried out once the all parts have been loaded.
_parts
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def _xml_rels(self) -> dict[PackURI, CT_Relationships]: """dict {partname: xml_rels} for package and all package parts. This is used as the basis for other loading operations such as loading parts and populating their relationships. """ xml_rels: dict[PackURI, CT_Relationships] = {} visited_partnames: Set[PackURI] = set() def load_rels(source_partname: PackURI, rels: CT_Relationships): """Populate `xml_rels` dict by traversing relationships depth-first.""" xml_rels[source_partname] = rels visited_partnames.add(source_partname) base_uri = source_partname.baseURI # --- recursion stops when there are no unvisited partnames in rels --- for rel in rels.relationship_lst: if rel.targetMode == RTM.EXTERNAL: continue target_partname = PackURI.from_rel_ref(base_uri, rel.target_ref) if target_partname in visited_partnames: continue load_rels(target_partname, self._xml_rels_for(target_partname)) load_rels(PACKAGE_URI, self._xml_rels_for(PACKAGE_URI)) return xml_rels
dict {partname: xml_rels} for package and all package parts. This is used as the basis for other loading operations such as loading parts and populating their relationships.
_xml_rels
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def load_rels(source_partname: PackURI, rels: CT_Relationships): """Populate `xml_rels` dict by traversing relationships depth-first.""" xml_rels[source_partname] = rels visited_partnames.add(source_partname) base_uri = source_partname.baseURI # --- recursion stops when there are no unvisited partnames in rels --- for rel in rels.relationship_lst: if rel.targetMode == RTM.EXTERNAL: continue target_partname = PackURI.from_rel_ref(base_uri, rel.target_ref) if target_partname in visited_partnames: continue load_rels(target_partname, self._xml_rels_for(target_partname))
Populate `xml_rels` dict by traversing relationships depth-first.
load_rels
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def _xml_rels_for(self, partname: PackURI) -> CT_Relationships: """Return CT_Relationships object formed by parsing rels XML for `partname`. A CT_Relationships object is returned in all cases. A part that has no relationships receives an "empty" CT_Relationships object, i.e. containing no `CT_Relationship` objects. """ rels_xml = self._package_reader.rels_xml_for(partname) return ( CT_Relationships.new() if rels_xml is None else cast(CT_Relationships, parse_xml(rels_xml)) )
Return CT_Relationships object formed by parsing rels XML for `partname`. A CT_Relationships object is returned in all cases. A part that has no relationships receives an "empty" CT_Relationships object, i.e. containing no `CT_Relationship` objects.
_xml_rels_for
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def _blob_from_file(self, file: str | IO[bytes]) -> bytes: """Return bytes of `file`, which is either a str path or a file-like object.""" # --- a str `file` is assumed to be a path --- if isinstance(file, str): with open(file, "rb") as f: return f.read() # --- otherwise, assume `file` is a file-like object # --- reposition file cursor if it has one if callable(getattr(file, "seek")): file.seek(0) return file.read()
Return bytes of `file`, which is either a str path or a file-like object.
_blob_from_file
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def load(cls, partname: PackURI, content_type: str, package: Package, blob: bytes): """Return instance of `cls` loaded with parsed XML from `blob`.""" return cls( partname, content_type, package, element=cast("BaseOxmlElement", parse_xml(blob)) )
Return instance of `cls` loaded with parsed XML from `blob`.
load
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT
def _part_cls_for(cls, content_type: str) -> type[Part]: """Return the custom part class registered for `content_type`. Returns |Part| if no custom class is registered for `content_type`. """ if content_type in cls.part_type_for: return cls.part_type_for[content_type] return Part
Return the custom part class registered for `content_type`. Returns |Part| if no custom class is registered for `content_type`.
_part_cls_for
python
scanny/python-pptx
src/pptx/opc/package.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/opc/package.py
MIT