-
Notifications
You must be signed in to change notification settings - Fork 21
/
HTML_tester.py
executable file
·133 lines (94 loc) · 3.48 KB
/
HTML_tester.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
"""
TA simple test app for wxHTML
It provides and easy way to test HTML, and how it is rendered by wxHtml
The wxHtml window automatically updates as you type in the text window.
Also tests printing.
"""
## some sample html to start with
body = ["<font size=%i> <p> text in size %i </p> </font>"%(i,i) for i in [10, 14, 16]]
HTML = """<html><body>
<h1> Header1: Very basic Sample HTML </h1>
<h2> Header 2: a test of fonts...</h2>
<tt>
<p> text default size</p>
<font size=10> <p> text in size 10 </p> </font>
<font size=16> <p> text in size 16 </p> </font>
</tt>
<h3> Header 3: a test of subscripts</h3>
H<sub>2</sub>O
<h4>Header 4:</h4>
<h5>Header 5:</h5>
<h6>Header 6:</h6>
</body></html>
"""
import wx
import wx.html
#-------------------------------------------------------------------
class MyHTMLWindow(wx.html.HtmlWindow):
"""
Not much need for a class here -- but maybe they'll be moreto add later
"""
def __init__(self, parent):
wx.html.HtmlWindow.__init__(self, parent,
style=wx.VSCROLL|wx.ALWAYS_SHOW_SB)
if "gtk2" in wx.PlatformInfo:
self.SetStandardFonts()
self.Show()
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
title = 'wxHtml Tester'
wx.Frame.__init__(self, *args, **kwargs)
self.htwindow = MyHTMLWindow(self)
self.InputWindow = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.InputWindow.SetFont(wx.Font(12,
wx.FONTFAMILY_TELETYPE,
wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL))
self.InputWindow.Value = HTML
self.InputWindow.Bind(wx.EVT_TEXT, self.OnTextChanged)
# lay out the frame
S = wx.BoxSizer(wx.HORIZONTAL)
S.Add(self.InputWindow, 3, wx.EXPAND)
S.Add(self.htwindow, 4, wx.EXPAND)
self.Printer = wx.html.HtmlEasyPrinting()
MenuBar = wx.MenuBar()
FileMenu = wx.Menu()
item = FileMenu.Append(wx.ID_EXIT, text = "&Exit")
self.Bind(wx.EVT_MENU, self.OnQuit, item)
item = FileMenu.Append(wx.ID_PRINT, text = "&Print")
self.Bind(wx.EVT_MENU, self.OnPrint, item)
item = FileMenu.Append(wx.ID_PRINT, text = "Print P&review")
self.Bind(wx.EVT_MENU, self.OnPreview, item)
MenuBar.Append(FileMenu, "&File")
self.SetMenuBar(MenuBar)
self.SetSizerAndFit(S)
wx.CallAfter(self.OnTextChanged)
def OnTextChanged(self, evt=None):
"""
Updates the HTML: called whenever there is a change in the input
text field.
Keeps the HtmlWindow scrolled to the same position as it was
"""
pos = self.htwindow.GetViewStart()
self.htwindow.Freeze()
self.htwindow.SetPage(self.InputWindow.Value)
self.htwindow.Scroll(*pos)
self.htwindow.Thaw()
def OnPrint(self, evt=None):
self.Printer.PrintText(self.InputWindow.Value, "HTML tester")
def OnPreview(self, evt=None):
self.Printer.PreviewText(self.InputWindow.Value)
def OnQuit(self,Event):
self.Destroy()
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, title="HTML Tester Window", size=(600, 500))
self.SetTopWindow(frame)
frame.Size = (900, 500)
frame.Centre()
frame.Show(True)
return True
if __name__ == "__main__" :
app = MyApp(0)
app.MainLoop()