views:

127

answers:

0

How it is possible wxHtmlEasyPrinting to force to work with utf-8 encoding?

# -*- coding: utf-8 -*-

import wx
import wx.html as  html
import wx.lib.printout as printer

class MyFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size=(450, 500))

        wind = wx.SplitterWindow(self, -1)
        pan1 = wx.Panel(wind, -1)
        pan2 = wx.Panel(wind, -1)
        wind.SetMinSize((450,500))
        pan1.SetMinSize((450,425))
        pan2.SetMinSize((450,30))
        Font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
        wind.SplitHorizontally(pan1, pan2)
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)

        self.html = html.HtmlWindow(pan1, -1,
                                    style=wx.NO_FULL_REPAINT_ON_RESIZE)
        self.html.SetMinSize((450,425))

        self.printer = html.HtmlEasyPrinting()
        self.txt_date = u"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                <title>Печать документа</title>
            </head>
            <body><br><br>
                <h3>Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства</h3>
            </body>
        </html>"""
        self.html.SetPage(self.txt_date)

        self.btn1 = wx.Button(pan2, -1, u"Print")
        self.btn1.SetFont(Font)
        self.btn2 = wx.Button(pan2, -1, u"Close")
        self.btn2.SetFont(Font)

        wx.EVT_BUTTON(self, self.btn1.GetId(), self.on_print)
        wx.EVT_BUTTON(self, self.btn2.GetId(), self.on_close)

        pan1.SetSizer(sizer_1)
        pan2.SetSizer(sizer_2)

        sizer_1.Add(self.html, 0, wx.EXPAND)
        sizer_2.Add(self.btn1, -1, wx.EXPAND)
        sizer_2.Add(self.btn2, -1, wx.EXPAND)

    def on_print(self, evt):
        self.printer.GetPrintData().SetPaperId(wx.PAPER_LETTER)
        self.printer.PrintText(self.txt_date)
        evt.Skip()

    def on_close(self, evt):
        self.Destroy()
        evt.Skip()

class MyApp(wx.App):
    def OnInit(self):
        wx.InitAllImageHandlers()
        frame_1 = MyFrame(None, u"View HTML")
        self.SetTopWindow(frame_1)
        frame_1.Show()
        return True

if __name__ == "__main__":
    app = MyApp()
    app.MainLoop()

Ubuntu 10.04 wxpython 2.8.10.1