source: sasview/fittingview/src/sans/perspectives/fitting/help_panel.py @ dafc36f

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since dafc36f was 7bce31d, checked in by Jae Cho <jhjcho@…>, 13 years ago

improved the help resetting problem on resizing

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