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 | import sys |
---|
8 | |
---|
9 | |
---|
10 | class HelpWindow(wx.Frame): |
---|
11 | """ |
---|
12 | """ |
---|
13 | def __init__(self, parent, id, title= 'HelpWindow', pageToOpen=None): |
---|
14 | wx.Frame.__init__(self, parent, id, title, size=(850, 530)) |
---|
15 | """ |
---|
16 | contains help info |
---|
17 | """ |
---|
18 | path = os.path.dirname(__file__) |
---|
19 | temp_path = os.path.join(path,'images') |
---|
20 | ico_file = os.path.join(temp_path,'ball.ico') |
---|
21 | if os.path.isfile(ico_file): |
---|
22 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
23 | else: |
---|
24 | temp_path = os.path.join(os.getcwd(),'images') |
---|
25 | ico_file = os.path.join(temp_path,'ball.ico') |
---|
26 | if os.path.isfile(ico_file): |
---|
27 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
28 | else: |
---|
29 | ico_file = os.path.join(os.path.dirname(os.path.sys.path[0]), |
---|
30 | 'images', 'ball.ico') |
---|
31 | if os.path.isfile(ico_file): |
---|
32 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
33 | |
---|
34 | splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE) |
---|
35 | rpanel = wx.Panel(splitter, -1) |
---|
36 | lpanel = wx.Panel(splitter, -1,style=wx.BORDER_SUNKEN) |
---|
37 | |
---|
38 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
39 | header = wx.Panel(rpanel, -1) |
---|
40 | header.SetBackgroundColour('#6666FF') |
---|
41 | header.SetForegroundColour('WHITE') |
---|
42 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
43 | st = wx.StaticText(header, -1, 'Contents', (5, 5)) |
---|
44 | font = st.GetFont() |
---|
45 | font.SetPointSize(10) |
---|
46 | st.SetFont(font) |
---|
47 | hbox.Add(st, 1, wx.TOP | wx.BOTTOM | wx.LEFT, 5) |
---|
48 | header.SetSizer(hbox) |
---|
49 | vbox.Add(header, 0, wx.EXPAND) |
---|
50 | |
---|
51 | vboxl= wx.BoxSizer(wx.VERTICAL) |
---|
52 | headerl = wx.Panel(lpanel, -1, size=(-1, 20)) |
---|
53 | |
---|
54 | headerl.SetBackgroundColour('#6666FF') |
---|
55 | headerl.SetForegroundColour('WHITE') |
---|
56 | hboxl = wx.BoxSizer(wx.HORIZONTAL) |
---|
57 | lst = wx.StaticText(headerl, -1, 'Menu', (5, 5)) |
---|
58 | fontl = lst.GetFont() |
---|
59 | fontl.SetPointSize(10) |
---|
60 | lst.SetFont(fontl) |
---|
61 | hboxl.Add(lst, 1, wx.TOP | wx.BOTTOM | wx.LEFT, 5) |
---|
62 | headerl.SetSizer(hboxl) |
---|
63 | vboxl.Add(headerl, 0, wx.EXPAND) |
---|
64 | self.lhelp = html.HtmlWindow(lpanel, -1, style=wx.NO_BORDER) |
---|
65 | self.rhelp = html.HtmlWindow(rpanel, -1, style=wx.NO_BORDER, size=(500,-1)) |
---|
66 | |
---|
67 | import sans.models as models |
---|
68 | # get the media path |
---|
69 | path = models.get_data_path(media='media') |
---|
70 | if not os.path.isdir(path): |
---|
71 | path = os.path.dirname(os.path.sys.path[0]) |
---|
72 | self.path = os.path.join(path,"model_functions.html") |
---|
73 | self.path_pd = os.path.join(path,"pd_help.html") |
---|
74 | self.path_sm = os.path.join(path,"smear_computation.html") |
---|
75 | |
---|
76 | page1="""<html> |
---|
77 | <body> |
---|
78 | <p>Select topic on Menu</p> |
---|
79 | </body> |
---|
80 | </html>""" |
---|
81 | |
---|
82 | if not os.path.isfile(os.path.join(path, "change_scale_help.html")): |
---|
83 | path = os.path.join(os.path.dirname(os.path.sys.path[0]), 'media') |
---|
84 | page = """<html> |
---|
85 | <body> |
---|
86 | <ul> |
---|
87 | <li><a href ="%s" target ="showframe">Change Scale</a><br></li> |
---|
88 | """ % str(os.path.join(path, "change_scale_help.html")) |
---|
89 | page += """ |
---|
90 | <li><a href ="%s" target ="showframe">Graph Help</a><br></li> |
---|
91 | """ % str(os.path.join(path, "reset_Graph_help.html")) |
---|
92 | page += """ |
---|
93 | <li><a href ="%s" target ="showframe">Status Bar Help</a><br></li> |
---|
94 | """ % str(os.path.join(path, "status_bar_help.html")) |
---|
95 | page += """ |
---|
96 | <li><a href ="%s" target ="showframe">Load a File</a><br></li> |
---|
97 | """ % str(os.path.join(path, "load_data_help.html")) |
---|
98 | page += """ |
---|
99 | <li><a href ="%s" |
---|
100 | target ="showframe">Simultaneous Fit</a><br></li> |
---|
101 | """ % str(os.path.join(path, "simultaneous_fit_help.html")) |
---|
102 | page += """ |
---|
103 | <li><a href ="%s" |
---|
104 | target ="showframe">Single Fit</a><br></li> |
---|
105 | """ % str(os.path.join(path, "single_fit_help.html")) |
---|
106 | page += """ |
---|
107 | <li><a href ="%s" |
---|
108 | target ="showframe">Visualize Model</a><br></li> |
---|
109 | """ % str(os.path.join(path, "model_use_help.html")) |
---|
110 | page += """ |
---|
111 | <li><a href ="%s" |
---|
112 | target ="showframe">Data Averaging</a><br></li> |
---|
113 | """ % str(os.path.join(path, "averaging_help.html")) |
---|
114 | page += """ |
---|
115 | <li><a href ="%s" target ="showframe">Model Functions</a><br></li> |
---|
116 | """ % str(self.path) |
---|
117 | page += """<li><a href ="%s" target ="showframe"> |
---|
118 | Polydispersion Distributions</a><br></li> |
---|
119 | """ % str(self.path_pd) |
---|
120 | page += """ |
---|
121 | <li><a href ="%s" target ="showframe">Smear Computation</a><br></li> |
---|
122 | """ % str(self.path_sm) |
---|
123 | page += """<li><a href ="%s" |
---|
124 | target ="showframe">Key Combination</a><br></li> |
---|
125 | </ul> |
---|
126 | </body> |
---|
127 | </html>""" % str(os.path.join(path, "key_help.html")) |
---|
128 | |
---|
129 | self.rhelp.SetPage(page1) |
---|
130 | self.lhelp.SetPage(page) |
---|
131 | self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED,self.OnLinkClicked ) |
---|
132 | |
---|
133 | #open the help frame a the current page |
---|
134 | if pageToOpen!= None: |
---|
135 | self.rhelp.LoadPage(str( pageToOpen)) |
---|
136 | |
---|
137 | vbox.Add(self.rhelp,1, wx.EXPAND) |
---|
138 | vboxl.Add(self.lhelp, 1, wx.EXPAND) |
---|
139 | rpanel.SetSizer(vbox) |
---|
140 | lpanel.SetSizer(vboxl) |
---|
141 | lpanel.SetFocus() |
---|
142 | |
---|
143 | vbox1 = wx.BoxSizer(wx.HORIZONTAL) |
---|
144 | vbox1.Add(splitter,1,wx.EXPAND) |
---|
145 | splitter.AppendWindow(lpanel, 200) |
---|
146 | splitter.AppendWindow(rpanel) |
---|
147 | self.SetSizer(vbox1) |
---|
148 | |
---|
149 | self.Centre() |
---|
150 | self.Show(True) |
---|
151 | |
---|
152 | def OnButtonClicked(self, event): |
---|
153 | """ |
---|
154 | Function to diplay Model html page related to the hyperlinktext selected |
---|
155 | """ |
---|
156 | |
---|
157 | self.rhelp.LoadPage(self.path) |
---|
158 | |
---|
159 | def OnLinkClicked(self, event): |
---|
160 | """ |
---|
161 | Function to diplay html page related to the hyperlinktext selected |
---|
162 | """ |
---|
163 | link= event.GetLinkInfo().GetHref() |
---|
164 | |
---|
165 | self.rhelp.LoadPage(link) |
---|
166 | |
---|
167 | """ |
---|
168 | Example: :: |
---|
169 | |
---|
170 | class ViewApp(wx.App): |
---|
171 | def OnInit(self): |
---|
172 | frame = HelpWindow(None, -1, 'HelpWindow') |
---|
173 | frame.Show(True) |
---|
174 | self.SetTopWindow(frame) |
---|
175 | |
---|
176 | return True |
---|
177 | |
---|
178 | |
---|
179 | if __name__ == "__main__": |
---|
180 | app = ViewApp(0) |
---|
181 | app.MainLoop() |
---|
182 | |
---|
183 | """ |
---|