[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 | """ |
---|
[fdc3cb0] | 23 | self.SetTitle('Fitting Help') |
---|
[34ffeed] | 24 | from sans.perspectives.fitting import get_data_path as fit_path |
---|
| 25 | fitting_path = fit_path(media='media') |
---|
| 26 | ico_file = os.path.join(fitting_path,'ball.ico') |
---|
| 27 | if os.path.isfile(ico_file): |
---|
| 28 | self.SetIcon(wx.Icon(ico_file, wx.BITMAP_TYPE_ICO)) |
---|
[f8b79d6] | 29 | splitter = MultiSplitterWindow(self, style=wx.SP_LIVE_UPDATE) |
---|
| 30 | rpanel = wx.Panel(splitter, -1) |
---|
| 31 | lpanel = wx.Panel(splitter, -1,style=wx.BORDER_SUNKEN) |
---|
[d7d143b0] | 32 | |
---|
| 33 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[6fb01b6] | 34 | header = wx.Panel(rpanel, -1) |
---|
[d7d143b0] | 35 | header.SetBackgroundColour('#6666FF') |
---|
| 36 | header.SetForegroundColour('WHITE') |
---|
| 37 | hbox = wx.BoxSizer(wx.HORIZONTAL) |
---|
[2268d10] | 38 | st = wx.StaticText(header, -1, 'Contents', (5, 5)) |
---|
[d7d143b0] | 39 | font = st.GetFont() |
---|
| 40 | font.SetPointSize(10) |
---|
| 41 | st.SetFont(font) |
---|
| 42 | hbox.Add(st, 1, wx.TOP | wx.BOTTOM | wx.LEFT, 5) |
---|
| 43 | header.SetSizer(hbox) |
---|
| 44 | vbox.Add(header, 0, wx.EXPAND) |
---|
| 45 | |
---|
[b92884a] | 46 | vboxl= wx.BoxSizer(wx.VERTICAL) |
---|
| 47 | headerl = wx.Panel(lpanel, -1, size=(-1, 20)) |
---|
[d292959] | 48 | |
---|
[b92884a] | 49 | headerl.SetBackgroundColour('#6666FF') |
---|
| 50 | headerl.SetForegroundColour('WHITE') |
---|
| 51 | hboxl = wx.BoxSizer(wx.HORIZONTAL) |
---|
[2268d10] | 52 | lst = wx.StaticText(headerl, -1, 'Menu', (5, 5)) |
---|
[b92884a] | 53 | fontl = lst.GetFont() |
---|
| 54 | fontl.SetPointSize(10) |
---|
| 55 | lst.SetFont(fontl) |
---|
| 56 | hboxl.Add(lst, 1, wx.TOP | wx.BOTTOM | wx.LEFT, 5) |
---|
| 57 | headerl.SetSizer(hboxl) |
---|
| 58 | vboxl.Add(headerl, 0, wx.EXPAND) |
---|
| 59 | self.lhelp = html.HtmlWindow(lpanel, -1, style=wx.NO_BORDER) |
---|
[6fb01b6] | 60 | self.rhelp = html.HtmlWindow(rpanel, -1, style=wx.NO_BORDER, size=(500,-1)) |
---|
[18cdddb] | 61 | |
---|
| 62 | # get the media path |
---|
[70b760da] | 63 | if pageToOpen != None: |
---|
| 64 | path = os.path.dirname(pageToOpen) |
---|
| 65 | else: |
---|
| 66 | from sans.models import get_data_path as model_path |
---|
| 67 | # Get models help model_function path |
---|
| 68 | path = model_path(media='media') |
---|
| 69 | |
---|
[18cdddb] | 70 | self.path = os.path.join(path,"model_functions.html") |
---|
[389c991] | 71 | self.path_pd = os.path.join(path,"pd_help.html") |
---|
[384647dc] | 72 | self.path_sm = os.path.join(path,"smear_computation.html") |
---|
[34ffeed] | 73 | |
---|
[c0a30a24] | 74 | |
---|
[ec538c7] | 75 | _html_file = [("load_data_help.html", "Load a File"), |
---|
| 76 | ("single_fit_help.html", "Single Fit"), |
---|
| 77 | ("simultaneous_fit_help.html", "Simultaneous Fit"), |
---|
| 78 | ("batch_help.html", "Batch Fit"), |
---|
| 79 | ("model_use_help.html", "Model Selection"), |
---|
| 80 | ("%s" % self.path, "Model Functions"), |
---|
| 81 | ("%s" % self.path_pd, "Polydispersion Distributions"), |
---|
| 82 | ("%s" % self.path_sm, "Smear Computation"), |
---|
| 83 | ("key_help.html", "Key Combination"), |
---|
| 84 | ("status_bar_help.html", "Status Bar Help"), |
---|
| 85 | ] |
---|
[c0a30a24] | 86 | |
---|
[18cdddb] | 87 | |
---|
[2268d10] | 88 | page1="""<html> |
---|
| 89 | <body> |
---|
| 90 | <p>Select topic on Menu</p> |
---|
| 91 | </body> |
---|
| 92 | </html>""" |
---|
[08e1912] | 93 | page="""<html> |
---|
[b92884a] | 94 | <body> |
---|
| 95 | <ul> |
---|
[c0a30a24] | 96 | """ |
---|
[ec538c7] | 97 | for (p, title) in _html_file: |
---|
[c0a30a24] | 98 | pp = os.path.join(fitting_path, p) |
---|
| 99 | page += """<li><a href ="%s" target="showframe">%s</a><br></li>""" % (pp, title) |
---|
[ec538c7] | 100 | page += """</ul> |
---|
| 101 | </body> |
---|
| 102 | </html> |
---|
| 103 | """ |
---|
| 104 | #page += """ |
---|
| 105 | # <li><a href ="%s" target="showframe">Model Functions</a><br></li> |
---|
| 106 | # <li><a href ="%s" target="showframe">Polydispersion Distributions</a><br></li> |
---|
| 107 | # <li><a href ="%s" target="showframe">Smear Computation</a><br></li> |
---|
| 108 | # </ul> |
---|
| 109 | # </body> |
---|
| 110 | # </html>""" % (self.path, self.path_pd, self.path_sm) |
---|
[18cdddb] | 111 | |
---|
[2268d10] | 112 | self.rhelp.SetPage(page1) |
---|
[b92884a] | 113 | self.lhelp.SetPage(page) |
---|
| 114 | self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED,self.OnLinkClicked ) |
---|
[9181512] | 115 | |
---|
[4faf4ba] | 116 | #open the help frame a the current page |
---|
| 117 | if pageToOpen!= None: |
---|
| 118 | self.rhelp.LoadPage(str( pageToOpen)) |
---|
[9181512] | 119 | |
---|
[dcd330b] | 120 | vbox.Add(self.rhelp,1, wx.EXPAND) |
---|
[b92884a] | 121 | vboxl.Add(self.lhelp, 1, wx.EXPAND) |
---|
[d7d143b0] | 122 | rpanel.SetSizer(vbox) |
---|
[b92884a] | 123 | lpanel.SetSizer(vboxl) |
---|
| 124 | lpanel.SetFocus() |
---|
[d7d143b0] | 125 | |
---|
[f8b79d6] | 126 | vbox1 = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 127 | vbox1.Add(splitter,1,wx.EXPAND) |
---|
| 128 | splitter.AppendWindow(lpanel, 200) |
---|
| 129 | splitter.AppendWindow(rpanel) |
---|
[d7d143b0] | 130 | self.SetSizer(vbox1) |
---|
[7bce31d] | 131 | |
---|
| 132 | self.splitter = splitter |
---|
[d7d143b0] | 133 | self.Centre() |
---|
| 134 | self.Show(True) |
---|
[7bce31d] | 135 | self.Bind(wx.EVT_SIZE, self.on_Size) |
---|
[925a30e] | 136 | |
---|
[9181512] | 137 | def OnButtonClicked(self, event): |
---|
| 138 | """ |
---|
[389c991] | 139 | Function to diplay Model html page related to the hyperlinktext selected |
---|
[9181512] | 140 | """ |
---|
[18cdddb] | 141 | |
---|
| 142 | self.rhelp.LoadPage(self.path) |
---|
[925a30e] | 143 | |
---|
[b92884a] | 144 | def OnLinkClicked(self, event): |
---|
| 145 | """ |
---|
[5062bbf] | 146 | Function to diplay html page related to the hyperlinktext selected |
---|
[b92884a] | 147 | """ |
---|
| 148 | link= event.GetLinkInfo().GetHref() |
---|
[389c991] | 149 | |
---|
[c0a30a24] | 150 | self.rhelp.LoadPage(os.path.abspath(link)) |
---|
[7bce31d] | 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 | |
---|
[ec538c7] | 164 | |
---|
[389c991] | 165 | |
---|
[5062bbf] | 166 | """ |
---|
| 167 | Example: :: |
---|
[b92884a] | 168 | |
---|
[5062bbf] | 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__": |
---|
[2268d10] | 179 | app = ViewApp(0) |
---|
[5062bbf] | 180 | app.MainLoop() |
---|
| 181 | |
---|
| 182 | """ |
---|