1 | #!/usr/bin/python |
---|
2 | """ |
---|
3 | Help panel for calculator |
---|
4 | """ |
---|
5 | import os |
---|
6 | import wx |
---|
7 | import wx.html as html |
---|
8 | from wx.lib.splitter import MultiSplitterWindow |
---|
9 | import sans.perspectives.calculator as calculator |
---|
10 | |
---|
11 | |
---|
12 | class HelpWindow(wx.Frame): |
---|
13 | """ |
---|
14 | """ |
---|
15 | def __init__(self, parent, title='HelpWindow', pageToOpen=None): |
---|
16 | wx.Frame.__init__(self, parent, title, size=(700, 450)) |
---|
17 | """ |
---|
18 | contains help info |
---|
19 | """ |
---|
20 | splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE) |
---|
21 | rpanel = wx.Panel(splitter, -1) |
---|
22 | lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN) |
---|
23 | |
---|
24 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
25 | header = wx.Panel(rpanel, -1) |
---|
26 | header.SetBackgroundColour('#6666FF') |
---|
27 | header.SetForegroundColour('WHITE') |
---|
28 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
29 | st = wx.StaticText(header, -1, 'Contents', (5, 5)) |
---|
30 | font = st.GetFont() |
---|
31 | font.SetPointSize(10) |
---|
32 | st.SetFont(font) |
---|
33 | hbox.Add(st, 1, wx.TOP | wx.BOTTOM | wx.LEFT, 5) |
---|
34 | header.SetSizer(hbox) |
---|
35 | vbox.Add(header, 0, wx.EXPAND) |
---|
36 | |
---|
37 | vboxl = wx.BoxSizer(wx.VERTICAL) |
---|
38 | headerl = wx.Panel(lpanel, -1, size=(-1, 20)) |
---|
39 | |
---|
40 | headerl.SetBackgroundColour('#6666FF') |
---|
41 | headerl.SetForegroundColour('WHITE') |
---|
42 | hboxl = wx.BoxSizer(wx.HORIZONTAL) |
---|
43 | lst = wx.StaticText(headerl, -1, 'Menu', (5, 5)) |
---|
44 | fontl = lst.GetFont() |
---|
45 | fontl.SetPointSize(10) |
---|
46 | lst.SetFont(fontl) |
---|
47 | hboxl.Add(lst, 1, wx.TOP | wx.BOTTOM | wx.LEFT, 5) |
---|
48 | headerl.SetSizer(hboxl) |
---|
49 | vboxl.Add(headerl, 0, wx.EXPAND) |
---|
50 | self.lhelp = html.HtmlWindow(lpanel, -1, style=wx.NO_BORDER) |
---|
51 | self.rhelp = html.HtmlWindow(rpanel, -1, style=wx.NO_BORDER, |
---|
52 | size=(500,-1)) |
---|
53 | |
---|
54 | self.path = calculator.get_data_path(media='media') |
---|
55 | |
---|
56 | page1 = """<html> |
---|
57 | <body> |
---|
58 | <p>Select topic on Menu</p> |
---|
59 | </body> |
---|
60 | </html>""" |
---|
61 | self.rhelp.SetPage(page1) |
---|
62 | page = """<html> |
---|
63 | <body> |
---|
64 | <ul> |
---|
65 | <li><a href ="sld_calculator_help.html" |
---|
66 | target ="showframe">SLD Calculator</a><br></li> |
---|
67 | <li><a href ="slit_calculator_help.html" |
---|
68 | target ="showframe">Slit Size Calculator</a><br></li> |
---|
69 | <li><a href ="kiessig_calculator_help.html" |
---|
70 | target ="showframe">Kiessig Thickness Calculator</a><br></li> |
---|
71 | <li><a href ="resolution_calculator_help.html" |
---|
72 | target ="showframe">Resolution Estimator</a><br></li> |
---|
73 | </ul> |
---|
74 | </body> |
---|
75 | </html>""" |
---|
76 | |
---|
77 | self.lhelp.SetPage(page) |
---|
78 | self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkClicked) |
---|
79 | |
---|
80 | vbox.Add(self.rhelp, 1, wx.EXPAND) |
---|
81 | vboxl.Add(self.lhelp, 1, wx.EXPAND) |
---|
82 | rpanel.SetSizer(vbox) |
---|
83 | lpanel.SetSizer(vboxl) |
---|
84 | lpanel.SetFocus() |
---|
85 | |
---|
86 | vbox1 = wx.BoxSizer(wx.HORIZONTAL) |
---|
87 | vbox1.Add(splitter, 1, wx.EXPAND) |
---|
88 | splitter.AppendWindow(lpanel, 200) |
---|
89 | splitter.AppendWindow(rpanel) |
---|
90 | self.SetSizer(vbox1) |
---|
91 | |
---|
92 | self.Centre() |
---|
93 | self.Show(True) |
---|
94 | |
---|
95 | def OnLinkClicked(self, event): |
---|
96 | """ |
---|
97 | Function to diplay html page related to the hyperlinktext selected |
---|
98 | """ |
---|
99 | link = event.GetLinkInfo().GetHref() |
---|
100 | link = os.path.join(self.path, link) |
---|
101 | self.rhelp.LoadPage(link) |
---|
102 | |
---|
103 | |
---|
104 | class ViewApp(wx.App): |
---|
105 | def OnInit(self): |
---|
106 | frame = HelpWindow(None, -1, 'HelpWindow') |
---|
107 | frame.Show(True) |
---|
108 | self.SetTopWindow(frame) |
---|
109 | return True |
---|
110 | |
---|
111 | if __name__ == "__main__": |
---|
112 | app = ViewApp(0) |
---|
113 | app.MainLoop() |
---|