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