Mercurial > jouvence
comparison fontaine/document.py @ 1:74b83e3d921e
Add more states, add more tests.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 02 Jan 2017 21:54:59 -0800 |
parents | 243401c49520 |
children | 59fe8cb6190d |
comparison
equal
deleted
inserted
replaced
0:243401c49520 | 1:74b83e3d921e |
---|---|
44 module = sys.modules[__name__] | 44 module = sys.modules[__name__] |
45 add_type = getattr(module, | 45 add_type = getattr(module, |
46 'TYPE_%s' % add_type_name.upper()) | 46 'TYPE_%s' % add_type_name.upper()) |
47 | 47 |
48 def _type_adder(_text): | 48 def _type_adder(_text): |
49 self.paragraphs.append( | 49 new_p = FontaineSceneElement(add_type, _text) |
50 FontaineSceneElement(add_type, _text)) | 50 self.paragraphs.append(new_p) |
51 return new_p | |
51 | 52 |
52 adder = _type_adder | 53 adder = _type_adder |
53 self._adders[add_type_name] = adder | 54 self._adders[add_type_name] = adder |
54 return adder | 55 return adder |
55 else: | 56 else: |
56 raise AttributeError | 57 raise AttributeError |
58 | |
59 def addPageBreak(self): | |
60 self.paragraphs.append(FontaineSceneElement(TYPE_PAGEBREAK, None)) | |
57 | 61 |
58 def lastParagraph(self): | 62 def lastParagraph(self): |
59 try: | 63 try: |
60 return self.paragraphs[-1] | 64 return self.paragraphs[-1] |
61 except IndexError: | 65 except IndexError: |
72 _scene_element_type_str(self.type), | 76 _scene_element_type_str(self.type), |
73 _ellipsis(self.text, 15)) | 77 _ellipsis(self.text, 15)) |
74 | 78 |
75 | 79 |
76 TYPE_ACTION = 0 | 80 TYPE_ACTION = 0 |
77 TYPE_CHARACTER = 1 | 81 TYPE_CENTEREDACTION = 1 |
78 TYPE_DIALOG = 2 | 82 TYPE_CHARACTER = 2 |
79 TYPE_PARENTHETICAL = 3 | 83 TYPE_DIALOG = 3 |
84 TYPE_PARENTHETICAL = 4 | |
85 TYPE_TRANSITION = 5 | |
86 TYPE_LYRICS = 6 | |
87 TYPE_PAGEBREAK = 7 | |
80 | 88 |
81 | 89 |
82 def _scene_element_type_str(t): | 90 def _scene_element_type_str(t): |
83 if t == TYPE_ACTION: | 91 if t == TYPE_ACTION: |
84 return 'ACTION' | 92 return 'ACTION' |
93 if t == TYPE_CENTEREDACTION: | |
94 return 'CENTEREDACTION' | |
85 if t == TYPE_CHARACTER: | 95 if t == TYPE_CHARACTER: |
86 return 'CHARACTER' | 96 return 'CHARACTER' |
87 if t == TYPE_DIALOG: | 97 if t == TYPE_DIALOG: |
88 return 'DIALOG' | 98 return 'DIALOG' |
89 if t == TYPE_PARENTHETICAL: | 99 if t == TYPE_PARENTHETICAL: |
90 return 'PARENTHETICAL' | 100 return 'PARENTHETICAL' |
101 if t == TYPE_TRANSITION: | |
102 return 'TRANSITION' | |
103 if t == TYPE_LYRICS: | |
104 return 'LYRICS' | |
105 if t == TYPE_PAGEBREAK: | |
106 return 'PAGEBREAK' | |
91 raise NotImplementedError() | 107 raise NotImplementedError() |
92 | 108 |
93 | 109 |
94 def _ellipsis(text, length): | 110 def _ellipsis(text, length): |
95 if len(text) > length: | 111 if len(text) > length: |