Mercurial > libervia-desktop-kivy
comparison cagou/core/simple_xhtml.py @ 288:44752e8031f8
simple XHTML: fixed crash when parent is set to None + fixed bold restoration when escaped message is modified
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 28 Mar 2019 08:42:11 +0100 |
parents | ca4daced4638 |
children | 86b1cd8121dd |
comparison
equal
deleted
inserted
replaced
287:5d96bcd3bfec | 288:44752e8031f8 |
---|---|
39 | 39 |
40 | 40 |
41 class SimpleXHTMLWidgetEscapedText(Label): | 41 class SimpleXHTMLWidgetEscapedText(Label): |
42 | 42 |
43 def on_parent(self, instance, parent): | 43 def on_parent(self, instance, parent): |
44 self.font_size = parent.font_size | 44 if parent is not None: |
45 self.font_size = parent.font_size | |
45 | 46 |
46 def _addUrlMarkup(self, text): | 47 def _addUrlMarkup(self, text): |
47 text_elts = [] | 48 text_elts = [] |
48 idx = 0 | 49 idx = 0 |
49 links = 0 | 50 links = 0 |
150 # text/XHTML input | 151 # text/XHTML input |
151 | 152 |
152 def on_xhtml(self, instance, xhtml): | 153 def on_xhtml(self, instance, xhtml): |
153 """parse xhtml and set content accordingly | 154 """parse xhtml and set content accordingly |
154 | 155 |
155 if xhtml is an instance of Escape, a Label with not markup | 156 if xhtml is an instance of Escape, a Label with no markup will be used |
156 will be used | |
157 """ | 157 """ |
158 self.clear_widgets() | 158 self.clear_widgets() |
159 if isinstance(xhtml, Escape): | 159 if isinstance(xhtml, Escape): |
160 label = SimpleXHTMLWidgetEscapedText(text=xhtml, color=self.color) | 160 label = SimpleXHTMLWidgetEscapedText( |
161 text=xhtml, color=self.color, bold=self.bold) | |
161 self.bind(color=label.setter('color')) | 162 self.bind(color=label.setter('color')) |
162 self.bind(bold=label.setter('bold')) | 163 self.bind(bold=label.setter('bold')) |
163 self.add_widget(label) | 164 self.add_widget(label) |
164 else: | 165 else: |
165 xhtml = ET.fromstring(xhtml.encode('utf-8')) | 166 xhtml = ET.fromstring(xhtml.encode('utf-8')) |