1 | #!/usr/bin/python |
---|
2 | |
---|
3 | import wx |
---|
4 | import wx.html as html |
---|
5 | from wx.lib.splitter import MultiSplitterWindow |
---|
6 | import os |
---|
7 | |
---|
8 | |
---|
9 | class HelpWindow(wx.Frame): |
---|
10 | """ |
---|
11 | """ |
---|
12 | def __init__(self, parent, id, title= 'HelpWindow', pageToOpen=None): |
---|
13 | wx.Frame.__init__(self, parent, id, title, size=(850, 530)) |
---|
14 | """ |
---|
15 | contains help info |
---|
16 | """ |
---|
17 | |
---|
18 | splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE) |
---|
19 | rpanel = wx.Panel(splitter, -1) |
---|
20 | lpanel = wx.Panel(splitter, -1,style=wx.BORDER_SUNKEN) |
---|
21 | |
---|
22 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
23 | header = wx.Panel(rpanel, -1) |
---|
24 | header.SetBackgroundColour('#6666FF') |
---|
25 | header.SetForegroundColour('WHITE') |
---|
26 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
27 | st = wx.StaticText(header, -1, 'Contents', (5, 5)) |
---|
28 | font = st.GetFont() |
---|
29 | font.SetPointSize(10) |
---|
30 | st.SetFont(font) |
---|
31 | hbox.Add(st, 1, wx.TOP | wx.BOTTOM | wx.LEFT, 5) |
---|
32 | header.SetSizer(hbox) |
---|
33 | vbox.Add(header, 0, wx.EXPAND) |
---|
34 | |
---|
35 | vboxl= wx.BoxSizer(wx.VERTICAL) |
---|
36 | headerl = wx.Panel(lpanel, -1, size=(-1, 20)) |
---|
37 | |
---|
38 | headerl.SetBackgroundColour('#6666FF') |
---|
39 | headerl.SetForegroundColour('WHITE') |
---|
40 | hboxl = wx.BoxSizer(wx.HORIZONTAL) |
---|
41 | lst = wx.StaticText(headerl, -1, 'Menu', (5, 5)) |
---|
42 | fontl = lst.GetFont() |
---|
43 | fontl.SetPointSize(10) |
---|
44 | lst.SetFont(fontl) |
---|
45 | hboxl.Add(lst, 1, wx.TOP | wx.BOTTOM | wx.LEFT, 5) |
---|
46 | headerl.SetSizer(hboxl) |
---|
47 | vboxl.Add(headerl, 0, wx.EXPAND) |
---|
48 | self.lhelp = html.HtmlWindow(lpanel, -1, style=wx.NO_BORDER) |
---|
49 | self.rhelp = html.HtmlWindow(rpanel, -1, style=wx.NO_BORDER, size=(500,-1)) |
---|
50 | |
---|
51 | # get the media path |
---|
52 | if pageToOpen != None: |
---|
53 | path = os.path.dirname(pageToOpen) |
---|
54 | else: |
---|
55 | from sans.models import get_data_path as model_path |
---|
56 | # Get models help model_function path |
---|
57 | path = model_path(media='media') |
---|
58 | |
---|
59 | self.path = os.path.join(path,"model_functions.html") |
---|
60 | self.path_pd = os.path.join(path,"pd_help.html") |
---|
61 | self.path_sm = os.path.join(path,"smear_computation.html") |
---|
62 | from sans.perspectives.fitting import get_data_path as fit_path |
---|
63 | fitting_path = fit_path(media='media') |
---|
64 | |
---|
65 | _html_file = {"status_bar_help.html":"Status Bar Help", |
---|
66 | "load_data_help.html":"Load a File", |
---|
67 | "simultaneous_fit_help.html":"Simultaneous Fit", |
---|
68 | "single_fit_help.html":"Single Fit", |
---|
69 | "model_use_help.html":"Model Selection", |
---|
70 | "key_help.html":"Key Combination", |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | page1="""<html> |
---|
75 | <body> |
---|
76 | <p>Select topic on Menu</p> |
---|
77 | </body> |
---|
78 | </html>""" |
---|
79 | page="""<html> |
---|
80 | <body> |
---|
81 | <ul> |
---|
82 | """ |
---|
83 | for p, title in _html_file.iteritems(): |
---|
84 | pp = os.path.join(fitting_path, p) |
---|
85 | page += """<li><a href ="%s" target="showframe">%s</a><br></li>""" % (pp, title) |
---|
86 | |
---|
87 | page += """ |
---|
88 | <li><a href ="%s" target="showframe">Model Functions</a><br></li> |
---|
89 | <li><a href ="%s" target="showframe">Polydispersion Distributions</a><br></li> |
---|
90 | <li><a href ="%s" target="showframe">Smear Computation</a><br></li> |
---|
91 | </ul> |
---|
92 | </body> |
---|
93 | </html>""" % (self.path, self.path_pd, self.path_sm) |
---|
94 | |
---|
95 | self.rhelp.SetPage(page1) |
---|
96 | self.lhelp.SetPage(page) |
---|
97 | self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED,self.OnLinkClicked ) |
---|
98 | |
---|
99 | #open the help frame a the current page |
---|
100 | if pageToOpen!= None: |
---|
101 | self.rhelp.LoadPage(str( pageToOpen)) |
---|
102 | |
---|
103 | vbox.Add(self.rhelp,1, wx.EXPAND) |
---|
104 | vboxl.Add(self.lhelp, 1, wx.EXPAND) |
---|
105 | rpanel.SetSizer(vbox) |
---|
106 | lpanel.SetSizer(vboxl) |
---|
107 | lpanel.SetFocus() |
---|
108 | |
---|
109 | vbox1 = wx.BoxSizer(wx.HORIZONTAL) |
---|
110 | vbox1.Add(splitter,1,wx.EXPAND) |
---|
111 | splitter.AppendWindow(lpanel, 200) |
---|
112 | splitter.AppendWindow(rpanel) |
---|
113 | self.SetSizer(vbox1) |
---|
114 | |
---|
115 | self.Centre() |
---|
116 | self.Show(True) |
---|
117 | |
---|
118 | def OnButtonClicked(self, event): |
---|
119 | """ |
---|
120 | Function to diplay Model html page related to the hyperlinktext selected |
---|
121 | """ |
---|
122 | |
---|
123 | self.rhelp.LoadPage(self.path) |
---|
124 | |
---|
125 | def OnLinkClicked(self, event): |
---|
126 | """ |
---|
127 | Function to diplay html page related to the hyperlinktext selected |
---|
128 | """ |
---|
129 | link= event.GetLinkInfo().GetHref() |
---|
130 | |
---|
131 | self.rhelp.LoadPage(os.path.abspath(link)) |
---|
132 | |
---|
133 | """ |
---|
134 | Example: :: |
---|
135 | |
---|
136 | class ViewApp(wx.App): |
---|
137 | def OnInit(self): |
---|
138 | frame = HelpWindow(None, -1, 'HelpWindow') |
---|
139 | frame.Show(True) |
---|
140 | self.SetTopWindow(frame) |
---|
141 | |
---|
142 | return True |
---|
143 | |
---|
144 | |
---|
145 | if __name__ == "__main__": |
---|
146 | app = ViewApp(0) |
---|
147 | app.MainLoop() |
---|
148 | |
---|
149 | """ |
---|