mirror of
https://github.com/aykhans/AzSuicideDataVisualization.git
synced 2025-09-06 02:44:18 +00:00
Version 0.1
Added sidebar, Dashboard, Line Graph
This commit is contained in:
4
.venv/Lib/site-packages/openpyxl/cell/__init__.py
Normal file
4
.venv/Lib/site-packages/openpyxl/cell/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# Copyright (c) 2010-2022 openpyxl
|
||||
|
||||
from .cell import Cell, WriteOnlyCell, MergedCell
|
||||
from .read_only import ReadOnlyCell
|
108
.venv/Lib/site-packages/openpyxl/cell/_writer.py
Normal file
108
.venv/Lib/site-packages/openpyxl/cell/_writer.py
Normal file
@@ -0,0 +1,108 @@
|
||||
# Copyright (c) 2010-2022 openpyxl
|
||||
|
||||
from openpyxl.compat import safe_string
|
||||
from openpyxl.xml.functions import Element, SubElement, whitespace, XML_NS, REL_NS
|
||||
from openpyxl import LXML
|
||||
from openpyxl.utils.datetime import to_excel, to_ISO8601
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
def _set_attributes(cell, styled=None):
|
||||
"""
|
||||
Set coordinate and datatype
|
||||
"""
|
||||
coordinate = cell.coordinate
|
||||
attrs = {'r': coordinate}
|
||||
if styled:
|
||||
attrs['s'] = f"{cell.style_id}"
|
||||
|
||||
if cell.data_type == "s":
|
||||
attrs['t'] = "inlineStr"
|
||||
elif cell.data_type != 'f':
|
||||
attrs['t'] = cell.data_type
|
||||
|
||||
value = cell._value
|
||||
|
||||
if cell.data_type == "d":
|
||||
if hasattr(value, "tzinfo") and value.tzinfo is not None:
|
||||
raise TypeError("Excel does not support timezones in datetimes. "
|
||||
"The tzinfo in the datetime/time object must be set to None.")
|
||||
|
||||
if cell.parent.parent.iso_dates and not isinstance(value, timedelta):
|
||||
value = to_ISO8601(value)
|
||||
else:
|
||||
attrs['t'] = "n"
|
||||
value = to_excel(value, cell.parent.parent.epoch)
|
||||
|
||||
if cell.hyperlink:
|
||||
cell.parent._hyperlinks.append(cell.hyperlink)
|
||||
|
||||
return value, attrs
|
||||
|
||||
|
||||
def etree_write_cell(xf, worksheet, cell, styled=None):
|
||||
|
||||
value, attributes = _set_attributes(cell, styled)
|
||||
|
||||
el = Element("c", attributes)
|
||||
if value is None or value == "":
|
||||
xf.write(el)
|
||||
return
|
||||
|
||||
if cell.data_type == 'f':
|
||||
shared_formula = worksheet.formula_attributes.get(cell.coordinate, {})
|
||||
formula = SubElement(el, 'f', shared_formula)
|
||||
if value is not None:
|
||||
formula.text = value[1:]
|
||||
value = None
|
||||
|
||||
if cell.data_type == 's':
|
||||
inline_string = SubElement(el, 'is')
|
||||
text = SubElement(inline_string, 't')
|
||||
text.text = value
|
||||
whitespace(text)
|
||||
|
||||
|
||||
else:
|
||||
cell_content = SubElement(el, 'v')
|
||||
if value is not None:
|
||||
cell_content.text = safe_string(value)
|
||||
|
||||
xf.write(el)
|
||||
|
||||
|
||||
def lxml_write_cell(xf, worksheet, cell, styled=False):
|
||||
value, attributes = _set_attributes(cell, styled)
|
||||
|
||||
if value == '' or value is None:
|
||||
with xf.element("c", attributes):
|
||||
return
|
||||
|
||||
with xf.element('c', attributes):
|
||||
if cell.data_type == 'f':
|
||||
shared_formula = worksheet.formula_attributes.get(cell.coordinate, {})
|
||||
with xf.element('f', shared_formula):
|
||||
if value is not None:
|
||||
xf.write(value[1:])
|
||||
value = None
|
||||
|
||||
if cell.data_type == 's':
|
||||
with xf.element("is"):
|
||||
attrs = {}
|
||||
if value != value.strip():
|
||||
attrs["{%s}space" % XML_NS] = "preserve"
|
||||
el = Element("t", attrs) # lxml can't handle xml-ns
|
||||
el.text = value
|
||||
xf.write(el)
|
||||
#with xf.element("t", attrs):
|
||||
#xf.write(value)
|
||||
else:
|
||||
with xf.element("v"):
|
||||
if value is not None:
|
||||
xf.write(safe_string(value))
|
||||
|
||||
|
||||
if LXML:
|
||||
write_cell = lxml_write_cell
|
||||
else:
|
||||
write_cell = etree_write_cell
|
329
.venv/Lib/site-packages/openpyxl/cell/cell.py
Normal file
329
.venv/Lib/site-packages/openpyxl/cell/cell.py
Normal file
@@ -0,0 +1,329 @@
|
||||
# Copyright (c) 2010-2022 openpyxl
|
||||
|
||||
"""Manage individual cells in a spreadsheet.
|
||||
|
||||
The Cell class is required to know its value and type, display options,
|
||||
and any other features of an Excel cell. Utilities for referencing
|
||||
cells using Excel's 'A1' column/row nomenclature are also provided.
|
||||
|
||||
"""
|
||||
|
||||
__docformat__ = "restructuredtext en"
|
||||
|
||||
# Python stdlib imports
|
||||
from copy import copy
|
||||
import datetime
|
||||
import re
|
||||
|
||||
|
||||
from openpyxl.compat import (
|
||||
NUMERIC_TYPES,
|
||||
deprecated,
|
||||
)
|
||||
|
||||
from openpyxl.utils.exceptions import IllegalCharacterError
|
||||
|
||||
from openpyxl.utils import get_column_letter
|
||||
from openpyxl.styles import numbers, is_date_format
|
||||
from openpyxl.styles.styleable import StyleableObject
|
||||
from openpyxl.worksheet.hyperlink import Hyperlink
|
||||
|
||||
# constants
|
||||
|
||||
TIME_TYPES = (datetime.datetime, datetime.date, datetime.time, datetime.timedelta)
|
||||
TIME_FORMATS = {
|
||||
datetime.datetime:numbers.FORMAT_DATE_DATETIME,
|
||||
datetime.date:numbers.FORMAT_DATE_YYYYMMDD2,
|
||||
datetime.time:numbers.FORMAT_DATE_TIME6,
|
||||
datetime.timedelta:numbers.FORMAT_DATE_TIMEDELTA,
|
||||
}
|
||||
|
||||
STRING_TYPES = (str, bytes)
|
||||
KNOWN_TYPES = NUMERIC_TYPES + TIME_TYPES + STRING_TYPES + (bool, type(None))
|
||||
|
||||
ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')
|
||||
ERROR_CODES = ('#NULL!', '#DIV/0!', '#VALUE!', '#REF!', '#NAME?', '#NUM!',
|
||||
'#N/A')
|
||||
|
||||
TYPE_STRING = 's'
|
||||
TYPE_FORMULA = 'f'
|
||||
TYPE_NUMERIC = 'n'
|
||||
TYPE_BOOL = 'b'
|
||||
TYPE_NULL = 'n'
|
||||
TYPE_INLINE = 'inlineStr'
|
||||
TYPE_ERROR = 'e'
|
||||
TYPE_FORMULA_CACHE_STRING = 'str'
|
||||
|
||||
VALID_TYPES = (TYPE_STRING, TYPE_FORMULA, TYPE_NUMERIC, TYPE_BOOL,
|
||||
TYPE_NULL, TYPE_INLINE, TYPE_ERROR, TYPE_FORMULA_CACHE_STRING)
|
||||
|
||||
|
||||
_TYPES = {int:'n', float:'n', str:'s', bool:'b'}
|
||||
|
||||
|
||||
def get_type(t, value):
|
||||
if isinstance(value, NUMERIC_TYPES):
|
||||
dt = 'n'
|
||||
elif isinstance(value, STRING_TYPES):
|
||||
dt = 's'
|
||||
elif isinstance(value, TIME_TYPES):
|
||||
dt = 'd'
|
||||
else:
|
||||
return
|
||||
_TYPES[t] = dt
|
||||
return dt
|
||||
|
||||
|
||||
def get_time_format(t):
|
||||
value = TIME_FORMATS.get(t)
|
||||
if value:
|
||||
return value
|
||||
for base in t.mro()[1:]:
|
||||
value = TIME_FORMATS.get(base)
|
||||
if value:
|
||||
TIME_FORMATS[t] = value
|
||||
return value
|
||||
raise ValueError("Could not get time format for {0!r}".format(value))
|
||||
|
||||
|
||||
class Cell(StyleableObject):
|
||||
"""Describes cell associated properties.
|
||||
|
||||
Properties of interest include style, type, value, and address.
|
||||
|
||||
"""
|
||||
__slots__ = (
|
||||
'row',
|
||||
'column',
|
||||
'_value',
|
||||
'data_type',
|
||||
'parent',
|
||||
'_hyperlink',
|
||||
'_comment',
|
||||
)
|
||||
|
||||
def __init__(self, worksheet, row=None, column=None, value=None, style_array=None):
|
||||
super(Cell, self).__init__(worksheet, style_array)
|
||||
self.row = row
|
||||
"""Row number of this cell (1-based)"""
|
||||
self.column = column
|
||||
"""Column number of this cell (1-based)"""
|
||||
# _value is the stored value, while value is the displayed value
|
||||
self._value = None
|
||||
self._hyperlink = None
|
||||
self.data_type = 'n'
|
||||
if value is not None:
|
||||
self.value = value
|
||||
self._comment = None
|
||||
|
||||
|
||||
@property
|
||||
def coordinate(self):
|
||||
"""This cell's coordinate (ex. 'A5')"""
|
||||
col = get_column_letter(self.column)
|
||||
return f"{col}{self.row}"
|
||||
|
||||
|
||||
@property
|
||||
def col_idx(self):
|
||||
"""The numerical index of the column"""
|
||||
return self.column
|
||||
|
||||
|
||||
@property
|
||||
def column_letter(self):
|
||||
return get_column_letter(self.column)
|
||||
|
||||
|
||||
@property
|
||||
def encoding(self):
|
||||
return self.parent.encoding
|
||||
|
||||
@property
|
||||
def base_date(self):
|
||||
return self.parent.parent.epoch
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return "<Cell {0!r}.{1}>".format(self.parent.title, self.coordinate)
|
||||
|
||||
def check_string(self, value):
|
||||
"""Check string coding, length, and line break character"""
|
||||
if value is None:
|
||||
return
|
||||
# convert to str string
|
||||
if not isinstance(value, str):
|
||||
value = str(value, self.encoding)
|
||||
value = str(value)
|
||||
# string must never be longer than 32,767 characters
|
||||
# truncate if necessary
|
||||
value = value[:32767]
|
||||
if next(ILLEGAL_CHARACTERS_RE.finditer(value), None):
|
||||
raise IllegalCharacterError
|
||||
return value
|
||||
|
||||
def check_error(self, value):
|
||||
"""Tries to convert Error" else N/A"""
|
||||
try:
|
||||
return str(value)
|
||||
except UnicodeDecodeError:
|
||||
return u'#N/A'
|
||||
|
||||
|
||||
def _bind_value(self, value):
|
||||
"""Given a value, infer the correct data type"""
|
||||
|
||||
self.data_type = "n"
|
||||
t = type(value)
|
||||
try:
|
||||
dt = _TYPES[t]
|
||||
except KeyError:
|
||||
dt = get_type(t, value)
|
||||
|
||||
if dt is None and value is not None:
|
||||
raise ValueError("Cannot convert {0!r} to Excel".format(value))
|
||||
|
||||
if dt:
|
||||
self.data_type = dt
|
||||
|
||||
if dt == 'd':
|
||||
if not is_date_format(self.number_format):
|
||||
self.number_format = get_time_format(t)
|
||||
|
||||
elif dt == "s":
|
||||
value = self.check_string(value)
|
||||
if len(value) > 1 and value.startswith("="):
|
||||
self.data_type = 'f'
|
||||
elif value in ERROR_CODES:
|
||||
self.data_type = 'e'
|
||||
|
||||
self._value = value
|
||||
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
"""Get or set the value held in the cell.
|
||||
|
||||
:type: depends on the value (string, float, int or
|
||||
:class:`datetime.datetime`)
|
||||
"""
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
"""Set the value and infer type and display options."""
|
||||
self._bind_value(value)
|
||||
|
||||
@property
|
||||
def internal_value(self):
|
||||
"""Always returns the value for excel."""
|
||||
return self._value
|
||||
|
||||
@property
|
||||
def hyperlink(self):
|
||||
"""Return the hyperlink target or an empty string"""
|
||||
return self._hyperlink
|
||||
|
||||
|
||||
@hyperlink.setter
|
||||
def hyperlink(self, val):
|
||||
"""Set value and display for hyperlinks in a cell.
|
||||
Automatically sets the `value` of the cell with link text,
|
||||
but you can modify it afterwards by setting the `value`
|
||||
property, and the hyperlink will remain.
|
||||
Hyperlink is removed if set to ``None``."""
|
||||
if val is None:
|
||||
self._hyperlink = None
|
||||
else:
|
||||
if not isinstance(val, Hyperlink):
|
||||
val = Hyperlink(ref="", target=val)
|
||||
val.ref = self.coordinate
|
||||
self._hyperlink = val
|
||||
if self._value is None:
|
||||
self.value = val.target or val.location
|
||||
|
||||
|
||||
@property
|
||||
def is_date(self):
|
||||
"""True if the value is formatted as a date
|
||||
|
||||
:type: bool
|
||||
"""
|
||||
return self.data_type == 'd' or (
|
||||
self.data_type == 'n' and is_date_format(self.number_format)
|
||||
)
|
||||
|
||||
|
||||
def offset(self, row=0, column=0):
|
||||
"""Returns a cell location relative to this cell.
|
||||
|
||||
:param row: number of rows to offset
|
||||
:type row: int
|
||||
|
||||
:param column: number of columns to offset
|
||||
:type column: int
|
||||
|
||||
:rtype: :class:`openpyxl.cell.Cell`
|
||||
"""
|
||||
offset_column = self.col_idx + column
|
||||
offset_row = self.row + row
|
||||
return self.parent.cell(column=offset_column, row=offset_row)
|
||||
|
||||
|
||||
@property
|
||||
def comment(self):
|
||||
""" Returns the comment associated with this cell
|
||||
|
||||
:type: :class:`openpyxl.comments.Comment`
|
||||
"""
|
||||
return self._comment
|
||||
|
||||
|
||||
@comment.setter
|
||||
def comment(self, value):
|
||||
"""
|
||||
Assign a comment to a cell
|
||||
"""
|
||||
|
||||
if value is not None:
|
||||
if value.parent:
|
||||
value = copy(value)
|
||||
value.bind(self)
|
||||
elif value is None and self._comment:
|
||||
self._comment.unbind()
|
||||
self._comment = value
|
||||
|
||||
|
||||
class MergedCell(StyleableObject):
|
||||
|
||||
"""
|
||||
Describes the properties of a cell in a merged cell and helps to
|
||||
display the borders of the merged cell.
|
||||
|
||||
The value of a MergedCell is always None.
|
||||
"""
|
||||
|
||||
__slots__ = ('row', 'column')
|
||||
|
||||
_value = None
|
||||
data_type = "n"
|
||||
comment = None
|
||||
hyperlink = None
|
||||
|
||||
|
||||
def __init__(self, worksheet, row=None, column=None):
|
||||
super(MergedCell, self).__init__(worksheet)
|
||||
self.row = row
|
||||
self.column = column
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return "<MergedCell {0!r}.{1}>".format(self.parent.title, self.coordinate)
|
||||
|
||||
coordinate = Cell.coordinate
|
||||
_comment = comment
|
||||
value = _value
|
||||
|
||||
|
||||
def WriteOnlyCell(ws=None, value=None):
|
||||
return Cell(worksheet=ws, column=1, row=1, value=value)
|
136
.venv/Lib/site-packages/openpyxl/cell/read_only.py
Normal file
136
.venv/Lib/site-packages/openpyxl/cell/read_only.py
Normal file
@@ -0,0 +1,136 @@
|
||||
# Copyright (c) 2010-2022 openpyxl
|
||||
|
||||
from openpyxl.cell import Cell
|
||||
from openpyxl.utils import get_column_letter
|
||||
from openpyxl.utils.datetime import from_excel
|
||||
from openpyxl.styles import is_date_format
|
||||
from openpyxl.styles.numbers import BUILTIN_FORMATS, BUILTIN_FORMATS_MAX_SIZE
|
||||
|
||||
|
||||
class ReadOnlyCell(object):
|
||||
|
||||
__slots__ = ('parent', 'row', 'column', '_value', 'data_type', '_style_id')
|
||||
|
||||
def __init__(self, sheet, row, column, value, data_type='n', style_id=0):
|
||||
self.parent = sheet
|
||||
self._value = None
|
||||
self.row = row
|
||||
self.column = column
|
||||
self.data_type = data_type
|
||||
self.value = value
|
||||
self._style_id = style_id
|
||||
|
||||
|
||||
def __eq__(self, other):
|
||||
for a in self.__slots__:
|
||||
if getattr(self, a) != getattr(other, a):
|
||||
return
|
||||
return True
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return "<ReadOnlyCell {0!r}.{1}>".format(self.parent.title, self.coordinate)
|
||||
|
||||
|
||||
@property
|
||||
def coordinate(self):
|
||||
column = get_column_letter(self.column)
|
||||
return "{1}{0}".format(self.row, column)
|
||||
|
||||
|
||||
@property
|
||||
def coordinate(self):
|
||||
return Cell.coordinate.__get__(self)
|
||||
|
||||
|
||||
@property
|
||||
def column_letter(self):
|
||||
return Cell.column_letter.__get__(self)
|
||||
|
||||
|
||||
@property
|
||||
def style_array(self):
|
||||
return self.parent.parent._cell_styles[self._style_id]
|
||||
|
||||
|
||||
@property
|
||||
def has_style(self):
|
||||
return self._style_id != 0
|
||||
|
||||
|
||||
@property
|
||||
def number_format(self):
|
||||
_id = self.style_array.numFmtId
|
||||
if _id < BUILTIN_FORMATS_MAX_SIZE:
|
||||
return BUILTIN_FORMATS.get(_id, "General")
|
||||
else:
|
||||
return self.parent.parent._number_formats[
|
||||
_id - BUILTIN_FORMATS_MAX_SIZE]
|
||||
|
||||
@property
|
||||
def font(self):
|
||||
_id = self.style_array.fontId
|
||||
return self.parent.parent._fonts[_id]
|
||||
|
||||
@property
|
||||
def fill(self):
|
||||
_id = self.style_array.fillId
|
||||
return self.parent.parent._fills[_id]
|
||||
|
||||
@property
|
||||
def border(self):
|
||||
_id = self.style_array.borderId
|
||||
return self.parent.parent._borders[_id]
|
||||
|
||||
@property
|
||||
def alignment(self):
|
||||
_id = self.style_array.alignmentId
|
||||
return self.parent.parent._alignments[_id]
|
||||
|
||||
@property
|
||||
def protection(self):
|
||||
_id = self.style_array.protectionId
|
||||
return self.parent.parent._protections[_id]
|
||||
|
||||
|
||||
@property
|
||||
def is_date(self):
|
||||
return Cell.is_date.__get__(self)
|
||||
|
||||
|
||||
@property
|
||||
def internal_value(self):
|
||||
return self._value
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
if self._value is not None:
|
||||
raise AttributeError("Cell is read only")
|
||||
self._value = value
|
||||
|
||||
|
||||
class EmptyCell(object):
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
value = None
|
||||
is_date = False
|
||||
font = None
|
||||
border = None
|
||||
fill = None
|
||||
number_format = None
|
||||
alignment = None
|
||||
data_type = 'n'
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return "<EmptyCell>"
|
||||
|
||||
EMPTY_CELL = EmptyCell()
|
184
.venv/Lib/site-packages/openpyxl/cell/text.py
Normal file
184
.venv/Lib/site-packages/openpyxl/cell/text.py
Normal file
@@ -0,0 +1,184 @@
|
||||
# Copyright (c) 2010-2022 openpyxl
|
||||
|
||||
"""
|
||||
Richtext definition
|
||||
"""
|
||||
|
||||
from openpyxl.descriptors.serialisable import Serialisable
|
||||
from openpyxl.descriptors import (
|
||||
Alias,
|
||||
Typed,
|
||||
Integer,
|
||||
Set,
|
||||
NoneSet,
|
||||
Bool,
|
||||
String,
|
||||
Sequence,
|
||||
)
|
||||
from openpyxl.descriptors.nested import (
|
||||
NestedBool,
|
||||
NestedInteger,
|
||||
NestedString,
|
||||
NestedText,
|
||||
)
|
||||
from openpyxl.styles.fonts import Font
|
||||
|
||||
|
||||
class PhoneticProperties(Serialisable):
|
||||
|
||||
tagname = "phoneticPr"
|
||||
|
||||
fontId = Integer()
|
||||
type = NoneSet(values=(['halfwidthKatakana', 'fullwidthKatakana',
|
||||
'Hiragana', 'noConversion']))
|
||||
alignment = NoneSet(values=(['noControl', 'left', 'center', 'distributed']))
|
||||
|
||||
def __init__(self,
|
||||
fontId=None,
|
||||
type=None,
|
||||
alignment=None,
|
||||
):
|
||||
self.fontId = fontId
|
||||
self.type = type
|
||||
self.alignment = alignment
|
||||
|
||||
|
||||
class PhoneticText(Serialisable):
|
||||
|
||||
tagname = "rPh"
|
||||
|
||||
sb = Integer()
|
||||
eb = Integer()
|
||||
t = NestedText(expected_type=str)
|
||||
text = Alias('t')
|
||||
|
||||
def __init__(self,
|
||||
sb=None,
|
||||
eb=None,
|
||||
t=None,
|
||||
):
|
||||
self.sb = sb
|
||||
self.eb = eb
|
||||
self.t = t
|
||||
|
||||
|
||||
class InlineFont(Font):
|
||||
|
||||
"""
|
||||
Font for inline text because, yes what you need are different objects with the same elements but different constraints.
|
||||
"""
|
||||
|
||||
tagname = "RPrElt"
|
||||
|
||||
rFont = NestedString(allow_none=True)
|
||||
charset = Font.charset
|
||||
family = Font.family
|
||||
b =Font.b
|
||||
i = Font.i
|
||||
strike = Font.strike
|
||||
outline = Font.outline
|
||||
shadow = Font.shadow
|
||||
condense = Font.condense
|
||||
extend = Font.extend
|
||||
color = Font.color
|
||||
sz = Font.sz
|
||||
u = Font.u
|
||||
vertAlign = Font.vertAlign
|
||||
scheme = Font.scheme
|
||||
|
||||
__elements__ = ('rFont', 'charset', 'family', 'b', 'i', 'strike',
|
||||
'outline', 'shadow', 'condense', 'extend', 'color', 'sz', 'u',
|
||||
'vertAlign', 'scheme')
|
||||
|
||||
def __init__(self,
|
||||
rFont=None,
|
||||
charset=None,
|
||||
family=None,
|
||||
b=None,
|
||||
i=None,
|
||||
strike=None,
|
||||
outline=None,
|
||||
shadow=None,
|
||||
condense=None,
|
||||
extend=None,
|
||||
color=None,
|
||||
sz=None,
|
||||
u=None,
|
||||
vertAlign=None,
|
||||
scheme=None,
|
||||
):
|
||||
self.rFont = rFont
|
||||
self.charset = charset
|
||||
self.family = family
|
||||
self.b = b
|
||||
self.i = i
|
||||
self.strike = strike
|
||||
self.outline = outline
|
||||
self.shadow = shadow
|
||||
self.condense = condense
|
||||
self.extend = extend
|
||||
self.color = color
|
||||
self.sz = sz
|
||||
self.u = u
|
||||
self.vertAlign = vertAlign
|
||||
self.scheme = scheme
|
||||
|
||||
|
||||
class RichText(Serialisable):
|
||||
|
||||
tagname = "RElt"
|
||||
|
||||
rPr = Typed(expected_type=InlineFont, allow_none=True)
|
||||
font = Alias("rPr")
|
||||
t = NestedText(expected_type=str, allow_none=True)
|
||||
text = Alias("t")
|
||||
|
||||
__elements__ = ('rPr', 't')
|
||||
|
||||
def __init__(self,
|
||||
rPr=None,
|
||||
t=None,
|
||||
):
|
||||
self.rPr = rPr
|
||||
self.t = t
|
||||
|
||||
|
||||
class Text(Serialisable):
|
||||
|
||||
tagname = "text"
|
||||
|
||||
t = NestedText(allow_none=True, expected_type=str)
|
||||
plain = Alias("t")
|
||||
r = Sequence(expected_type=RichText, allow_none=True)
|
||||
formatted = Alias("r")
|
||||
rPh = Sequence(expected_type=PhoneticText, allow_none=True)
|
||||
phonetic = Alias("rPh")
|
||||
phoneticPr = Typed(expected_type=PhoneticProperties, allow_none=True)
|
||||
PhoneticProperties = Alias("phoneticPr")
|
||||
|
||||
__elements__ = ('t', 'r', 'rPh', 'phoneticPr')
|
||||
|
||||
def __init__(self,
|
||||
t=None,
|
||||
r=(),
|
||||
rPh=(),
|
||||
phoneticPr=None,
|
||||
):
|
||||
self.t = t
|
||||
self.r = r
|
||||
self.rPh = rPh
|
||||
self.phoneticPr = phoneticPr
|
||||
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
"""
|
||||
Text stripped of all formatting
|
||||
"""
|
||||
snippets = []
|
||||
if self.plain is not None:
|
||||
snippets.append(self.plain)
|
||||
for block in self.formatted:
|
||||
if block.t is not None:
|
||||
snippets.append(block.t)
|
||||
return u"".join(snippets)
|
Reference in New Issue
Block a user