Translated using Weblate.
[wammu.git] / Wammu / Displayer.py
blob44b0970f693311d83c94fc74a0389a5caf0ca786
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 HTML displayer with custom link handling
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright © 2003 - 2010 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 '''
26 import wx
27 import wx.html
28 import Wammu.Events
29 import Wammu.Utils
30 from Wammu.Locales import HtmlStrConv, StrConv
32 class Displayer(wx.html.HtmlWindow):
33 def __init__(self, parent, win):
34 wx.html.HtmlWindow.__init__(self, parent, -1)
35 self.win = win
37 def SetContent(self, text):
38 # default system colours
39 bgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_LISTBOX)
40 fgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
41 hfgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
43 colours = 'text="#%02x%02x%02x" bgcolor="#%02x%02x%02x" link="#%02x%02x%02x"' % (
44 fgc.Red(), fgc.Green(), fgc.Blue(),
45 bgc.Red(), bgc.Green(), bgc.Blue(),
46 hfgc.Red(), hfgc.Green(), hfgc.Blue())
48 pagefmt = u'<html><head><meta http-equiv="Content-Type" content="text/html; charset=%s"></head><body %s>%s</body></html>'
50 charset = 'ucs-2'
51 text = StrConv(text)
52 self.SetPage(pagefmt % (charset, colours, text))
55 def OnLinkClicked(self, linkinfo):
56 evt = Wammu.Events.LinkEvent(
57 link = linkinfo.GetHref()
59 wx.PostEvent(self.win, evt)