# Path: Wammu/Locales.py
# def StrConv(txt):
#     """
#     This function coverts something (txt) to string form usable by wxPython. There
#     is problem that in default configuration in most distros (maybe all) default
#     encoding for unicode objects is ascii. This leads to exception when converting
#     something different than ascii. And this exception is not catched inside
#     wxPython and leads to segfault.
# 
#     So if wxPython supports unicode, we give it unicode, otherwise locale
#     dependant text.
#     """
#     try:
#         if isinstance(txt, unicode):
#             return txt
#         elif isinstance(txt, str):
#             return unicode(txt, LOCALE_CHARSET)
#         return str(txt)
#     except UnicodeEncodeError:
#         return '???'


import wx
import wx.html
import Wammu.Events
import Wammu.Utils
from Wammu.Locales import StrConv
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
'''
Wammu - Phone manager
HTML displayer with custom link handling
'''
from __future__ import unicode_literals



class Displayer(wx.html.HtmlWindow):
    def __init__(self, parent, win):
        wx.html.HtmlWindow.__init__(self, parent, -1)
        self.win = win

    def SetContent(self, text):
        # default system colours
        bgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_LISTBOX)
        fgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
        hfgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)

        colours = 'text="#%02x%02x%02x" bgcolor="#%02x%02x%02x" link="#%02x%02x%02x"' % (
            fgc.Red(), fgc.Green(), fgc.Blue(),
            bgc.Red(), bgc.Green(), bgc.Blue(),
            hfgc.Red(), hfgc.Green(), hfgc.Blue())

        pagefmt = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=%s"></head><body %s>%s</body></html>'

        charset = 'ucs-2'

# Path: Wammu/Locales.py
# def StrConv(txt):
#     """
#     This function coverts something (txt) to string form usable by wxPython. There
#     is problem that in default configuration in most distros (maybe all) default
#     encoding for unicode objects is ascii. This leads to exception when converting
#     something different than ascii. And this exception is not catched inside
#     wxPython and leads to segfault.
# 
#     So if wxPython supports unicode, we give it unicode, otherwise locale
#     dependant text.
#     """
#     try:
#         if isinstance(txt, unicode):
#             return txt
#         elif isinstance(txt, str):
#             return unicode(txt, LOCALE_CHARSET)
#         return str(txt)
#     except UnicodeEncodeError:
#         return '???'


# Path: Wammu/Displayer.py
import wx
import wx.html
import Wammu.Events
import Wammu.Utils
from Wammu.Locales import StrConv

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
'''
Wammu - Phone manager
HTML displayer with custom link handling
'''
from __future__ import unicode_literals



class Displayer(wx.html.HtmlWindow):
    def __init__(self, parent, win):
        wx.html.HtmlWindow.__init__(self, parent, -1)
        self.win = win

    def SetContent(self, text):
        # default system colours
        bgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_LISTBOX)
        fgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
        hfgc = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)

        colours = 'text="#%02x%02x%02x" bgcolor="#%02x%02x%02x" link="#%02x%02x%02x"' % (
            fgc.Red(), fgc.Green(), fgc.Blue(),
            bgc.Red(), bgc.Green(), bgc.Blue(),
            hfgc.Red(), hfgc.Green(), hfgc.Blue())

        pagefmt = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=%s"></head><body %s>%s</body></html>'

        charset = 'ucs-2'

        text = StrConv(text)