INSTRUCTION
stringlengths
1
8.43k
RESPONSE
stringlengths
75
104k
Return a loose lxml element having the tag specified by * nsptag_str *. * nsptag_str * must contain the standard namespace prefix e. g. a: tbl. The resulting element is an instance of the custom element class for this tag name if one is defined. A dictionary of attribute values may be provided as * attrs * ; they are s...
def OxmlElement(nsptag_str, attrs=None, nsdecls=None): """ Return a 'loose' lxml element having the tag specified by *nsptag_str*. *nsptag_str* must contain the standard namespace prefix, e.g. 'a:tbl'. The resulting element is an instance of the custom element class for this tag name if one is defin...
Return an |_IfdEntry| subclass instance containing the value of the directory entry at * offset * in * stream_rdr *.
def _IfdEntryFactory(stream_rdr, offset): """ Return an |_IfdEntry| subclass instance containing the value of the directory entry at *offset* in *stream_rdr*. """ ifd_entry_classes = { TIFF_FLD.ASCII: _AsciiIfdEntry, TIFF_FLD.SHORT: _ShortIfdEntry, TIFF_FLD.LONG: _L...
Return a |Tiff| instance containing the properties of the TIFF image in * stream *.
def from_stream(cls, stream): """ Return a |Tiff| instance containing the properties of the TIFF image in *stream*. """ parser = _TiffParser.parse(stream) px_width = parser.px_width px_height = parser.px_height horz_dpi = parser.horz_dpi vert_dpi ...
Return an instance of |_TiffParser| containing the properties parsed from the TIFF image in * stream *.
def parse(cls, stream): """ Return an instance of |_TiffParser| containing the properties parsed from the TIFF image in *stream*. """ stream_rdr = cls._make_stream_reader(stream) ifd0_offset = stream_rdr.read_long(4) ifd_entries = _IfdEntries.from_stream(stream_rd...
Return either BIG_ENDIAN or LITTLE_ENDIAN depending on the endian indicator found in the TIFF * stream * header either MM or II.
def _detect_endian(cls, stream): """ Return either BIG_ENDIAN or LITTLE_ENDIAN depending on the endian indicator found in the TIFF *stream* header, either 'MM' or 'II'. """ stream.seek(0) endian_str = stream.read(2) return BIG_ENDIAN if endian_str == b'MM' else LI...
Return the dpi value calculated for * resolution_tag * which can be either TIFF_TAG. X_RESOLUTION or TIFF_TAG. Y_RESOLUTION. The calculation is based on the values of both that tag and the TIFF_TAG. RESOLUTION_UNIT tag in this parser s |_IfdEntries| instance.
def _dpi(self, resolution_tag): """ Return the dpi value calculated for *resolution_tag*, which can be either TIFF_TAG.X_RESOLUTION or TIFF_TAG.Y_RESOLUTION. The calculation is based on the values of both that tag and the TIFF_TAG.RESOLUTION_UNIT tag in this parser's |_IfdEntries...
Return a |StreamReader| instance with wrapping * stream * and having endian - ness determined by the MM or II indicator in the TIFF stream header.
def _make_stream_reader(cls, stream): """ Return a |StreamReader| instance with wrapping *stream* and having "endian-ness" determined by the 'MM' or 'II' indicator in the TIFF stream header. """ endian = cls._detect_endian(stream) return StreamReader(stream, endia...
Return a new |_IfdEntries| instance parsed from * stream * starting at * offset *.
def from_stream(cls, stream, offset): """ Return a new |_IfdEntries| instance parsed from *stream* starting at *offset*. """ ifd_parser = _IfdParser(stream, offset) entries = dict((e.tag, e.value) for e in ifd_parser.iter_entries()) return cls(entries)
Generate an |_IfdEntry| instance corresponding to each entry in the directory.
def iter_entries(self): """ Generate an |_IfdEntry| instance corresponding to each entry in the directory. """ for idx in range(self._entry_count): dir_entry_offset = self._offset + 2 + (idx*12) ifd_entry = _IfdEntryFactory(self._stream_rdr, dir_entry_offs...
Return an |_IfdEntry| subclass instance containing the tag and value of the tag parsed from * stream_rdr * at * offset *. Note this method is common to all subclasses. Override the _parse_value () method to provide distinctive behavior based on field type.
def from_stream(cls, stream_rdr, offset): """ Return an |_IfdEntry| subclass instance containing the tag and value of the tag parsed from *stream_rdr* at *offset*. Note this method is common to all subclasses. Override the ``_parse_value()`` method to provide distinctive behavior...
Return the ASCII string parsed from * stream_rdr * at * value_offset *. The length of the string including a terminating \ x00 ( NUL ) character is in * value_count *.
def _parse_value(cls, stream_rdr, offset, value_count, value_offset): """ Return the ASCII string parsed from *stream_rdr* at *value_offset*. The length of the string, including a terminating '\x00' (NUL) character, is in *value_count*. """ return stream_rdr.read_str(valu...
Return the short int value contained in the * value_offset * field of this entry. Only supports single values at present.
def _parse_value(cls, stream_rdr, offset, value_count, value_offset): """ Return the short int value contained in the *value_offset* field of this entry. Only supports single values at present. """ if value_count == 1: return stream_rdr.read_short(offset, 8) e...
Return the long int value contained in the * value_offset * field of this entry. Only supports single values at present.
def _parse_value(cls, stream_rdr, offset, value_count, value_offset): """ Return the long int value contained in the *value_offset* field of this entry. Only supports single values at present. """ if value_count == 1: return stream_rdr.read_long(offset, 8) els...
Return the rational ( numerator/ denominator ) value at * value_offset * in * stream_rdr * as a floating - point number. Only supports single values at present.
def _parse_value(cls, stream_rdr, offset, value_count, value_offset): """ Return the rational (numerator / denominator) value at *value_offset* in *stream_rdr* as a floating-point number. Only supports single values at present. """ if value_count == 1: numerat...
Return ( footer_part rId ) pair for newly - created footer part.
def add_footer_part(self): """Return (footer_part, rId) pair for newly-created footer part.""" footer_part = FooterPart.new(self.package) rId = self.relate_to(footer_part, RT.FOOTER) return footer_part, rId
Return ( header_part rId ) pair for newly - created header part.
def add_header_part(self): """Return (header_part, rId) pair for newly-created header part.""" header_part = HeaderPart.new(self.package) rId = self.relate_to(header_part, RT.HEADER) return header_part, rId
A |NumberingPart| object providing access to the numbering definitions for this document. Creates an empty numbering part if one is not present.
def numbering_part(self): """ A |NumberingPart| object providing access to the numbering definitions for this document. Creates an empty numbering part if one is not present. """ try: return self.part_related_by(RT.NUMBERING) except KeyError: ...
A |SettingsPart| object providing access to the document - level settings for this document. Creates a default settings part if one is not present.
def _settings_part(self): """ A |SettingsPart| object providing access to the document-level settings for this document. Creates a default settings part if one is not present. """ try: return self.part_related_by(RT.SETTINGS) except KeyError: ...
Instance of |StylesPart| for this document. Creates an empty styles part if one is not present.
def _styles_part(self): """ Instance of |StylesPart| for this document. Creates an empty styles part if one is not present. """ try: return self.part_related_by(RT.STYLES) except KeyError: styles_part = StylesPart.default(self.package) ...
Return string containing the contents of the file at * relpath * relative to this file.
def text_of(relpath): """ Return string containing the contents of the file at *relpath* relative to this file. """ thisdir = os.path.dirname(__file__) file_path = os.path.join(thisdir, os.path.normpath(relpath)) with open(file_path) as f: text = f.read() return text
Write a physical package (. pptx file ) to * pkg_file * containing * pkg_rels * and * parts * and a content types stream based on the content types of the parts.
def write(pkg_file, pkg_rels, parts): """ Write a physical package (.pptx file) to *pkg_file* containing *pkg_rels* and *parts* and a content types stream based on the content types of the parts. """ phys_writer = PhysPkgWriter(pkg_file) PackageWriter._write_conte...
Write [ Content_Types ]. xml part to the physical package with an appropriate content type lookup target for each part in * parts *.
def _write_content_types_stream(phys_writer, parts): """ Write ``[Content_Types].xml`` part to the physical package with an appropriate content type lookup target for each part in *parts*. """ cti = _ContentTypesItem.from_parts(parts) phys_writer.write(CONTENT_TYPES_URI, ...
Write the blob of each part in * parts * to the package along with a rels item for its relationships if and only if it has any.
def _write_parts(phys_writer, parts): """ Write the blob of each part in *parts* to the package, along with a rels item for its relationships if and only if it has any. """ for part in parts: phys_writer.write(part.partname, part.blob) if len(part._rels): ...
Return content types XML mapping each part in * parts * to the appropriate content type and suitable for storage as [ Content_Types ]. xml in an OPC package.
def from_parts(cls, parts): """ Return content types XML mapping each part in *parts* to the appropriate content type and suitable for storage as ``[Content_Types].xml`` in an OPC package. """ cti = cls() cti._defaults['rels'] = CT.OPC_RELATIONSHIPS cti._d...
Add a content type for the part with * partname * and * content_type * using a default or override as appropriate.
def _add_content_type(self, partname, content_type): """ Add a content type for the part with *partname* and *content_type*, using a default or override as appropriate. """ ext = partname.ext if (ext.lower(), content_type) in default_content_types: self._defau...
Return XML form of this content types item suitable for storage as [ Content_Types ]. xml in an OPC package. Although the sequence of elements is not strictly significant as an aid to testing and readability Default elements are sorted by extension and Override elements are sorted by partname.
def _element(self): """ Return XML form of this content types item, suitable for storage as ``[Content_Types].xml`` in an OPC package. Although the sequence of elements is not strictly significant, as an aid to testing and readability Default elements are sorted by extension and ...
Mixed here meaning it contains <w: tab/ > <w: cr/ > etc. elements.
def given_a_run_having_mixed_text_content(context): """ Mixed here meaning it contains ``<w:tab/>``, ``<w:cr/>``, etc. elements. """ r_xml = """\ <w:r %s> <w:t>abc</w:t> <w:tab/> <w:t>def</w:t> <w:cr/> <w:t>ghi</w:t> <w:drawing/> ...
Return w: sectPr element for new section added at end of document.
def add_section_break(self): """Return `w:sectPr` element for new section added at end of document. The last `w:sectPr` becomes the second-to-last, with the new `w:sectPr` being an exact clone of the previous one, except that all header and footer references are removed (and are therefo...
Remove all content child elements from this <w: body > element. Leave the <w: sectPr > element if it is present.
def clear_content(self): """ Remove all content child elements from this <w:body> element. Leave the <w:sectPr> element if it is present. """ if self.sectPr is not None: content_elms = self[:-1] else: content_elms = self[:] for content_elm ...
Return a |BaseImageHeader| subclass instance that knows how to parse the headers of the image in * stream *.
def _ImageHeaderFactory(stream): """ Return a |BaseImageHeader| subclass instance that knows how to parse the headers of the image in *stream*. """ from docx.image import SIGNATURES def read_32(stream): stream.seek(0) return stream.read(32) header = read_32(stream) for ...
Return a new |Image| subclass instance parsed from the image binary contained in * blob *.
def from_blob(cls, blob): """ Return a new |Image| subclass instance parsed from the image binary contained in *blob*. """ stream = BytesIO(blob) return cls._from_stream(stream, blob)
Return a new |Image| subclass instance loaded from the image file identified by * image_descriptor * a path or file - like object.
def from_file(cls, image_descriptor): """ Return a new |Image| subclass instance loaded from the image file identified by *image_descriptor*, a path or file-like object. """ if is_string(image_descriptor): path = image_descriptor with open(path, 'rb') as f...
Return a ( cx cy ) 2 - tuple representing the native dimensions of this image scaled by applying the following rules to * width * and * height *. If both * width * and * height * are specified the return value is ( * width * * height * ) ; no scaling is performed. If only one is specified it is used to compute a scalin...
def scaled_dimensions(self, width=None, height=None): """ Return a (cx, cy) 2-tuple representing the native dimensions of this image scaled by applying the following rules to *width* and *height*. If both *width* and *height* are specified, the return value is (*width*, *height*)...
Return an instance of the |Image| subclass corresponding to the format of the image in * stream *.
def _from_stream(cls, stream, blob, filename=None): """ Return an instance of the |Image| subclass corresponding to the format of the image in *stream*. """ image_header = _ImageHeaderFactory(stream) if filename is None: filename = 'image.%s' % image_header.de...
Append a run to this paragraph containing * text * and having character style identified by style ID * style *. * text * can contain tab ( \\ t ) characters which are converted to the appropriate XML form for a tab. * text * can also include newline ( \\ n ) or carriage return ( \\ r ) characters each of which is conve...
def add_run(self, text=None, style=None): """ Append a run to this paragraph containing *text* and having character style identified by style ID *style*. *text* can contain tab (``\\t``) characters, which are converted to the appropriate XML form for a tab. *text* can also includ...
Return a newly created paragraph inserted directly before this paragraph. If * text * is supplied the new paragraph contains that text in a single run. If * style * is provided that style is assigned to the new paragraph.
def insert_paragraph_before(self, text=None, style=None): """ Return a newly created paragraph, inserted directly before this paragraph. If *text* is supplied, the new paragraph contains that text in a single run. If *style* is provided, that style is assigned to the new paragrap...
Read/ Write. |_ParagraphStyle| object representing the style assigned to this paragraph. If no explicit style is assigned to this paragraph its value is the default paragraph style for the document. A paragraph style name can be assigned in lieu of a paragraph style object. Assigning |None| removes any applied style ma...
def style(self): """ Read/Write. |_ParagraphStyle| object representing the style assigned to this paragraph. If no explicit style is assigned to this paragraph, its value is the default paragraph style for the document. A paragraph style name can be assigned in lieu of a paragrap...
String formed by concatenating the text of each run in the paragraph. Tabs and line breaks in the XML are mapped to \\ t and \\ n characters respectively.
def text(self): """ String formed by concatenating the text of each run in the paragraph. Tabs and line breaks in the XML are mapped to ``\\t`` and ``\\n`` characters respectively. Assigning text to this property causes all existing paragraph content to be replaced with ...
Return a newly created paragraph inserted directly before this paragraph.
def _insert_paragraph_before(self): """ Return a newly created paragraph, inserted directly before this paragraph. """ p = self._p.add_p_before() return Paragraph(p, self._parent)
Serialize * element * to human - readable XML suitable for tests. No XML declaration.
def serialize_for_reading(element): """ Serialize *element* to human-readable XML suitable for tests. No XML declaration. """ xml = etree.tostring(element, encoding='unicode', pretty_print=True) return XmlString(xml)
Return a sequence of attribute strings parsed from * attrs *. Each attribute string is stripped of whitespace on both ends.
def _attr_seq(self, attrs): """ Return a sequence of attribute strings parsed from *attrs*. Each attribute string is stripped of whitespace on both ends. """ attrs = attrs.strip() attr_lst = attrs.split() return sorted(attr_lst)
Return True if the element in * line_2 * is XML equivalent to the element in * line *.
def _eq_elm_strs(self, line, line_2): """ Return True if the element in *line_2* is XML equivalent to the element in *line*. """ front, attrs, close, text = self._parse_line(line) front_2, attrs_2, close_2, text_2 = self._parse_line(line_2) if front != front_2: ...
Return front attrs close text 4 - tuple result of parsing XML element string * line *.
def _parse_line(cls, line): """ Return front, attrs, close, text 4-tuple result of parsing XML element string *line*. """ match = cls._xml_elm_line_patt.match(line) front, attrs, close, text = [match.group(n) for n in range(1, 5)] return front, attrs, close, text
Add the appropriate methods to * element_cls *.
def populate_class_members(self, element_cls, prop_name): """ Add the appropriate methods to *element_cls*. """ self._element_cls = element_cls self._prop_name = prop_name self._add_attr_property()
Add a read/ write { prop_name } property to the element class that returns the interpreted value of this attribute on access and changes the attribute value to its ST_ * counterpart on assignment.
def _add_attr_property(self): """ Add a read/write ``{prop_name}`` property to the element class that returns the interpreted value of this attribute on access and changes the attribute value to its ST_* counterpart on assignment. """ property_ = property(self._getter, se...
Return a function object suitable for the get side of the attribute property descriptor.
def _getter(self): """ Return a function object suitable for the "get" side of the attribute property descriptor. """ def get_attr_value(obj): attr_str_value = obj.get(self._clark_name) if attr_str_value is None: return self._default ...
Return a function object suitable for the set side of the attribute property descriptor.
def _setter(self): """ Return a function object suitable for the "set" side of the attribute property descriptor. """ def set_attr_value(obj, value): if value is None or value == self._default: if self._clark_name in obj.attrib: del...
Return a function object suitable for the get side of the attribute property descriptor.
def _getter(self): """ Return a function object suitable for the "get" side of the attribute property descriptor. """ def get_attr_value(obj): attr_str_value = obj.get(self._clark_name) if attr_str_value is None: raise InvalidXmlError( ...
Return a function object suitable for the set side of the attribute property descriptor.
def _setter(self): """ Return a function object suitable for the "set" side of the attribute property descriptor. """ def set_attr_value(obj, value): str_value = self._simple_type.to_xml(value) obj.set(self._clark_name, str_value) return set_attr_v...
Add an _add_x () method to the element class for this child element.
def _add_adder(self): """ Add an ``_add_x()`` method to the element class for this child element. """ def _add_child(obj, **attrs): new_method = getattr(obj, self._new_method_name) child = new_method() for key, value in attrs.items(): ...
Add a _new_ { prop_name } () method to the element class that creates a new empty element of the correct type having no attributes.
def _add_creator(self): """ Add a ``_new_{prop_name}()`` method to the element class that creates a new, empty element of the correct type, having no attributes. """ creator = self._creator creator.__doc__ = ( 'Return a "loose", newly created ``<%s>`` element ...
Add a read - only { prop_name } property to the element class for this child element.
def _add_getter(self): """ Add a read-only ``{prop_name}`` property to the element class for this child element. """ property_ = property(self._getter, None, None) # assign unconditionally to overwrite element name definition setattr(self._element_cls, self._prop_...
Add an _insert_x () method to the element class for this child element.
def _add_inserter(self): """ Add an ``_insert_x()`` method to the element class for this child element. """ def _insert_child(obj, child): obj.insert_element_before(child, *self._successors) return child _insert_child.__doc__ = ( 'Retu...
Add a read - only { prop_name } _lst property to the element class to retrieve a list of child elements matching this type.
def _add_list_getter(self): """ Add a read-only ``{prop_name}_lst`` property to the element class to retrieve a list of child elements matching this type. """ prop_name = '%s_lst' % self._prop_name property_ = property(self._list_getter, None, None) setattr(self._...
Add a public add_x () method to the parent element class.
def _add_public_adder(self): """ Add a public ``add_x()`` method to the parent element class. """ def add_child(obj): private_add_method = getattr(obj, self._add_method_name) child = private_add_method() return child add_child.__doc__ = ( ...
Add * method * to the target class as * name * unless * name * is already defined on the class.
def _add_to_class(self, name, method): """ Add *method* to the target class as *name*, unless *name* is already defined on the class. """ if hasattr(self._element_cls, name): return setattr(self._element_cls, name, method)
Return a function object suitable for the get side of the property descriptor. This default getter returns the child element with matching tag name or |None| if not present.
def _getter(self): """ Return a function object suitable for the "get" side of the property descriptor. This default getter returns the child element with matching tag name or |None| if not present. """ def get_child_element(obj): return obj.find(qn(self._nspt...
Return a function object suitable for the get side of a list property descriptor.
def _list_getter(self): """ Return a function object suitable for the "get" side of a list property descriptor. """ def get_child_element_list(obj): return obj.findall(qn(self._nsptagname)) get_child_element_list.__doc__ = ( 'A list containing each...
Add the appropriate methods to * element_cls *.
def populate_class_members( self, element_cls, group_prop_name, successors): """ Add the appropriate methods to *element_cls*. """ self._element_cls = element_cls self._group_prop_name = group_prop_name self._successors = successors self._add_getter()...
Add a get_or_change_to_x () method to the element class for this child element.
def _add_get_or_change_to_method(self): """ Add a ``get_or_change_to_x()`` method to the element class for this child element. """ def get_or_change_to_child(obj): child = getattr(obj, self._prop_name) if child is not None: return child ...
Calculate property name from tag name e. g. a: schemeClr - > schemeClr.
def _prop_name(self): """ Calculate property name from tag name, e.g. a:schemeClr -> schemeClr. """ if ':' in self._nsptagname: start = self._nsptagname.index(':') + 1 else: start = 0 return self._nsptagname[start:]
Add the appropriate methods to * element_cls *.
def populate_class_members(self, element_cls, prop_name): """ Add the appropriate methods to *element_cls*. """ super(OneAndOnlyOne, self).populate_class_members( element_cls, prop_name ) self._add_getter()
Add the appropriate methods to * element_cls *.
def populate_class_members(self, element_cls, prop_name): """ Add the appropriate methods to *element_cls*. """ super(OneOrMore, self).populate_class_members( element_cls, prop_name ) self._add_list_getter() self._add_creator() self._add_insert...
Add the appropriate methods to * element_cls *.
def populate_class_members(self, element_cls, prop_name): """ Add the appropriate methods to *element_cls*. """ super(ZeroOrOne, self).populate_class_members(element_cls, prop_name) self._add_getter() self._add_creator() self._add_inserter() self._add_adde...
Add a get_or_add_x () method to the element class for this child element.
def _add_get_or_adder(self): """ Add a ``get_or_add_x()`` method to the element class for this child element. """ def get_or_add_child(obj): child = getattr(obj, self._prop_name) if child is None: add_method = getattr(obj, self._add_method_...
Add a _remove_x () method to the element class for this child element.
def _add_remover(self): """ Add a ``_remove_x()`` method to the element class for this child element. """ def _remove_child(obj): obj.remove_all(self._nsptagname) _remove_child.__doc__ = ( 'Remove all ``<%s>`` child elements.' ) % self._nsp...
Add the appropriate methods to * element_cls *.
def populate_class_members(self, element_cls, prop_name): """ Add the appropriate methods to *element_cls*. """ super(ZeroOrOneChoice, self).populate_class_members( element_cls, prop_name ) self._add_choice_getter() for choice in self._choices: ...
Add a read - only { prop_name } property to the element class that returns the present member of this group or |None| if none are present.
def _add_choice_getter(self): """ Add a read-only ``{prop_name}`` property to the element class that returns the present member of this group, or |None| if none are present. """ property_ = property(self._choice_getter, None, None) # assign unconditionally to over...
Add a _remove_eg_x () method to the element class for this choice group.
def _add_group_remover(self): """ Add a ``_remove_eg_x()`` method to the element class for this choice group. """ def _remove_choice_group(obj): for tagname in self._member_nsptagnames: obj.remove_all(tagname) _remove_choice_group.__doc__ = ( ...
Return a function object suitable for the get side of the property descriptor.
def _choice_getter(self): """ Return a function object suitable for the "get" side of the property descriptor. """ def get_group_member_element(obj): return obj.first_child_found_in(*self._member_nsptagnames) get_group_member_element.__doc__ = ( 'R...
Return the first child found with tag in * tagnames * or None if not found.
def first_child_found_in(self, *tagnames): """ Return the first child found with tag in *tagnames*, or None if not found. """ for tagname in tagnames: child = self.find(qn(tagname)) if child is not None: return child return None
Remove all child elements whose tagname ( e. g. a: p ) appears in * tagnames *.
def remove_all(self, *tagnames): """ Remove all child elements whose tagname (e.g. 'a:p') appears in *tagnames*. """ for tagname in tagnames: matching = self.findall(qn(tagname)) for child in matching: self.remove(child)
Override of lxml _Element. xpath () method to provide standard Open XML namespace mapping ( nsmap ) in centralized location.
def xpath(self, xpath_str): """ Override of ``lxml`` _Element.xpath() method to provide standard Open XML namespace mapping (``nsmap``) in centralized location. """ return super(BaseOxmlElement, self).xpath( xpath_str, namespaces=nsmap )
An |RGBColor| value or |None| if no RGB color is specified.
def rgb(self): """ An |RGBColor| value or |None| if no RGB color is specified. When :attr:`type` is `MSO_COLOR_TYPE.RGB`, the value of this property will always be an |RGBColor| value. It may also be an |RGBColor| value if :attr:`type` is `MSO_COLOR_TYPE.THEME`, as Word writes t...
A member of: ref: MsoThemeColorIndex or |None| if no theme color is specified. When: attr: type is MSO_COLOR_TYPE. THEME the value of this property will always be a member of: ref: MsoThemeColorIndex. When: attr: type has any other value the value of this property is |None|.
def theme_color(self): """ A member of :ref:`MsoThemeColorIndex` or |None| if no theme color is specified. When :attr:`type` is `MSO_COLOR_TYPE.THEME`, the value of this property will always be a member of :ref:`MsoThemeColorIndex`. When :attr:`type` has any other value, the valu...
Read - only. A member of: ref: MsoColorType one of RGB THEME or AUTO corresponding to the way this color is defined. Its value is |None| if no color is applied at this level which causes the effective color to be inherited from the style hierarchy.
def type(self): """ Read-only. A member of :ref:`MsoColorType`, one of RGB, THEME, or AUTO, corresponding to the way this color is defined. Its value is |None| if no color is applied at this level, which causes the effective color to be inherited from the style hierarchy. ...
The type of this inline shape as a member of docx. enum. shape. WD_INLINE_SHAPE e. g. LINKED_PICTURE. Read - only.
def type(self): """ The type of this inline shape as a member of ``docx.enum.shape.WD_INLINE_SHAPE``, e.g. ``LINKED_PICTURE``. Read-only. """ graphicData = self._inline.graphic.graphicData uri = graphicData.uri if uri == nsmap['pic']: blip = gr...
Extracts the data from a Plotly Figure
def to_df(figure): """ Extracts the data from a Plotly Figure Parameters ---------- figure : plotly_figure Figure from which data will be extracted Returns a DataFrame or list of DataFrame """ dfs=[] for trace in figure['data']: if '...
Converts from hex|rgb to rgba
def to_rgba(color, alpha): """ Converts from hex|rgb to rgba Parameters: ----------- color : string Color representation on hex or rgb alpha : float Value from 0 to 1.0 that represents the alpha value. Example: ...
Converts from hex to rgb
def hex_to_rgb(color): """ Converts from hex to rgb Parameters: ----------- color : string Color representation on hex or rgb Example: hex_to_rgb('#E1E5ED') hex_to_rgb('#f03') """ color = normalize(color) color = color[1:] # r...
Returns an hex color
def normalize(color): """ Returns an hex color Parameters: ----------- color : string Color representation in rgba|rgb|hex Example: normalize('#f03') """ if type(color) == tuple: color = to_rgba(*color) if 'rgba' in color: ret...
Converts from rgb to hex
def rgb_to_hex(color): """ Converts from rgb to hex Parameters: ----------- color : string Color representation on hex or rgb Example: rgb_to_hex('rgb(23,25,24)') """ rgb = eval(color.replace('rgb', '')) # return '#'+''.join(map(chr, rgb)).en...
Converts from rgba to rgb
def rgba_to_rgb(color, bg='rgb(255,255,255)'): """ Converts from rgba to rgb Parameters: ----------- color : string Color representation in rgba bg : string Color representation in rgb Example: rgba_to_rgb('rgb(23,25,24,.4...
Converts from hex to hsv
def hex_to_hsv(color): """ Converts from hex to hsv Parameters: ----------- color : string Color representation on color Example: hex_to_hsv('#ff9933') """ color = normalize(color) color = color[1:] # color=tuple(ord(c)/255.0 for c in col...
Generates a scale of colours from a base colour
def color_range(color, N=20): """ Generates a scale of colours from a base colour Parameters: ----------- color : string Color representation in hex N : int number of colours to generate Example: color_range('#ff9933',20...
Generates a colour table
def color_table(color, N=1, sort=False, sort_values=False, inline=False, as_html=False): """ Generates a colour table Parameters: ----------- color : string | list | dict Color representation in rgba|rgb|hex If a list of colors is passed then these ...
Returns a generator with a list of colors and gradients of those colors
def colorgen(colors=None, n=None, scale=None, theme=None): """ Returns a generator with a list of colors and gradients of those colors Parameters: ----------- colors : list(colors) List of colors to use Example: colorgen() colorgen(['blue...
Displays a color scale ( HTML )
def scales(scale=None): """ Displays a color scale (HTML) Parameters: ----------- scale : str Color scale name If no scale name is provided then all scales are returned (max number for each scale) If sca...
Returns a color scale
def get_scales(scale=None, n=None): """ Returns a color scale Parameters: ----------- scale : str Color scale name If the color name is preceded by a minus (-) then the scale is inversed n : int Nu...
Returns a color scale to be used for a plotly figure
def get_colorscale(scale): """ Returns a color scale to be used for a plotly figure Parameters: ----------- scale : str or list Color scale name If the color name is preceded by a minus (-) then the scale is inversed. ...
Generates a plotly Data object
def _to_iplot(self,colors=None,colorscale=None,kind='scatter',mode='lines',interpolation='linear',symbol='dot',size='12',fill=False, width=3,dash='solid',sortbars=False,keys=False,bestfit=False,bestfit_colors=None,opacity=0.6, mean=False,mean_colors=None,asDates=False,asTimestamp=False,text=None,**kwargs): """ Ge...
Returns a plotly chart either as inline chart image of Figure object
def _iplot(self,kind='scatter',data=None,layout=None,filename='',sharing=None,title='',xTitle='',yTitle='',zTitle='',theme=None,colors=None,colorscale=None,fill=False,width=None, dash='solid',mode='',interpolation='linear',symbol='circle',size=12,barmode='',sortbars=False,bargap=None,bargroupgap=None,bins=None,histn...
Returns a dict with an item per key
def get_items_as_list(items,keys,items_names='styles'): """ Returns a dict with an item per key Parameters: ----------- items : string, list or dict Items (ie line styles) keys: list List of keys items_names : string Name of items """ if type(items)!=dict: if type(items)==list: if len(items...
Displays a matrix with scatter plot for each pair of Series in the DataFrame. The diagonal shows a histogram for each of the Series
def _scatter_matrix(self,theme=None,bins=10,color='grey',size=2, asFigure=False, **iplot_kwargs): """ Displays a matrix with scatter plot for each pair of Series in the DataFrame. The diagonal shows a histogram for each of the Series Parameters: ----------- df : DataFrame Pandas DataFrame theme : string ...
Plots a figure in IPython creates an HTML or generates an Image
def iplot(figure,validate=True,sharing=None,filename='', online=None,asImage=False,asUrl=False,asPlot=False, dimensions=None,display_image=True,**kwargs): """ Plots a figure in IPython, creates an HTML or generates an Image figure : figure Plotly figure to be charted validate : bool If True then all va...
Generates a Technical Study Chart
def _ta_plot(self,study,periods=14,column=None,include=True,str='{name}({period})',detail=False, theme=None,sharing=None,filename='',asFigure=False,**iplot_kwargs): """ Generates a Technical Study Chart Parameters: ----------- study : string Technical Study to be charted sma - 'Simple Moving Averag...
Plots a figure in IPython
def _fig_iplot(self,validate=True,sharing=None,filename='', online=None,asImage=False,asUrl=False,asPlot=False, dimensions=None,display_image=True,**kwargs): """ Plots a figure in IPython figure : figure Plotly figure to be charted validate : bool If True then all values are validated before it is c...
Ensure that filesystem is setup/ filled out in a valid way
def ensure_local_files(): """ Ensure that filesystem is setup/filled out in a valid way """ if _file_permissions: if not os.path.isdir(AUTH_DIR): os.mkdir(AUTH_DIR) for fn in [CONFIG_FILE]: contents = load_json_dict(fn) for key, val in list(_FILE_CONTENT[fn].items()): if key not in contents: c...
Set the keyword - value pairs in ~/. config.
def set_config_file(sharing=None,theme=None,colorscale=None,offline=None,offline_connected=None, offline_url=None,offline_show_link=None,offline_link_text=None, offline_config=None, datagen_mode=None,**kwargs): """ Set the keyword-value pairs in `~/.config`. sharing : string Sets the sharing level...
Checks if file exists. Returns {} if something fails.
def load_json_dict(filename, *args): """Checks if file exists. Returns {} if something fails.""" data = {} if os.path.exists(filename): with open(filename, "r") as f: try: data = json.load(f) if not isinstance(data, dict): data = {} except: pass if args: return {key: data[key] for key ...