[d7d143b0] | 1 | #!/usr/bin/python |
---|
[5062bbf] | 2 | |
---|
[d7d143b0] | 3 | import wx |
---|
| 4 | import wx.html as html |
---|
[f8b79d6] | 5 | from wx.lib.splitter import MultiSplitterWindow |
---|
[d292959] | 6 | import os |
---|
[925a30e] | 7 | |
---|
[ec538c7] | 8 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
[08e1912] | 9 | |
---|
[ec538c7] | 10 | class HelpPanel(ScrolledPanel): |
---|
| 11 | def __init__(self, parent, **kwargs): |
---|
| 12 | ScrolledPanel.__init__(self, parent, **kwargs) |
---|
| 13 | self.SetupScrolling() |
---|
| 14 | |
---|
[2268d10] | 15 | class HelpWindow(wx.Frame): |
---|
[5062bbf] | 16 | """ |
---|
| 17 | """ |
---|
[fdc3cb0] | 18 | def __init__(self, parent, id, title='Fitting Help', pageToOpen=None): |
---|
[389c991] | 19 | wx.Frame.__init__(self, parent, id, title, size=(850, 530)) |
---|
[925a30e] | 20 | """ |
---|
[5062bbf] | 21 | contains help info |
---|
[925a30e] | 22 | """ |
---|
[6f140f2] | 23 | self.Show(False) |
---|
[fdc3cb0] | 24 | self.SetTitle('Fitting Help') |
---|
[34ffeed] | 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)) |
---|
[f8b79d6] | 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) |
---|
[d7d143b0] | 33 | |
---|
| 34 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[6fb01b6] | 35 | header = wx.Panel(rpanel, -1) |
---|
[d7d143b0] | 36 | header.SetBackgroundColour('#6666FF') |
---|
| 37 | header.SetForegroundColour('WHITE') |
---|
| 38 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
[2268d10] | 39 | st = wx.StaticText(header, -1, 'Contents', (5, 5)) |
---|
[d7d143b0] | 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 | |
---|
[b92884a] | 47 | vboxl= wx.BoxSizer(wx.VERTICAL) |
---|
| 48 | headerl = wx.Panel(lpanel, -1, size=(-1, 20)) |
---|
[d292959] | 49 | |
---|
[b92884a] | 50 | headerl.SetBackgroundColour('#6666FF') |
---|
| 51 | headerl.SetForegroundColour('WHITE') |
---|
| 52 | hboxl = wx.BoxSizer(wx.HORIZONTAL) |
---|
[2268d10] | 53 | lst = wx.StaticText(headerl, -1, 'Menu', (5, 5)) |
---|
[b92884a] | 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) |
---|
[6fb01b6] | 61 | self.rhelp = html.HtmlWindow(rpanel, -1, style=wx.NO_BORDER, size=(500,-1)) |
---|
[18cdddb] | 62 | |
---|
| 63 | # get the media path |
---|
[70b760da] | 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 | |
---|
[18cdddb] | 71 | self.path = os.path.join(path,"model_functions.html") |
---|
[389c991] | 72 | self.path_pd = os.path.join(path,"pd_help.html") |
---|
[384647dc] | 73 | self.path_sm = os.path.join(path,"smear_computation.html") |
---|
[34ffeed] | 74 | |
---|
[c0a30a24] | 75 | |
---|
[ec538c7] | 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"), |
---|
[83e0aa1] | 82 | ("model_editor_help.html", "Custom Model Editor"), |
---|
[ec538c7] | 83 | ("%s" % self.path_pd, "Polydispersion Distributions"), |
---|
| 84 | ("%s" % self.path_sm, "Smear Computation"), |
---|
| 85 | ("key_help.html", "Key Combination"), |
---|
| 86 | ("status_bar_help.html", "Status Bar Help"), |
---|
| 87 | ] |
---|
[c0a30a24] | 88 | |
---|
[18cdddb] | 89 | |
---|
[2268d10] | 90 | page1="""<html> |
---|
| 91 | <body> |
---|
| 92 | <p>Select topic on Menu</p> |
---|
| 93 | </body> |
---|
| 94 | </html>""" |
---|
[08e1912] | 95 | page="""<html> |
---|
[b92884a] | 96 | <body> |
---|
| 97 | <ul> |
---|
[c0a30a24] | 98 | """ |
---|
[ec538c7] | 99 | for (p, title) in _html_file: |
---|
[c0a30a24] | 100 | pp = os.path.join(fitting_path, p) |
---|
| 101 | page += """<li><a href ="%s" target="showframe">%s</a><br></li>""" % (pp, title) |
---|
[ec538c7] | 102 | page += """</ul> |
---|
| 103 | </body> |
---|
| 104 | </html> |
---|
| 105 | """ |
---|
| 106 | #page += """ |
---|
| 107 | # <li><a href ="%s" target="showframe">Model Functions</a><br></li> |
---|
| 108 | # <li><a href ="%s" target="showframe">Polydispersion Distributions</a><br></li> |
---|
| 109 | # <li><a href ="%s" target="showframe">Smear Computation</a><br></li> |
---|
| 110 | # </ul> |
---|
| 111 | # </body> |
---|
| 112 | # </html>""" % (self.path, self.path_pd, self.path_sm) |
---|
[18cdddb] | 113 | |
---|
[2268d10] | 114 | self.rhelp.SetPage(page1) |
---|
[b92884a] | 115 | self.lhelp.SetPage(page) |
---|
| 116 | self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED,self.OnLinkClicked ) |
---|
[9181512] | 117 | |
---|
[4faf4ba] | 118 | #open the help frame a the current page |
---|
| 119 | if pageToOpen!= None: |
---|
| 120 | self.rhelp.LoadPage(str( pageToOpen)) |
---|
[9181512] | 121 | |
---|
[dcd330b] | 122 | vbox.Add(self.rhelp,1, wx.EXPAND) |
---|
[b92884a] | 123 | vboxl.Add(self.lhelp, 1, wx.EXPAND) |
---|
[d7d143b0] | 124 | rpanel.SetSizer(vbox) |
---|
[b92884a] | 125 | lpanel.SetSizer(vboxl) |
---|
| 126 | lpanel.SetFocus() |
---|
[d7d143b0] | 127 | |
---|
[f8b79d6] | 128 | vbox1 = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 129 | vbox1.Add(splitter,1,wx.EXPAND) |
---|
| 130 | splitter.AppendWindow(lpanel, 200) |
---|
| 131 | splitter.AppendWindow(rpanel) |
---|
[d7d143b0] | 132 | self.SetSizer(vbox1) |
---|
[7bce31d] | 133 | |
---|
| 134 | self.splitter = splitter |
---|
[d7d143b0] | 135 | self.Centre() |
---|
[7bce31d] | 136 | self.Bind(wx.EVT_SIZE, self.on_Size) |
---|
[925a30e] | 137 | |
---|
[9181512] | 138 | def OnButtonClicked(self, event): |
---|
| 139 | """ |
---|
[389c991] | 140 | Function to diplay Model html page related to the hyperlinktext selected |
---|
[9181512] | 141 | """ |
---|
[18cdddb] | 142 | |
---|
| 143 | self.rhelp.LoadPage(self.path) |
---|
[925a30e] | 144 | |
---|
[b92884a] | 145 | def OnLinkClicked(self, event): |
---|
| 146 | """ |
---|
[5062bbf] | 147 | Function to diplay html page related to the hyperlinktext selected |
---|
[b92884a] | 148 | """ |
---|
| 149 | link= event.GetLinkInfo().GetHref() |
---|
[389c991] | 150 | |
---|
[c0a30a24] | 151 | self.rhelp.LoadPage(os.path.abspath(link)) |
---|
[7bce31d] | 152 | |
---|
| 153 | def on_Size(self, event): |
---|
| 154 | """ |
---|
| 155 | Recover the scroll position On Size |
---|
| 156 | """ |
---|
| 157 | pos = self.rhelp.GetScrollPos(wx.VERTICAL) |
---|
| 158 | size = self.GetClientSize() |
---|
| 159 | self.splitter.SetSize(size) |
---|
| 160 | self.rhelp.Show(False) |
---|
| 161 | self.rhelp.ScrollLines(pos) |
---|
| 162 | self.rhelp.Show(True) |
---|
| 163 | #self.rhelp.SetScrollPos(wx.VERTICAL, pos1, True) |
---|
| 164 | |
---|
[ec538c7] | 165 | |
---|
[389c991] | 166 | |
---|
[5062bbf] | 167 | """ |
---|
| 168 | Example: :: |
---|
[b92884a] | 169 | |
---|
[5062bbf] | 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__": |
---|
[2268d10] | 180 | app = ViewApp(0) |
---|
[5062bbf] | 181 | app.MainLoop() |
---|
| 182 | |
---|
| 183 | """ |
---|