-
Notifications
You must be signed in to change notification settings - Fork 10
/
help.py
68 lines (58 loc) · 2.16 KB
/
help.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
import wx
import wx.html
import webbrowser
import markdown2
class HelpDialog(wx.Dialog):
def __init__(self, helpFile, title='Temp'):
"""Constructor"""
wx.Dialog.__init__(self, None, title=title)
self.help = helpFile
self.InitUI()
self.SetSize((700, 600))
def InitUI(self):
self.panel = wx.Panel(self, wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
self.html = help = wx.html.HtmlWindow(self.panel, -1, style=wx.NO_BORDER)
# http://wxpython-users.1045709.n5.nabble.com/Open-a-URL-with-the-default-browser-from-an-HtmlWindow-td2326349.html
# Bind LINK Click Event to own Function
help.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkClicked)
#import codecs
#file = codecs.open(self.help, "r", "utf-8")
try:
file = open(self.help, "r")
except IOError:
dlgmsg = u"File not found: \"{}\"".format(self.help)
dlg = wx.MessageDialog(None, dlgmsg, "WPKG-GP Client", wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
self.Destroy()
else:
test = file.read().decode("utf-8")
html = markdown2.markdown(test, extras=["tables"])
html = '<body bgcolor="#f0f0f5">' + html
#print html
help.SetPage(html)
sizer.Add(help, 1, wx.EXPAND)
self.panel.SetSizerAndFit(sizer)
self.Bind(wx.EVT_CLOSE, self.OnClose)
def OnLinkClicked(self, link):
# If Link is an anchor link let the html window do its job
# If it is not an anchor link let the default browser open the page
href = link.GetLinkInfo().GetHref()
anchor = href[1:]
if href.startswith('#'):
self.html.ScrollToAnchor(anchor)
else:
wx.BeginBusyCursor()
webbrowser.open(href)
wx.EndBusyCursor()
def OnClose(self, e):
self.Destroy()
class MyApp(wx.App):
def OnInit(self):
frame = HelpDialog('help.md', title='WPKG-GP-Client - Help')
frame.Show(True)
return True
if __name__ == '__main__':
app = MyApp(0)
app.MainLoop()