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