Skip to content

Commit 45f2c64

Browse files
author
Steve Canny
committed
blkct: introduce BlockItemContainer
* base _Body on BlockItemContainer * no substantial inheritence yet, just getting it wired up
1 parent 235e2f1 commit 45f2c64

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

docx/blkcntnr.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Block item container, used by body, cell, header, etc. Block level items are
5+
things like paragraph and table, although there are a few other specialized
6+
ones like structured document tags.
7+
"""
8+
9+
from __future__ import absolute_import, print_function
10+
11+
from .shared import Parented
12+
13+
14+
class BlockItemContainer(Parented):
15+
"""
16+
Base class for proxy objects that can contain block items, such as _Body,
17+
_Cell, header, footer, footnote, endnote, comment, and text box objects.
18+
Provides the shared functionality to add a block item like a paragraph or
19+
table.
20+
"""
21+
def __init__(self, element, parent):
22+
super(BlockItemContainer, self).__init__(parent)
23+
self._element = element

docx/parts/document.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from collections import Sequence
1212

13+
from ..blkcntnr import BlockItemContainer
1314
from ..enum.section import WD_SECTION
1415
from ..opc.constants import RELATIONSHIP_TYPE as RT
1516
from ..opc.package import XmlPart
@@ -113,13 +114,13 @@ def tables(self):
113114
return self.body.tables
114115

115116

116-
class _Body(Parented):
117+
class _Body(BlockItemContainer):
117118
"""
118119
Proxy for ``<w:body>`` element in this document, having primarily a
119120
container role.
120121
"""
121122
def __init__(self, body_elm, parent):
122-
super(_Body, self).__init__(parent)
123+
super(_Body, self).__init__(body_elm, parent)
123124
self._body = body_elm
124125

125126
def add_paragraph(self, text='', style=None):

0 commit comments

Comments
 (0)