comparison cagou/core/simple_xhtml.py @ 185:ab3f5173ef5c

chat, simple XHTML: font size adjustement
author Goffi <goffi@goffi.org>
date Fri, 11 May 2018 20:07:17 +0200
parents cd99f70ea592
children 1b835bcfa663
comparison
equal deleted inserted replaced
184:c63922860f80 185:ab3f5173ef5c
21 from sat.core import log as logging 21 from sat.core import log as logging
22 log = logging.getLogger(__name__) 22 log = logging.getLogger(__name__)
23 from kivy.uix.stacklayout import StackLayout 23 from kivy.uix.stacklayout import StackLayout
24 from kivy.uix.label import Label 24 from kivy.uix.label import Label
25 from kivy.utils import escape_markup 25 from kivy.utils import escape_markup
26 from kivy.metrics import sp
26 from kivy import properties 27 from kivy import properties
27 from xml.etree import ElementTree as ET 28 from xml.etree import ElementTree as ET
28 from sat_frontends.tools import css_color, strings as sat_strings 29 from sat_frontends.tools import css_color, strings as sat_strings
29 from cagou.core.image import AsyncImage 30 from cagou.core.image import AsyncImage
30 import webbrowser 31 import webbrowser
36 def __init__(self, text): 37 def __init__(self, text):
37 super(Escape, self).__init__(text) 38 super(Escape, self).__init__(text)
38 39
39 40
40 class SimpleXHTMLWidgetEscapedText(Label): 41 class SimpleXHTMLWidgetEscapedText(Label):
42
43 def on_parent(self, instance, parent):
44 self.font_size = parent.font_size
41 45
42 def _addUrlMarkup(self, text): 46 def _addUrlMarkup(self, text):
43 text_elts = [] 47 text_elts = []
44 idx = 0 48 idx = 0
45 links = 0 49 links = 0
77 url = self.ref_urls[ref] 81 url = self.ref_urls[ref]
78 webbrowser.open(url) 82 webbrowser.open(url)
79 83
80 84
81 class SimpleXHTMLWidgetText(Label): 85 class SimpleXHTMLWidgetText(Label):
82 pass 86
87 def on_parent(self, instance, parent):
88 self.font_size = parent.font_size
83 89
84 90
85 class SimpleXHTMLWidgetImage(AsyncImage): 91 class SimpleXHTMLWidgetImage(AsyncImage):
86 # following properties are desired height/width 92 # following properties are desired height/width
87 # i.e. the ones specified in height/width attributes of <img> 93 # i.e. the ones specified in height/width attributes of <img>
137 xhtml = properties.StringProperty() 143 xhtml = properties.StringProperty()
138 color = properties.ListProperty([1, 1, 1, 1]) 144 color = properties.ListProperty([1, 1, 1, 1])
139 # XXX: bold is only used for escaped text 145 # XXX: bold is only used for escaped text
140 bold = properties.BooleanProperty(False) 146 bold = properties.BooleanProperty(False)
141 content_width = properties.NumericProperty(0) 147 content_width = properties.NumericProperty(0)
148 font_size = properties.NumericProperty(sp(14))
142 149
143 # text/XHTML input 150 # text/XHTML input
144 151
145 def on_xhtml(self, instance, xhtml): 152 def on_xhtml(self, instance, xhtml):
146 """parse xhtml and set content accordingly 153 """parse xhtml and set content accordingly