@v587d/capital-generation 2.29.0 → 2.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/README.md +3 -3
- package/THIRD_PARTY_NOTICES.md +16 -0
- package/automation/package.json +1 -1
- package/chart-ui/package.json +1 -1
- package/config/package.json +1 -1
- package/lib/collector-runtime.js +56 -1
- package/lib/data-collector/catalog-taxonomy.d.ts +1 -1
- package/lib/data-collector/catalog-taxonomy.js +33 -0
- package/lib/data-collector/dataset-tools.js +4 -2
- package/lib/data-collector/describe.d.ts +2 -0
- package/lib/data-collector/describe.js +2 -0
- package/lib/data-collector/store.d.ts +11 -0
- package/lib/data-collector/store.js +80 -1
- package/lib/data-collector/tools.d.ts +1 -1
- package/lib/data-collector/tools.js +10 -9
- package/lib/python-runtime/errors.d.ts +1 -1
- package/lib/python-runtime/errors.js +2 -0
- package/lib/python-runtime/manager.d.ts +28 -1
- package/lib/python-runtime/manager.js +141 -5
- package/lib/python-runtime/probe.d.ts +24 -0
- package/lib/python-runtime/probe.js +66 -50
- package/lib/sources/csindex-http.d.ts +4 -0
- package/lib/sources/csindex-http.js +233 -0
- package/lib/sources/eastmoney-http.js +1504 -1
- package/lib/sources/fuyao-rest.js +168 -8
- package/lib/sources/official-http.d.ts +4 -0
- package/lib/sources/official-http.js +477 -0
- package/lib/sources/python-remote.d.ts +25 -0
- package/lib/sources/python-remote.js +461 -0
- package/lib/sources/sina-http.d.ts +2 -0
- package/lib/sources/sina-http.js +484 -0
- package/lib/sources/tencent-http.js +23 -8
- package/lib/sources/ths-http.d.ts +2 -0
- package/lib/sources/ths-http.js +517 -0
- package/lib/time/tools.js +19 -0
- package/lib/web-retriever/local-fetch.d.ts +1 -1
- package/lib/web-retriever/local-fetch.js +1 -1
- package/lib/web-retriever/sources.d.ts +7 -0
- package/lib/web-retriever/sources.js +46 -21
- package/lib/web-retriever/throttle.d.ts +8 -0
- package/lib/web-retriever/throttle.js +13 -0
- package/lib/web-retriever/tools.js +1 -1
- package/lib/web-retriever/wind-client.d.ts +1 -1
- package/lib/web-retriever/wind-client.js +1 -1
- package/package.json +1 -1
- package/preset/capital-generation/agent.patch.yml +7 -5
- package/preset/capital-generation/skills/capital-data-protocol/SKILL.md +16 -16
- package/python/scripts/baostock_stock_basic.py +129 -0
- package/python/scripts/baostock_valuation_history.py +141 -0
- package/python/scripts/pbc_social_financing.py +291 -0
- package/python/vendor/baostock/LICENSE +19 -0
- package/python/vendor/baostock/__init__.py +42 -0
- package/python/vendor/baostock/common/__init__.py +0 -0
- package/python/vendor/baostock/common/contants.py +189 -0
- package/python/vendor/baostock/common/context.py +4 -0
- package/python/vendor/baostock/corpreport/__init__.py +0 -0
- package/python/vendor/baostock/corpreport/corp_performance.py +202 -0
- package/python/vendor/baostock/data/__init__.py +0 -0
- package/python/vendor/baostock/data/messageheader.py +17 -0
- package/python/vendor/baostock/data/msg.py +21 -0
- package/python/vendor/baostock/data/resultset.py +200 -0
- package/python/vendor/baostock/demo/__init__.py +0 -0
- package/python/vendor/baostock/demo/demo_A_stock_5mk-data.py +34 -0
- package/python/vendor/baostock/demo/demo_A_stock_k_data.py +36 -0
- package/python/vendor/baostock/demo/demo_AllStock.py +27 -0
- package/python/vendor/baostock/demo/demo_Balance_data.py +22 -0
- package/python/vendor/baostock/demo/demo_CashFlow_data.py +22 -0
- package/python/vendor/baostock/demo/demo_Dividend_data.py +35 -0
- package/python/vendor/baostock/demo/demo_Dupont_data.py +25 -0
- package/python/vendor/baostock/demo/demo_Forecast_report.py +24 -0
- package/python/vendor/baostock/demo/demo_Growth_data.py +22 -0
- package/python/vendor/baostock/demo/demo_Index_k_data.py +39 -0
- package/python/vendor/baostock/demo/demo_Operation_data.py +22 -0
- package/python/vendor/baostock/demo/demo_PerformanceExpress_report.py +25 -0
- package/python/vendor/baostock/demo/demo_Profit_data.py +22 -0
- package/python/vendor/baostock/demo/demo_TradeDates.py +27 -0
- package/python/vendor/baostock/demo/demo_adjust_factor_data.py +23 -0
- package/python/vendor/baostock/demo/demo_assignDayData.py +23 -0
- package/python/vendor/baostock/demo/demo_daily_adjust_factor_data.py +28 -0
- package/python/vendor/baostock/demo/demo_daily_k_4_AStock.py +28 -0
- package/python/vendor/baostock/demo/demo_daily_k_4_ETF.py +28 -0
- package/python/vendor/baostock/demo/demo_depositRate_data.py +26 -0
- package/python/vendor/baostock/demo/demo_hs300_stocks.py +26 -0
- package/python/vendor/baostock/demo/demo_loanRate_data.py +26 -0
- package/python/vendor/baostock/demo/demo_moneySupplyDataMonth_data.py +26 -0
- package/python/vendor/baostock/demo/demo_moneySupplyDataYear_data.py +26 -0
- package/python/vendor/baostock/demo/demo_requiredReserveRatio_data.py +26 -0
- package/python/vendor/baostock/demo/demo_set_API_key.py +37 -0
- package/python/vendor/baostock/demo/demo_stockBasic_data.py +27 -0
- package/python/vendor/baostock/demo/demo_stock_Valuation_indicator_data.py +34 -0
- package/python/vendor/baostock/demo/demo_stock_industry.py +26 -0
- package/python/vendor/baostock/demo/demo_sz50stocks.py +26 -0
- package/python/vendor/baostock/demo/demo_zz500_stock.py +26 -0
- package/python/vendor/baostock/evaluation/__init__.py +0 -0
- package/python/vendor/baostock/evaluation/season_index.py +758 -0
- package/python/vendor/baostock/login/__init__.py +0 -0
- package/python/vendor/baostock/login/loginout.py +230 -0
- package/python/vendor/baostock/macroscopic/__init__.py +0 -0
- package/python/vendor/baostock/macroscopic/economic_data.py +723 -0
- package/python/vendor/baostock/metadata/__init__.py +0 -0
- package/python/vendor/baostock/metadata/stock_metadata.py +207 -0
- package/python/vendor/baostock/security/__init__.py +0 -0
- package/python/vendor/baostock/security/history.py +265 -0
- package/python/vendor/baostock/security/sectorinfo.py +1024 -0
- package/python/vendor/baostock/util/__init__.py +0 -0
- package/python/vendor/baostock/util/socketutil.py +97 -0
- package/python/vendor/baostock/util/stringutil.py +83 -0
- package/python/vendor/et_xmlfile/LICENSE +23 -0
- package/python/vendor/et_xmlfile/LICENSE.python +298 -0
- package/python/vendor/et_xmlfile/__init__.py +8 -0
- package/python/vendor/et_xmlfile/incremental_tree.py +917 -0
- package/python/vendor/et_xmlfile/xmlfile.py +158 -0
- package/python/vendor/openpyxl/LICENSE +23 -0
- package/python/vendor/openpyxl/__init__.py +19 -0
- package/python/vendor/openpyxl/_constants.py +13 -0
- package/python/vendor/openpyxl/cell/__init__.py +4 -0
- package/python/vendor/openpyxl/cell/_writer.py +136 -0
- package/python/vendor/openpyxl/cell/cell.py +332 -0
- package/python/vendor/openpyxl/cell/read_only.py +136 -0
- package/python/vendor/openpyxl/cell/rich_text.py +202 -0
- package/python/vendor/openpyxl/cell/text.py +184 -0
- package/python/vendor/openpyxl/chart/_3d.py +105 -0
- package/python/vendor/openpyxl/chart/__init__.py +19 -0
- package/python/vendor/openpyxl/chart/_chart.py +199 -0
- package/python/vendor/openpyxl/chart/area_chart.py +106 -0
- package/python/vendor/openpyxl/chart/axis.py +401 -0
- package/python/vendor/openpyxl/chart/bar_chart.py +144 -0
- package/python/vendor/openpyxl/chart/bubble_chart.py +67 -0
- package/python/vendor/openpyxl/chart/chartspace.py +195 -0
- package/python/vendor/openpyxl/chart/data_source.py +246 -0
- package/python/vendor/openpyxl/chart/descriptors.py +43 -0
- package/python/vendor/openpyxl/chart/error_bar.py +62 -0
- package/python/vendor/openpyxl/chart/label.py +127 -0
- package/python/vendor/openpyxl/chart/layout.py +74 -0
- package/python/vendor/openpyxl/chart/legend.py +75 -0
- package/python/vendor/openpyxl/chart/line_chart.py +129 -0
- package/python/vendor/openpyxl/chart/marker.py +90 -0
- package/python/vendor/openpyxl/chart/picture.py +35 -0
- package/python/vendor/openpyxl/chart/pie_chart.py +177 -0
- package/python/vendor/openpyxl/chart/pivot.py +65 -0
- package/python/vendor/openpyxl/chart/plotarea.py +162 -0
- package/python/vendor/openpyxl/chart/print_settings.py +57 -0
- package/python/vendor/openpyxl/chart/radar_chart.py +55 -0
- package/python/vendor/openpyxl/chart/reader.py +32 -0
- package/python/vendor/openpyxl/chart/reference.py +124 -0
- package/python/vendor/openpyxl/chart/scatter_chart.py +53 -0
- package/python/vendor/openpyxl/chart/series.py +197 -0
- package/python/vendor/openpyxl/chart/series_factory.py +41 -0
- package/python/vendor/openpyxl/chart/shapes.py +89 -0
- package/python/vendor/openpyxl/chart/stock_chart.py +54 -0
- package/python/vendor/openpyxl/chart/surface_chart.py +119 -0
- package/python/vendor/openpyxl/chart/text.py +78 -0
- package/python/vendor/openpyxl/chart/title.py +76 -0
- package/python/vendor/openpyxl/chart/trendline.py +98 -0
- package/python/vendor/openpyxl/chart/updown_bars.py +31 -0
- package/python/vendor/openpyxl/chartsheet/__init__.py +3 -0
- package/python/vendor/openpyxl/chartsheet/chartsheet.py +107 -0
- package/python/vendor/openpyxl/chartsheet/custom.py +61 -0
- package/python/vendor/openpyxl/chartsheet/properties.py +28 -0
- package/python/vendor/openpyxl/chartsheet/protection.py +41 -0
- package/python/vendor/openpyxl/chartsheet/publish.py +58 -0
- package/python/vendor/openpyxl/chartsheet/relation.py +97 -0
- package/python/vendor/openpyxl/chartsheet/views.py +51 -0
- package/python/vendor/openpyxl/comments/__init__.py +4 -0
- package/python/vendor/openpyxl/comments/author.py +21 -0
- package/python/vendor/openpyxl/comments/comment_sheet.py +211 -0
- package/python/vendor/openpyxl/comments/comments.py +62 -0
- package/python/vendor/openpyxl/comments/shape_writer.py +112 -0
- package/python/vendor/openpyxl/compat/__init__.py +54 -0
- package/python/vendor/openpyxl/compat/abc.py +8 -0
- package/python/vendor/openpyxl/compat/numbers.py +43 -0
- package/python/vendor/openpyxl/compat/product.py +17 -0
- package/python/vendor/openpyxl/compat/singleton.py +40 -0
- package/python/vendor/openpyxl/compat/strings.py +25 -0
- package/python/vendor/openpyxl/descriptors/__init__.py +58 -0
- package/python/vendor/openpyxl/descriptors/base.py +272 -0
- package/python/vendor/openpyxl/descriptors/container.py +41 -0
- package/python/vendor/openpyxl/descriptors/excel.py +112 -0
- package/python/vendor/openpyxl/descriptors/namespace.py +12 -0
- package/python/vendor/openpyxl/descriptors/nested.py +129 -0
- package/python/vendor/openpyxl/descriptors/sequence.py +136 -0
- package/python/vendor/openpyxl/descriptors/serialisable.py +240 -0
- package/python/vendor/openpyxl/descriptors/slots.py +18 -0
- package/python/vendor/openpyxl/drawing/__init__.py +4 -0
- package/python/vendor/openpyxl/drawing/colors.py +435 -0
- package/python/vendor/openpyxl/drawing/connector.py +144 -0
- package/python/vendor/openpyxl/drawing/drawing.py +92 -0
- package/python/vendor/openpyxl/drawing/effect.py +407 -0
- package/python/vendor/openpyxl/drawing/fill.py +425 -0
- package/python/vendor/openpyxl/drawing/geometry.py +584 -0
- package/python/vendor/openpyxl/drawing/graphic.py +177 -0
- package/python/vendor/openpyxl/drawing/image.py +65 -0
- package/python/vendor/openpyxl/drawing/line.py +144 -0
- package/python/vendor/openpyxl/drawing/picture.py +144 -0
- package/python/vendor/openpyxl/drawing/properties.py +174 -0
- package/python/vendor/openpyxl/drawing/relation.py +17 -0
- package/python/vendor/openpyxl/drawing/spreadsheet_drawing.py +382 -0
- package/python/vendor/openpyxl/drawing/text.py +717 -0
- package/python/vendor/openpyxl/drawing/xdr.py +33 -0
- package/python/vendor/openpyxl/formatting/__init__.py +3 -0
- package/python/vendor/openpyxl/formatting/formatting.py +114 -0
- package/python/vendor/openpyxl/formatting/rule.py +291 -0
- package/python/vendor/openpyxl/formula/__init__.py +3 -0
- package/python/vendor/openpyxl/formula/tokenizer.py +446 -0
- package/python/vendor/openpyxl/formula/translate.py +166 -0
- package/python/vendor/openpyxl/packaging/__init__.py +3 -0
- package/python/vendor/openpyxl/packaging/core.py +115 -0
- package/python/vendor/openpyxl/packaging/custom.py +289 -0
- package/python/vendor/openpyxl/packaging/extended.py +137 -0
- package/python/vendor/openpyxl/packaging/interface.py +56 -0
- package/python/vendor/openpyxl/packaging/manifest.py +194 -0
- package/python/vendor/openpyxl/packaging/relationship.py +158 -0
- package/python/vendor/openpyxl/packaging/workbook.py +185 -0
- package/python/vendor/openpyxl/pivot/__init__.py +1 -0
- package/python/vendor/openpyxl/pivot/cache.py +965 -0
- package/python/vendor/openpyxl/pivot/fields.py +326 -0
- package/python/vendor/openpyxl/pivot/record.py +111 -0
- package/python/vendor/openpyxl/pivot/table.py +1261 -0
- package/python/vendor/openpyxl/reader/__init__.py +1 -0
- package/python/vendor/openpyxl/reader/drawings.py +71 -0
- package/python/vendor/openpyxl/reader/excel.py +349 -0
- package/python/vendor/openpyxl/reader/strings.py +44 -0
- package/python/vendor/openpyxl/reader/workbook.py +133 -0
- package/python/vendor/openpyxl/styles/__init__.py +11 -0
- package/python/vendor/openpyxl/styles/alignment.py +62 -0
- package/python/vendor/openpyxl/styles/borders.py +103 -0
- package/python/vendor/openpyxl/styles/builtins.py +1397 -0
- package/python/vendor/openpyxl/styles/cell_style.py +206 -0
- package/python/vendor/openpyxl/styles/colors.py +172 -0
- package/python/vendor/openpyxl/styles/differential.py +95 -0
- package/python/vendor/openpyxl/styles/fills.py +224 -0
- package/python/vendor/openpyxl/styles/fonts.py +113 -0
- package/python/vendor/openpyxl/styles/named_styles.py +282 -0
- package/python/vendor/openpyxl/styles/numbers.py +200 -0
- package/python/vendor/openpyxl/styles/protection.py +17 -0
- package/python/vendor/openpyxl/styles/proxy.py +62 -0
- package/python/vendor/openpyxl/styles/styleable.py +151 -0
- package/python/vendor/openpyxl/styles/stylesheet.py +274 -0
- package/python/vendor/openpyxl/styles/table.py +94 -0
- package/python/vendor/openpyxl/utils/__init__.py +17 -0
- package/python/vendor/openpyxl/utils/bound_dictionary.py +26 -0
- package/python/vendor/openpyxl/utils/cell.py +240 -0
- package/python/vendor/openpyxl/utils/dataframe.py +87 -0
- package/python/vendor/openpyxl/utils/datetime.py +140 -0
- package/python/vendor/openpyxl/utils/escape.py +43 -0
- package/python/vendor/openpyxl/utils/exceptions.py +34 -0
- package/python/vendor/openpyxl/utils/formulas.py +24 -0
- package/python/vendor/openpyxl/utils/indexed_list.py +49 -0
- package/python/vendor/openpyxl/utils/inference.py +60 -0
- package/python/vendor/openpyxl/utils/protection.py +22 -0
- package/python/vendor/openpyxl/utils/units.py +108 -0
- package/python/vendor/openpyxl/workbook/__init__.py +4 -0
- package/python/vendor/openpyxl/workbook/_writer.py +197 -0
- package/python/vendor/openpyxl/workbook/child.py +166 -0
- package/python/vendor/openpyxl/workbook/defined_name.py +189 -0
- package/python/vendor/openpyxl/workbook/external_link/__init__.py +3 -0
- package/python/vendor/openpyxl/workbook/external_link/external.py +190 -0
- package/python/vendor/openpyxl/workbook/external_reference.py +18 -0
- package/python/vendor/openpyxl/workbook/function_group.py +36 -0
- package/python/vendor/openpyxl/workbook/properties.py +151 -0
- package/python/vendor/openpyxl/workbook/protection.py +163 -0
- package/python/vendor/openpyxl/workbook/smart_tags.py +56 -0
- package/python/vendor/openpyxl/workbook/views.py +155 -0
- package/python/vendor/openpyxl/workbook/web.py +98 -0
- package/python/vendor/openpyxl/workbook/workbook.py +438 -0
- package/python/vendor/openpyxl/worksheet/__init__.py +1 -0
- package/python/vendor/openpyxl/worksheet/_read_only.py +190 -0
- package/python/vendor/openpyxl/worksheet/_reader.py +472 -0
- package/python/vendor/openpyxl/worksheet/_write_only.py +160 -0
- package/python/vendor/openpyxl/worksheet/_writer.py +390 -0
- package/python/vendor/openpyxl/worksheet/cell_range.py +512 -0
- package/python/vendor/openpyxl/worksheet/cell_watch.py +34 -0
- package/python/vendor/openpyxl/worksheet/controls.py +107 -0
- package/python/vendor/openpyxl/worksheet/copier.py +70 -0
- package/python/vendor/openpyxl/worksheet/custom.py +35 -0
- package/python/vendor/openpyxl/worksheet/datavalidation.py +202 -0
- package/python/vendor/openpyxl/worksheet/dimensions.py +306 -0
- package/python/vendor/openpyxl/worksheet/drawing.py +14 -0
- package/python/vendor/openpyxl/worksheet/errors.py +93 -0
- package/python/vendor/openpyxl/worksheet/filters.py +486 -0
- package/python/vendor/openpyxl/worksheet/formula.py +51 -0
- package/python/vendor/openpyxl/worksheet/header_footer.py +270 -0
- package/python/vendor/openpyxl/worksheet/hyperlink.py +46 -0
- package/python/vendor/openpyxl/worksheet/merge.py +141 -0
- package/python/vendor/openpyxl/worksheet/ole.py +133 -0
- package/python/vendor/openpyxl/worksheet/page.py +174 -0
- package/python/vendor/openpyxl/worksheet/pagebreak.py +94 -0
- package/python/vendor/openpyxl/worksheet/picture.py +8 -0
- package/python/vendor/openpyxl/worksheet/print_settings.py +184 -0
- package/python/vendor/openpyxl/worksheet/properties.py +97 -0
- package/python/vendor/openpyxl/worksheet/protection.py +120 -0
- package/python/vendor/openpyxl/worksheet/related.py +17 -0
- package/python/vendor/openpyxl/worksheet/scenario.py +105 -0
- package/python/vendor/openpyxl/worksheet/smart_tag.py +78 -0
- package/python/vendor/openpyxl/worksheet/table.py +385 -0
- package/python/vendor/openpyxl/worksheet/views.py +155 -0
- package/python/vendor/openpyxl/worksheet/worksheet.py +907 -0
- package/python/vendor/openpyxl/writer/__init__.py +1 -0
- package/python/vendor/openpyxl/writer/excel.py +295 -0
- package/python/vendor/openpyxl/writer/theme.py +291 -0
- package/python/vendor/openpyxl/xml/__init__.py +42 -0
- package/python/vendor/openpyxl/xml/constants.py +129 -0
- package/python/vendor/openpyxl/xml/functions.py +87 -0
- package/watchlist/package.json +1 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
from array import array
|
|
4
|
+
|
|
5
|
+
from openpyxl.descriptors.serialisable import Serialisable
|
|
6
|
+
from openpyxl.descriptors import (
|
|
7
|
+
Typed,
|
|
8
|
+
Float,
|
|
9
|
+
Bool,
|
|
10
|
+
Integer,
|
|
11
|
+
Sequence,
|
|
12
|
+
)
|
|
13
|
+
from openpyxl.descriptors.excel import ExtensionList
|
|
14
|
+
from openpyxl.utils.indexed_list import IndexedList
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
from .alignment import Alignment
|
|
18
|
+
from .protection import Protection
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ArrayDescriptor:
|
|
22
|
+
|
|
23
|
+
def __init__(self, key):
|
|
24
|
+
self.key = key
|
|
25
|
+
|
|
26
|
+
def __get__(self, instance, cls):
|
|
27
|
+
return instance[self.key]
|
|
28
|
+
|
|
29
|
+
def __set__(self, instance, value):
|
|
30
|
+
instance[self.key] = value
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class StyleArray(array):
|
|
34
|
+
"""
|
|
35
|
+
Simplified named tuple with an array
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
__slots__ = ()
|
|
39
|
+
tagname = 'xf'
|
|
40
|
+
|
|
41
|
+
fontId = ArrayDescriptor(0)
|
|
42
|
+
fillId = ArrayDescriptor(1)
|
|
43
|
+
borderId = ArrayDescriptor(2)
|
|
44
|
+
numFmtId = ArrayDescriptor(3)
|
|
45
|
+
protectionId = ArrayDescriptor(4)
|
|
46
|
+
alignmentId = ArrayDescriptor(5)
|
|
47
|
+
pivotButton = ArrayDescriptor(6)
|
|
48
|
+
quotePrefix = ArrayDescriptor(7)
|
|
49
|
+
xfId = ArrayDescriptor(8)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def __new__(cls, args=[0]*9):
|
|
53
|
+
return array.__new__(cls, 'i', args)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def __hash__(self):
|
|
57
|
+
return hash(tuple(self))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def __copy__(self):
|
|
61
|
+
return StyleArray((self))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def __deepcopy__(self, memo):
|
|
65
|
+
return StyleArray((self))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class CellStyle(Serialisable):
|
|
69
|
+
|
|
70
|
+
tagname = "xf"
|
|
71
|
+
|
|
72
|
+
numFmtId = Integer()
|
|
73
|
+
fontId = Integer()
|
|
74
|
+
fillId = Integer()
|
|
75
|
+
borderId = Integer()
|
|
76
|
+
xfId = Integer(allow_none=True)
|
|
77
|
+
quotePrefix = Bool(allow_none=True)
|
|
78
|
+
pivotButton = Bool(allow_none=True)
|
|
79
|
+
applyNumberFormat = Bool(allow_none=True)
|
|
80
|
+
applyFont = Bool(allow_none=True)
|
|
81
|
+
applyFill = Bool(allow_none=True)
|
|
82
|
+
applyBorder = Bool(allow_none=True)
|
|
83
|
+
applyAlignment = Bool(allow_none=True)
|
|
84
|
+
applyProtection = Bool(allow_none=True)
|
|
85
|
+
alignment = Typed(expected_type=Alignment, allow_none=True)
|
|
86
|
+
protection = Typed(expected_type=Protection, allow_none=True)
|
|
87
|
+
extLst = Typed(expected_type=ExtensionList, allow_none=True)
|
|
88
|
+
|
|
89
|
+
__elements__ = ('alignment', 'protection')
|
|
90
|
+
__attrs__ = ("numFmtId", "fontId", "fillId", "borderId",
|
|
91
|
+
"applyAlignment", "applyProtection", "pivotButton", "quotePrefix", "xfId")
|
|
92
|
+
|
|
93
|
+
def __init__(self,
|
|
94
|
+
numFmtId=0,
|
|
95
|
+
fontId=0,
|
|
96
|
+
fillId=0,
|
|
97
|
+
borderId=0,
|
|
98
|
+
xfId=None,
|
|
99
|
+
quotePrefix=None,
|
|
100
|
+
pivotButton=None,
|
|
101
|
+
applyNumberFormat=None,
|
|
102
|
+
applyFont=None,
|
|
103
|
+
applyFill=None,
|
|
104
|
+
applyBorder=None,
|
|
105
|
+
applyAlignment=None,
|
|
106
|
+
applyProtection=None,
|
|
107
|
+
alignment=None,
|
|
108
|
+
protection=None,
|
|
109
|
+
extLst=None,
|
|
110
|
+
):
|
|
111
|
+
self.numFmtId = numFmtId
|
|
112
|
+
self.fontId = fontId
|
|
113
|
+
self.fillId = fillId
|
|
114
|
+
self.borderId = borderId
|
|
115
|
+
self.xfId = xfId
|
|
116
|
+
self.quotePrefix = quotePrefix
|
|
117
|
+
self.pivotButton = pivotButton
|
|
118
|
+
self.applyNumberFormat = applyNumberFormat
|
|
119
|
+
self.applyFont = applyFont
|
|
120
|
+
self.applyFill = applyFill
|
|
121
|
+
self.applyBorder = applyBorder
|
|
122
|
+
self.alignment = alignment
|
|
123
|
+
self.protection = protection
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def to_array(self):
|
|
127
|
+
"""
|
|
128
|
+
Convert to StyleArray
|
|
129
|
+
"""
|
|
130
|
+
style = StyleArray()
|
|
131
|
+
for k in ("fontId", "fillId", "borderId", "numFmtId", "pivotButton",
|
|
132
|
+
"quotePrefix", "xfId"):
|
|
133
|
+
v = getattr(self, k, 0)
|
|
134
|
+
if v is not None:
|
|
135
|
+
setattr(style, k, v)
|
|
136
|
+
return style
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@classmethod
|
|
140
|
+
def from_array(cls, style):
|
|
141
|
+
"""
|
|
142
|
+
Convert from StyleArray
|
|
143
|
+
"""
|
|
144
|
+
return cls(numFmtId=style.numFmtId, fontId=style.fontId,
|
|
145
|
+
fillId=style.fillId, borderId=style.borderId, xfId=style.xfId,
|
|
146
|
+
quotePrefix=style.quotePrefix, pivotButton=style.pivotButton,)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def applyProtection(self):
|
|
151
|
+
return self.protection is not None or None
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@property
|
|
155
|
+
def applyAlignment(self):
|
|
156
|
+
return self.alignment is not None or None
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class CellStyleList(Serialisable):
|
|
160
|
+
|
|
161
|
+
tagname = "cellXfs"
|
|
162
|
+
|
|
163
|
+
__attrs__ = ("count",)
|
|
164
|
+
|
|
165
|
+
count = Integer(allow_none=True)
|
|
166
|
+
xf = Sequence(expected_type=CellStyle)
|
|
167
|
+
alignment = Sequence(expected_type=Alignment)
|
|
168
|
+
protection = Sequence(expected_type=Protection)
|
|
169
|
+
|
|
170
|
+
__elements__ = ('xf',)
|
|
171
|
+
|
|
172
|
+
def __init__(self,
|
|
173
|
+
count=None,
|
|
174
|
+
xf=(),
|
|
175
|
+
):
|
|
176
|
+
self.xf = xf
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def count(self):
|
|
181
|
+
return len(self.xf)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def __getitem__(self, idx):
|
|
185
|
+
try:
|
|
186
|
+
return self.xf[idx]
|
|
187
|
+
except IndexError:
|
|
188
|
+
print((f"{idx} is out of range"))
|
|
189
|
+
return self.xf[idx]
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _to_array(self):
|
|
193
|
+
"""
|
|
194
|
+
Extract protection and alignments, convert to style array
|
|
195
|
+
"""
|
|
196
|
+
self.prots = IndexedList([Protection()])
|
|
197
|
+
self.alignments = IndexedList([Alignment()])
|
|
198
|
+
styles = [] # allow duplicates
|
|
199
|
+
for xf in self.xf:
|
|
200
|
+
style = xf.to_array()
|
|
201
|
+
if xf.alignment is not None:
|
|
202
|
+
style.alignmentId = self.alignments.add(xf.alignment)
|
|
203
|
+
if xf.protection is not None:
|
|
204
|
+
style.protectionId = self.prots.add(xf.protection)
|
|
205
|
+
styles.append(style)
|
|
206
|
+
return IndexedList(styles)
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from openpyxl.compat import safe_string
|
|
5
|
+
from openpyxl.descriptors import (
|
|
6
|
+
String,
|
|
7
|
+
Bool,
|
|
8
|
+
MinMax,
|
|
9
|
+
Integer,
|
|
10
|
+
Typed,
|
|
11
|
+
)
|
|
12
|
+
from openpyxl.descriptors.sequence import NestedSequence
|
|
13
|
+
from openpyxl.descriptors.serialisable import Serialisable
|
|
14
|
+
|
|
15
|
+
# Default Color Index as per 18.8.27 of ECMA Part 4
|
|
16
|
+
COLOR_INDEX = (
|
|
17
|
+
'00000000', '00FFFFFF', '00FF0000', '0000FF00', '000000FF', #0-4
|
|
18
|
+
'00FFFF00', '00FF00FF', '0000FFFF', '00000000', '00FFFFFF', #5-9
|
|
19
|
+
'00FF0000', '0000FF00', '000000FF', '00FFFF00', '00FF00FF', #10-14
|
|
20
|
+
'0000FFFF', '00800000', '00008000', '00000080', '00808000', #15-19
|
|
21
|
+
'00800080', '00008080', '00C0C0C0', '00808080', '009999FF', #20-24
|
|
22
|
+
'00993366', '00FFFFCC', '00CCFFFF', '00660066', '00FF8080', #25-29
|
|
23
|
+
'000066CC', '00CCCCFF', '00000080', '00FF00FF', '00FFFF00', #30-34
|
|
24
|
+
'0000FFFF', '00800080', '00800000', '00008080', '000000FF', #35-39
|
|
25
|
+
'0000CCFF', '00CCFFFF', '00CCFFCC', '00FFFF99', '0099CCFF', #40-44
|
|
26
|
+
'00FF99CC', '00CC99FF', '00FFCC99', '003366FF', '0033CCCC', #45-49
|
|
27
|
+
'0099CC00', '00FFCC00', '00FF9900', '00FF6600', '00666699', #50-54
|
|
28
|
+
'00969696', '00003366', '00339966', '00003300', '00333300', #55-59
|
|
29
|
+
'00993300', '00993366', '00333399', '00333333', #60-63
|
|
30
|
+
)
|
|
31
|
+
# indices 64 and 65 are reserved for the system foreground and background colours respectively
|
|
32
|
+
|
|
33
|
+
# Will remove these definitions in a future release
|
|
34
|
+
BLACK = COLOR_INDEX[0]
|
|
35
|
+
WHITE = COLOR_INDEX[1]
|
|
36
|
+
#RED = COLOR_INDEX[2]
|
|
37
|
+
#DARKRED = COLOR_INDEX[8]
|
|
38
|
+
BLUE = COLOR_INDEX[4]
|
|
39
|
+
#DARKBLUE = COLOR_INDEX[12]
|
|
40
|
+
#GREEN = COLOR_INDEX[3]
|
|
41
|
+
#DARKGREEN = COLOR_INDEX[9]
|
|
42
|
+
#YELLOW = COLOR_INDEX[5]
|
|
43
|
+
#DARKYELLOW = COLOR_INDEX[19]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
aRGB_REGEX = re.compile("^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6})$")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class RGB(Typed):
|
|
50
|
+
"""
|
|
51
|
+
Descriptor for aRGB values
|
|
52
|
+
If not supplied alpha is 00
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
expected_type = str
|
|
56
|
+
|
|
57
|
+
def __set__(self, instance, value):
|
|
58
|
+
if not self.allow_none:
|
|
59
|
+
m = aRGB_REGEX.match(value)
|
|
60
|
+
if m is None:
|
|
61
|
+
raise ValueError("Colors must be aRGB hex values")
|
|
62
|
+
if len(value) == 6:
|
|
63
|
+
value = "00" + value
|
|
64
|
+
super().__set__(instance, value)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class Color(Serialisable):
|
|
68
|
+
"""Named colors for use in styles."""
|
|
69
|
+
|
|
70
|
+
tagname = "color"
|
|
71
|
+
|
|
72
|
+
rgb = RGB()
|
|
73
|
+
indexed = Integer()
|
|
74
|
+
auto = Bool()
|
|
75
|
+
theme = Integer()
|
|
76
|
+
tint = MinMax(min=-1, max=1, expected_type=float)
|
|
77
|
+
type = String()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def __init__(self, rgb=BLACK, indexed=None, auto=None, theme=None, tint=0.0, index=None, type='rgb'):
|
|
81
|
+
if index is not None:
|
|
82
|
+
indexed = index
|
|
83
|
+
if indexed is not None:
|
|
84
|
+
self.type = 'indexed'
|
|
85
|
+
self.indexed = indexed
|
|
86
|
+
elif theme is not None:
|
|
87
|
+
self.type = 'theme'
|
|
88
|
+
self.theme = theme
|
|
89
|
+
elif auto is not None:
|
|
90
|
+
self.type = 'auto'
|
|
91
|
+
self.auto = auto
|
|
92
|
+
else:
|
|
93
|
+
self.rgb = rgb
|
|
94
|
+
self.type = 'rgb'
|
|
95
|
+
self.tint = tint
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def value(self):
|
|
99
|
+
return getattr(self, self.type)
|
|
100
|
+
|
|
101
|
+
@value.setter
|
|
102
|
+
def value(self, value):
|
|
103
|
+
setattr(self, self.type, value)
|
|
104
|
+
|
|
105
|
+
def __iter__(self):
|
|
106
|
+
attrs = [(self.type, self.value)]
|
|
107
|
+
if self.tint != 0:
|
|
108
|
+
attrs.append(('tint', self.tint))
|
|
109
|
+
for k, v in attrs:
|
|
110
|
+
yield k, safe_string(v)
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def index(self):
|
|
114
|
+
# legacy
|
|
115
|
+
return self.value
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def __add__(self, other):
|
|
119
|
+
"""
|
|
120
|
+
Adding colours is undefined behaviour best do nothing
|
|
121
|
+
"""
|
|
122
|
+
if not isinstance(other, Color):
|
|
123
|
+
return super().__add__(other)
|
|
124
|
+
return self
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class ColorDescriptor(Typed):
|
|
128
|
+
|
|
129
|
+
expected_type = Color
|
|
130
|
+
|
|
131
|
+
def __set__(self, instance, value):
|
|
132
|
+
if isinstance(value, str):
|
|
133
|
+
value = Color(rgb=value)
|
|
134
|
+
super().__set__(instance, value)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class RgbColor(Serialisable):
|
|
138
|
+
|
|
139
|
+
tagname = "rgbColor"
|
|
140
|
+
|
|
141
|
+
rgb = RGB()
|
|
142
|
+
|
|
143
|
+
def __init__(self,
|
|
144
|
+
rgb=None,
|
|
145
|
+
):
|
|
146
|
+
self.rgb = rgb
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class ColorList(Serialisable):
|
|
150
|
+
|
|
151
|
+
tagname = "colors"
|
|
152
|
+
|
|
153
|
+
indexedColors = NestedSequence(expected_type=RgbColor)
|
|
154
|
+
mruColors = NestedSequence(expected_type=Color)
|
|
155
|
+
|
|
156
|
+
__elements__ = ('indexedColors', 'mruColors')
|
|
157
|
+
|
|
158
|
+
def __init__(self,
|
|
159
|
+
indexedColors=(),
|
|
160
|
+
mruColors=(),
|
|
161
|
+
):
|
|
162
|
+
self.indexedColors = indexedColors
|
|
163
|
+
self.mruColors = mruColors
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def __bool__(self):
|
|
167
|
+
return bool(self.indexedColors) or bool(self.mruColors)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def index(self):
|
|
172
|
+
return [val.rgb for val in self.indexedColors]
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
2
|
+
|
|
3
|
+
from openpyxl.descriptors import (
|
|
4
|
+
Typed,
|
|
5
|
+
Sequence,
|
|
6
|
+
Alias,
|
|
7
|
+
)
|
|
8
|
+
from openpyxl.descriptors.serialisable import Serialisable
|
|
9
|
+
from openpyxl.styles import (
|
|
10
|
+
Font,
|
|
11
|
+
Fill,
|
|
12
|
+
Border,
|
|
13
|
+
Alignment,
|
|
14
|
+
Protection,
|
|
15
|
+
)
|
|
16
|
+
from .numbers import NumberFormat
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DifferentialStyle(Serialisable):
|
|
20
|
+
|
|
21
|
+
tagname = "dxf"
|
|
22
|
+
|
|
23
|
+
__elements__ = ("font", "numFmt", "fill", "alignment", "border", "protection")
|
|
24
|
+
|
|
25
|
+
font = Typed(expected_type=Font, allow_none=True)
|
|
26
|
+
numFmt = Typed(expected_type=NumberFormat, allow_none=True)
|
|
27
|
+
fill = Typed(expected_type=Fill, allow_none=True)
|
|
28
|
+
alignment = Typed(expected_type=Alignment, allow_none=True)
|
|
29
|
+
border = Typed(expected_type=Border, allow_none=True)
|
|
30
|
+
protection = Typed(expected_type=Protection, allow_none=True)
|
|
31
|
+
|
|
32
|
+
def __init__(self,
|
|
33
|
+
font=None,
|
|
34
|
+
numFmt=None,
|
|
35
|
+
fill=None,
|
|
36
|
+
alignment=None,
|
|
37
|
+
border=None,
|
|
38
|
+
protection=None,
|
|
39
|
+
extLst=None,
|
|
40
|
+
):
|
|
41
|
+
self.font = font
|
|
42
|
+
self.numFmt = numFmt
|
|
43
|
+
self.fill = fill
|
|
44
|
+
self.alignment = alignment
|
|
45
|
+
self.border = border
|
|
46
|
+
self.protection = protection
|
|
47
|
+
self.extLst = extLst
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class DifferentialStyleList(Serialisable):
|
|
51
|
+
"""
|
|
52
|
+
Dedupable container for differential styles.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
tagname = "dxfs"
|
|
56
|
+
|
|
57
|
+
dxf = Sequence(expected_type=DifferentialStyle)
|
|
58
|
+
styles = Alias("dxf")
|
|
59
|
+
__attrs__ = ("count",)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def __init__(self, dxf=(), count=None):
|
|
63
|
+
self.dxf = dxf
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def append(self, dxf):
|
|
67
|
+
"""
|
|
68
|
+
Check to see whether style already exists and append it if does not.
|
|
69
|
+
"""
|
|
70
|
+
if not isinstance(dxf, DifferentialStyle):
|
|
71
|
+
raise TypeError('expected ' + str(DifferentialStyle))
|
|
72
|
+
if dxf in self.styles:
|
|
73
|
+
return
|
|
74
|
+
self.styles.append(dxf)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def add(self, dxf):
|
|
78
|
+
"""
|
|
79
|
+
Add a differential style and return its index
|
|
80
|
+
"""
|
|
81
|
+
self.append(dxf)
|
|
82
|
+
return self.styles.index(dxf)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def __bool__(self):
|
|
86
|
+
return bool(self.styles)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def __getitem__(self, idx):
|
|
90
|
+
return self.styles[idx]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def count(self):
|
|
95
|
+
return len(self.dxf)
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
|
|
2
|
+
# Copyright (c) 2010-2024 openpyxl
|
|
3
|
+
|
|
4
|
+
from openpyxl.descriptors import (
|
|
5
|
+
Float,
|
|
6
|
+
Set,
|
|
7
|
+
Alias,
|
|
8
|
+
NoneSet,
|
|
9
|
+
Sequence,
|
|
10
|
+
Integer,
|
|
11
|
+
MinMax,
|
|
12
|
+
)
|
|
13
|
+
from openpyxl.descriptors.serialisable import Serialisable
|
|
14
|
+
from openpyxl.compat import safe_string
|
|
15
|
+
|
|
16
|
+
from .colors import ColorDescriptor, Color
|
|
17
|
+
|
|
18
|
+
from openpyxl.xml.functions import Element, localname
|
|
19
|
+
from openpyxl.xml.constants import SHEET_MAIN_NS
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
FILL_NONE = 'none'
|
|
23
|
+
FILL_SOLID = 'solid'
|
|
24
|
+
FILL_PATTERN_DARKDOWN = 'darkDown'
|
|
25
|
+
FILL_PATTERN_DARKGRAY = 'darkGray'
|
|
26
|
+
FILL_PATTERN_DARKGRID = 'darkGrid'
|
|
27
|
+
FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal'
|
|
28
|
+
FILL_PATTERN_DARKTRELLIS = 'darkTrellis'
|
|
29
|
+
FILL_PATTERN_DARKUP = 'darkUp'
|
|
30
|
+
FILL_PATTERN_DARKVERTICAL = 'darkVertical'
|
|
31
|
+
FILL_PATTERN_GRAY0625 = 'gray0625'
|
|
32
|
+
FILL_PATTERN_GRAY125 = 'gray125'
|
|
33
|
+
FILL_PATTERN_LIGHTDOWN = 'lightDown'
|
|
34
|
+
FILL_PATTERN_LIGHTGRAY = 'lightGray'
|
|
35
|
+
FILL_PATTERN_LIGHTGRID = 'lightGrid'
|
|
36
|
+
FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal'
|
|
37
|
+
FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis'
|
|
38
|
+
FILL_PATTERN_LIGHTUP = 'lightUp'
|
|
39
|
+
FILL_PATTERN_LIGHTVERTICAL = 'lightVertical'
|
|
40
|
+
FILL_PATTERN_MEDIUMGRAY = 'mediumGray'
|
|
41
|
+
|
|
42
|
+
fills = (FILL_SOLID, FILL_PATTERN_DARKDOWN, FILL_PATTERN_DARKGRAY,
|
|
43
|
+
FILL_PATTERN_DARKGRID, FILL_PATTERN_DARKHORIZONTAL, FILL_PATTERN_DARKTRELLIS,
|
|
44
|
+
FILL_PATTERN_DARKUP, FILL_PATTERN_DARKVERTICAL, FILL_PATTERN_GRAY0625,
|
|
45
|
+
FILL_PATTERN_GRAY125, FILL_PATTERN_LIGHTDOWN, FILL_PATTERN_LIGHTGRAY,
|
|
46
|
+
FILL_PATTERN_LIGHTGRID, FILL_PATTERN_LIGHTHORIZONTAL,
|
|
47
|
+
FILL_PATTERN_LIGHTTRELLIS, FILL_PATTERN_LIGHTUP, FILL_PATTERN_LIGHTVERTICAL,
|
|
48
|
+
FILL_PATTERN_MEDIUMGRAY)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Fill(Serialisable):
|
|
52
|
+
|
|
53
|
+
"""Base class"""
|
|
54
|
+
|
|
55
|
+
tagname = "fill"
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def from_tree(cls, el):
|
|
59
|
+
children = [c for c in el]
|
|
60
|
+
if not children:
|
|
61
|
+
return
|
|
62
|
+
child = children[0]
|
|
63
|
+
if "patternFill" in child.tag:
|
|
64
|
+
return PatternFill._from_tree(child)
|
|
65
|
+
return super(Fill, GradientFill).from_tree(child)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class PatternFill(Fill):
|
|
69
|
+
"""Area fill patterns for use in styles.
|
|
70
|
+
Caution: if you do not specify a fill_type, other attributes will have
|
|
71
|
+
no effect !"""
|
|
72
|
+
|
|
73
|
+
tagname = "patternFill"
|
|
74
|
+
|
|
75
|
+
__elements__ = ('fgColor', 'bgColor')
|
|
76
|
+
|
|
77
|
+
patternType = NoneSet(values=fills)
|
|
78
|
+
fill_type = Alias("patternType")
|
|
79
|
+
fgColor = ColorDescriptor()
|
|
80
|
+
start_color = Alias("fgColor")
|
|
81
|
+
bgColor = ColorDescriptor()
|
|
82
|
+
end_color = Alias("bgColor")
|
|
83
|
+
|
|
84
|
+
def __init__(self, patternType=None, fgColor=Color(), bgColor=Color(),
|
|
85
|
+
fill_type=None, start_color=None, end_color=None):
|
|
86
|
+
if fill_type is not None:
|
|
87
|
+
patternType = fill_type
|
|
88
|
+
self.patternType = patternType
|
|
89
|
+
if start_color is not None:
|
|
90
|
+
fgColor = start_color
|
|
91
|
+
self.fgColor = fgColor
|
|
92
|
+
if end_color is not None:
|
|
93
|
+
bgColor = end_color
|
|
94
|
+
self.bgColor = bgColor
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
def _from_tree(cls, el):
|
|
98
|
+
attrib = dict(el.attrib)
|
|
99
|
+
for child in el:
|
|
100
|
+
desc = localname(child)
|
|
101
|
+
attrib[desc] = Color.from_tree(child)
|
|
102
|
+
return cls(**attrib)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def to_tree(self, tagname=None, idx=None):
|
|
106
|
+
parent = Element("fill")
|
|
107
|
+
el = Element(self.tagname)
|
|
108
|
+
if self.patternType is not None:
|
|
109
|
+
el.set('patternType', self.patternType)
|
|
110
|
+
for c in self.__elements__:
|
|
111
|
+
value = getattr(self, c)
|
|
112
|
+
if value != Color():
|
|
113
|
+
el.append(value.to_tree(c))
|
|
114
|
+
parent.append(el)
|
|
115
|
+
return parent
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
DEFAULT_EMPTY_FILL = PatternFill()
|
|
119
|
+
DEFAULT_GRAY_FILL = PatternFill(patternType='gray125')
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class Stop(Serialisable):
|
|
123
|
+
|
|
124
|
+
tagname = "stop"
|
|
125
|
+
|
|
126
|
+
position = MinMax(min=0, max=1)
|
|
127
|
+
color = ColorDescriptor()
|
|
128
|
+
|
|
129
|
+
def __init__(self, color, position):
|
|
130
|
+
self.position = position
|
|
131
|
+
self.color = color
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _assign_position(values):
|
|
135
|
+
"""
|
|
136
|
+
Automatically assign positions if a list of colours is provided.
|
|
137
|
+
|
|
138
|
+
It is not permitted to mix colours and stops
|
|
139
|
+
"""
|
|
140
|
+
n_values = len(values)
|
|
141
|
+
n_stops = sum(isinstance(value, Stop) for value in values)
|
|
142
|
+
|
|
143
|
+
if n_stops == 0:
|
|
144
|
+
interval = 1
|
|
145
|
+
if n_values > 2:
|
|
146
|
+
interval = 1 / (n_values - 1)
|
|
147
|
+
values = [Stop(value, i * interval)
|
|
148
|
+
for i, value in enumerate(values)]
|
|
149
|
+
|
|
150
|
+
elif n_stops < n_values:
|
|
151
|
+
raise ValueError('Cannot interpret mix of Stops and Colors in GradientFill')
|
|
152
|
+
|
|
153
|
+
pos = set()
|
|
154
|
+
for stop in values:
|
|
155
|
+
if stop.position in pos:
|
|
156
|
+
raise ValueError("Duplicate position {0}".format(stop.position))
|
|
157
|
+
pos.add(stop.position)
|
|
158
|
+
|
|
159
|
+
return values
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class StopList(Sequence):
|
|
163
|
+
|
|
164
|
+
expected_type = Stop
|
|
165
|
+
|
|
166
|
+
def __set__(self, obj, values):
|
|
167
|
+
values = _assign_position(values)
|
|
168
|
+
super().__set__(obj, values)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class GradientFill(Fill):
|
|
172
|
+
"""Fill areas with gradient
|
|
173
|
+
|
|
174
|
+
Two types of gradient fill are supported:
|
|
175
|
+
|
|
176
|
+
- A type='linear' gradient interpolates colours between
|
|
177
|
+
a set of specified Stops, across the length of an area.
|
|
178
|
+
The gradient is left-to-right by default, but this
|
|
179
|
+
orientation can be modified with the degree
|
|
180
|
+
attribute. A list of Colors can be provided instead
|
|
181
|
+
and they will be positioned with equal distance between them.
|
|
182
|
+
|
|
183
|
+
- A type='path' gradient applies a linear gradient from each
|
|
184
|
+
edge of the area. Attributes top, right, bottom, left specify
|
|
185
|
+
the extent of fill from the respective borders. Thus top="0.2"
|
|
186
|
+
will fill the top 20% of the cell.
|
|
187
|
+
|
|
188
|
+
"""
|
|
189
|
+
|
|
190
|
+
tagname = "gradientFill"
|
|
191
|
+
|
|
192
|
+
type = Set(values=('linear', 'path'))
|
|
193
|
+
fill_type = Alias("type")
|
|
194
|
+
degree = Float()
|
|
195
|
+
left = Float()
|
|
196
|
+
right = Float()
|
|
197
|
+
top = Float()
|
|
198
|
+
bottom = Float()
|
|
199
|
+
stop = StopList()
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def __init__(self, type="linear", degree=0, left=0, right=0, top=0,
|
|
203
|
+
bottom=0, stop=()):
|
|
204
|
+
self.degree = degree
|
|
205
|
+
self.left = left
|
|
206
|
+
self.right = right
|
|
207
|
+
self.top = top
|
|
208
|
+
self.bottom = bottom
|
|
209
|
+
self.stop = stop
|
|
210
|
+
self.type = type
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def __iter__(self):
|
|
214
|
+
for attr in self.__attrs__:
|
|
215
|
+
value = getattr(self, attr)
|
|
216
|
+
if value:
|
|
217
|
+
yield attr, safe_string(value)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def to_tree(self, tagname=None, namespace=None, idx=None):
|
|
221
|
+
parent = Element("fill")
|
|
222
|
+
el = super().to_tree()
|
|
223
|
+
parent.append(el)
|
|
224
|
+
return parent
|