[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 | """ |
---|
[318b5bbb] | 19 | def __init__(self, parent, id, title='Fitting Help', pageToOpen=None, size=(850, 540)): |
---|
| 20 | wx.Frame.__init__(self, parent, id, title, size=size) |
---|
[925a30e] | 21 | """ |
---|
[5062bbf] | 22 | contains help info |
---|
[925a30e] | 23 | """ |
---|
[6f140f2] | 24 | self.Show(False) |
---|
[318b5bbb] | 25 | self.SetTitle(title) |
---|
[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) |
---|
[318b5bbb] | 32 | self.rpanel = wx.Panel(splitter, -1) |
---|
| 33 | self.lpanel = wx.Panel(splitter, -1, style=wx.BORDER_SUNKEN) |
---|
[d7d143b0] | 34 | |
---|
| 35 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[318b5bbb] | 36 | header = wx.Panel(self.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) |
---|
[318b5bbb] | 49 | headerl = wx.Panel(self.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) |
---|
[318b5bbb] | 61 | self.lhelp = html.HtmlWindow(self.lpanel, -1, style=wx.NO_BORDER) |
---|
| 62 | self.rhelp = html.HtmlWindow(self.rpanel, -1, style=wx.NO_BORDER, |
---|
[f32d144] | 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") |
---|
[318b5bbb] | 76 | self.path_mag = os.path.join(path, "polar_mag_help.html") |
---|
| 77 | |
---|
[ec538c7] | 78 | _html_file = [("load_data_help.html", "Load a File"), |
---|
| 79 | ("single_fit_help.html", "Single Fit"), |
---|
| 80 | ("simultaneous_fit_help.html", "Simultaneous Fit"), |
---|
| 81 | ("batch_help.html", "Batch Fit"), |
---|
| 82 | ("model_use_help.html", "Model Selection"), |
---|
[f51c8ad] | 83 | ("category_manager_help.html", "Model Category Manager"), |
---|
[ec538c7] | 84 | ("%s" % self.path, "Model Functions"), |
---|
[83e0aa1] | 85 | ("model_editor_help.html", "Custom Model Editor"), |
---|
[ec538c7] | 86 | ("%s" % self.path_pd, "Polydispersion Distributions"), |
---|
| 87 | ("%s" % self.path_sm, "Smear Computation"), |
---|
[318b5bbb] | 88 | ("%s" % self.path_mag, "Polarization/Magnetic Scattering"), |
---|
[ec538c7] | 89 | ("key_help.html", "Key Combination"), |
---|
| 90 | ("status_bar_help.html", "Status Bar Help"), |
---|
| 91 | ] |
---|
[f32d144] | 92 | |
---|
| 93 | page1 = """<html> |
---|
[2268d10] | 94 | <body> |
---|
| 95 | <p>Select topic on Menu</p> |
---|
| 96 | </body> |
---|
| 97 | </html>""" |
---|
[f32d144] | 98 | |
---|
| 99 | page = """<html> |
---|
[b92884a] | 100 | <body> |
---|
| 101 | <ul> |
---|
[c0a30a24] | 102 | """ |
---|
[f32d144] | 103 | |
---|
[ec538c7] | 104 | for (p, title) in _html_file: |
---|
[c0a30a24] | 105 | pp = os.path.join(fitting_path, p) |
---|
| 106 | page += """<li><a href ="%s" target="showframe">%s</a><br></li>""" % (pp, title) |
---|
[ec538c7] | 107 | page += """</ul> |
---|
| 108 | </body> |
---|
| 109 | </html> |
---|
| 110 | """ |
---|
[f32d144] | 111 | |
---|
[2268d10] | 112 | self.rhelp.SetPage(page1) |
---|
[b92884a] | 113 | self.lhelp.SetPage(page) |
---|
[f32d144] | 114 | self.lhelp.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.OnLinkClicked ) |
---|
[9181512] | 115 | |
---|
[4faf4ba] | 116 | #open the help frame a the current page |
---|
[f32d144] | 117 | if pageToOpen != None: |
---|
| 118 | self.rhelp.LoadPage(str(pageToOpen)) |
---|
[9181512] | 119 | |
---|
[f32d144] | 120 | vbox.Add(self.rhelp, 1, wx.EXPAND) |
---|
[b92884a] | 121 | vboxl.Add(self.lhelp, 1, wx.EXPAND) |
---|
[318b5bbb] | 122 | self.rpanel.SetSizer(vbox) |
---|
| 123 | self.lpanel.SetSizer(vboxl) |
---|
| 124 | self.lpanel.SetFocus() |
---|
[d7d143b0] | 125 | |
---|
[f8b79d6] | 126 | vbox1 = wx.BoxSizer(wx.HORIZONTAL) |
---|
[f32d144] | 127 | vbox1.Add(splitter, 1, wx.EXPAND) |
---|
[318b5bbb] | 128 | splitter.AppendWindow(self.lpanel, 200) |
---|
| 129 | splitter.AppendWindow(self.rpanel) |
---|
[d7d143b0] | 130 | self.SetSizer(vbox1) |
---|
[7bce31d] | 131 | |
---|
| 132 | self.splitter = splitter |
---|
[d7d143b0] | 133 | self.Centre() |
---|
[7bce31d] | 134 | self.Bind(wx.EVT_SIZE, self.on_Size) |
---|
[925a30e] | 135 | |
---|
[9181512] | 136 | def OnButtonClicked(self, event): |
---|
| 137 | """ |
---|
[389c991] | 138 | Function to diplay Model html page related to the hyperlinktext selected |
---|
[9181512] | 139 | """ |
---|
[18cdddb] | 140 | self.rhelp.LoadPage(self.path) |
---|
[925a30e] | 141 | |
---|
[b92884a] | 142 | def OnLinkClicked(self, event): |
---|
| 143 | """ |
---|
[5062bbf] | 144 | Function to diplay html page related to the hyperlinktext selected |
---|
[b92884a] | 145 | """ |
---|
[f32d144] | 146 | link = event.GetLinkInfo().GetHref() |
---|
[389c991] | 147 | |
---|
[c0a30a24] | 148 | self.rhelp.LoadPage(os.path.abspath(link)) |
---|
[7bce31d] | 149 | |
---|
| 150 | def on_Size(self, event): |
---|
| 151 | """ |
---|
| 152 | Recover the scroll position On Size |
---|
| 153 | """ |
---|
| 154 | pos = self.rhelp.GetScrollPos(wx.VERTICAL) |
---|
| 155 | size = self.GetClientSize() |
---|
| 156 | self.splitter.SetSize(size) |
---|
| 157 | self.rhelp.Show(False) |
---|
| 158 | self.rhelp.ScrollLines(pos) |
---|
| 159 | self.rhelp.Show(True) |
---|