Changeset 427


Ignore:
Timestamp:
Nov 22, 2011 3:21:38 PM (10 years ago)
Author:
toby
Message:

implement HTML help

Location:
trunk
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r426 r427  
    4848    print "MKL module not present"
    4949__version__ = '0.1.5'
     50G2gd.__version__ = __version__
     51print "This is GSAS-II version:     ",__version__
    5052
    5153# useful degree trig functions
     
    7981wxID_EXPORTCIF, wxID_EXPORTPEAKLIST, wxID_EXPORTPDF,
    8082] = [wx.NewId() for _init_coll_Export_Items in range(7)]
    81 
    82 [wxID_HELPABOUT, wxID_HELPHELP,
    83 ] = [wx.NewId() for _init_coll_Help_Items in range(2)]
    8483
    8584class GSASII(wx.Frame):
     
    9190        parent.Append(menu=self.Import, title='Import')
    9291        parent.Append(menu=self.Export, title='Export')
    93         parent.Append(menu=self.Help, title='Help')
     92        parent.Append(menu=G2gd.MyHelp(self,helpType='Data tree'),title='&Help' )
    9493
    9594    def _init_coll_File_Items(self, parent):
     
    205204        self.Bind(wx.EVT_MENU, self.OnExportCIF, id=wxID_EXPORTCIF)
    206205               
    207     def _init_coll_Help_Items(self, parent):
    208         parent.Append(help='', id=wxID_HELPHELP, kind=wx.ITEM_NORMAL,
    209             text='Help')
    210         parent.Append(help='', id=wxID_HELPABOUT, kind=wx.ITEM_NORMAL,
    211             text='About')
    212         self.Bind(wx.EVT_MENU, self.OnHelpHelp, id=wxID_HELPHELP)
    213         self.Bind(wx.EVT_MENU, self.OnHelpAbout, id=wxID_HELPABOUT)
    214 
    215206    def _init_utils(self):
    216207        self.GSASIIMenu = wx.MenuBar()
     
    220211        self.Import = wx.Menu(title='')       
    221212        self.Export = wx.Menu(title='')       
    222         self.Help = wx.Menu(title='')
    223213
    224214        self._init_coll_GSASIIMenu_Menus(self.GSASIIMenu)
     
    228218        self._init_coll_Import_Items(self.Import)
    229219        self._init_coll_Export_Items(self.Export)
    230         self._init_coll_Help_Items(self.Help)
    231220       
    232221    def _init_ctrls(self, parent):
     
    15991588    def OnHelpHelp(self, event):
    16001589        event.Skip()
    1601        
    1602     def OnHelpAbout(self, event):
    1603         info = wx.AboutDialogInfo()
    1604         info.Name = 'GSAS-II'
    1605         info.Version = __version__
    1606         info.Copyright = '''
    1607 Robert B. Von Dreele
    1608 Argonne National Laboratory(C)
    1609 This product includes software developed
    1610 by the UChicago Argonne, LLC, as
    1611 Operator of Argonne National Laboratory.         '''
    1612         info.Description = '''
    1613 General Structure Analysis System - II
    1614         '''
    1615         wx.AboutBox(info)
    1616        
     1590               
    16171591class GSASIImain(wx.App):
    16181592    def OnInit(self):
  • trunk/GSASIIgrid.py

    r425 r427  
    1212import cPickle
    1313import numpy as np
     14import os.path
     15import wx.html        # could postpone this for quicker startup
     16import webbrowser     # could postpone this for quicker startup
    1417import GSASIIpath
    1518import GSASIIplot as G2plt
     
    2023#import GSASIImapvars as G2mv
    2124
     25# globals we will use later
     26__version__ = None # gets overridden in GSASII.py
     27path2GSAS2 = os.path.dirname(os.path.realpath(__file__)) # save location of this file
     28helpLocDict = {}
     29htmlPanel = None
     30htmlFrame = None
     31helpMode = 'internal'    # need a global control to set this
     32#helpMode = 'browser'    # need a global control to set this
     33htmlFirstUse = True
     34
    2235[ wxID_ATOMSEDITADD, wxID_ATOMSEDITINSERT, wxID_ATOMSEDITDELETE, wxID_ATOMSREFINE,
    2336    wxID_ATOMSMODIFY, wxID_ATOMSTRANSFORM, wxID_ATOMSTESTADD, wxID_ATONTESTINSERT,
     
    8093] = [wx.NewId() for _init_coll_PDF_Items in range(7)]
    8194
    82 [ wxID_HELP,
    83 ] = [wx.NewId() for _init_coll_Help_Items in range(1)]
    84 
    8595VERY_LIGHT_GREY = wx.Colour(235,235,235)
    8696
    8797class MyHelp(wx.Menu):
    88     def __init__(self,title='',helpType='this item'):
     98    '''This class creates the contents of a help menu.
     99    The menu will start with two entries:
     100      'Help on <helpType>': where helpType is a reference to an HTML page to
     101      be opened
     102      About: opens an About dialog using OnHelpAbout. N.B. on the Mac this
     103      gets moved to the App menu to be consistent with Apple style.
     104    NOTE: the title for this menu should be '&Help' so the wx handles
     105    it correctly. BHT
     106    '''
     107    def __init__(self,frame,title='',helpType=None):
    89108        wx.Menu.__init__(self,title)
    90         self.helpType = helpType            #there must be some way to get this
    91         self.Append(help='Help on '+helpType,id=wxID_HELP, kind=wx.ITEM_NORMAL,
    92             text='Help')                           
     109        self.helpType = helpType
     110        self.frame = frame
     111        # add a help item only when helpType is specified
     112        if helpType is not None:
     113            helpobj = self.Append(text='Help on '+helpType,
     114                                  id=wx.ID_ANY, kind=wx.ITEM_NORMAL)
     115            frame.Bind(wx.EVT_MENU, self.OnHelp, helpobj)
     116        self.Append(help='', id=wx.ID_ABOUT, kind=wx.ITEM_NORMAL,
     117                    text='&About GSAS-II')
     118        frame.Bind(wx.EVT_MENU, self.OnHelpAbout, id=wx.ID_ABOUT)
     119
     120    def OnHelp(self,event):
     121        '''Called when Help on... is pressed in a menu. Brings up
     122        a web page for documentation.
     123        '''
     124        global helpLocDict
     125        global helpMode
     126        # look up a definition for help info from dict
     127        helplink = helpLocDict.get(self.helpType)
     128        if helplink is None:
     129            # no defined link to use, create a default based on key
     130            helplink = 'gsasII.html#' + self.helpType
     131        helplink = os.path.join(path2GSAS2,'help',helplink)
     132        if helpMode == 'internal':
     133            global htmlPanel, htmlFrame
     134            try:
     135                htmlPanel.LoadFile(helplink)
     136            except:
     137                htmlFrame = wx.Frame(self.frame, -1, size=(610, 380))
     138                htmlFrame.Show(True)
     139                htmlFrame.SetTitle("HTML Window") # N.B. reset later in LoadFile
     140                htmlPanel = MyHtmlPanel(htmlFrame,-1)
     141                htmlPanel.LoadFile(helplink)
     142        else:
     143            global htmlFirstUse
     144            #import webbrowser
     145            if htmlFirstUse:
     146                webbrowser.open_new("file://"+helplink)
     147                htmlFirstUse = False
     148            else:
     149                webbrowser.open("file://"+helplink, new=0, autoraise=True)
     150
     151    def OnHelpAbout(self, event):
     152        "Display an 'About GSAS-II' box"
     153        global __version__
     154        info = wx.AboutDialogInfo()
     155        info.Name = 'GSAS-II'
     156        info.Version = __version__
     157        info.Copyright = '''
     158Robert B. Von Dreele
     159Argonne National Laboratory(C)
     160This product includes software developed
     161by the UChicago Argonne, LLC, as
     162Operator of Argonne National Laboratory.         '''
     163        info.Description = '''
     164General Structure Analysis System - II
     165'''
     166        wx.AboutBox(info)
     167
     168class MyHtmlPanel(wx.Panel):
     169    '''Defines a panel to display Help information'''
     170    def __init__(self, frame, id):
     171        self.frame = frame
     172        wx.Panel.__init__(self, frame, id)
     173        sizer = wx.BoxSizer(wx.VERTICAL)
     174        back = wx.Button(self, -1, "Back")
     175        back.Bind(wx.EVT_BUTTON, self.OnBack)
     176        sizer.Add(back, 0, wx.ALIGN_LEFT, 0)
     177
     178        #self.htmlwin = wx.html.HtmlWindow(self, id, size=(602,310))
     179        self.htmlwin = G2HtmlWindow(self, id, size=(602,310))
     180        sizer.Add(self.htmlwin, 1, wx.GROW|wx.ALL, 0)
     181        self.SetSizer(sizer)
     182        sizer.Fit(frame)       
     183    def OnBack(self, event):
     184        self.htmlwin.HistoryBack()
     185    def LoadFile(self,file):
     186        pos = file.rfind('#')
     187        if pos != -1:
     188            helpfile = file[:pos]
     189            helpanchor = file[pos+1:]
     190        else:
     191            helpfile = file
     192            helpanchor = None
     193        self.htmlwin.LoadPage(helpfile)
     194        if helpanchor is not None:
     195            self.htmlwin.ScrollToAnchor(helpanchor)
     196
     197class G2HtmlWindow(wx.html.HtmlWindow):
     198    '''Displays help information in a primitive HTML browser type window
     199    '''
     200    def __init__(self, parent, *args, **kwargs):
     201        self.parent = parent
     202        wx.html.HtmlWindow.__init__(self, parent, *args, **kwargs)
     203    def LoadPage(self, *args, **kwargs):
     204        wx.html.HtmlWindow.LoadPage(self, *args, **kwargs)
     205        self.TitlePage()
     206    def OnLinkClicked(self, *args, **kwargs):
     207        wx.html.HtmlWindow.OnLinkClicked(self, *args, **kwargs)
     208        self.TitlePage()
     209    def HistoryBack(self, *args, **kwargs):
     210        wx.html.HtmlWindow.HistoryBack(self, *args, **kwargs)
     211        self.TitlePage()
     212    def TitlePage(self):
     213        self.parent.frame.SetTitle(self.GetOpenedPage() + ' -- ' +
     214                                   self.GetOpenedPageTitle())
    93215
    94216class DataFrame(wx.Frame):
     
    98220    def _init_coll_AtomsMenu(self,parent):
    99221        parent.Append(menu=self.AtomEdit, title='Edit')
    100         parent.Append(menu=MyHelp(helpType='Atoms'),title='Help')
     222        parent.Append(menu=MyHelp(self,helpType='Atoms'),title='&Help')
    101223       
    102224    def _init_coll_ConstraintMenu(self,parent):
    103225        parent.Append(menu=self.ConstraintEdit, title='Edit')
    104         parent.Append(menu=MyHelp(helpType='Constraints'),title='Help')
     226        parent.Append(menu=MyHelp(self,helpType='Constraints'),title='&Help')
    105227       
    106228    def _init_coll_RestraintMenu(self,parent):
    107229        parent.Append(menu=self.RestraintEdit, title='Edit')
    108         parent.Append(menu=MyHelp(helpType='Restraints'),title='Help')
     230        parent.Append(menu=MyHelp(self,helpType='Restraints'),title='&Help')
    109231       
    110232    def _init_coll_DataMenu(self,parent):
    111233        parent.Append(menu=self.DataEdit, title='Edit')
    112         parent.Append(menu=MyHelp(helpType='Data'),title='Help')
     234        parent.Append(menu=MyHelp(self,helpType='Data'),title='&Help')
    113235       
    114236    def _init_coll_DrawAtomsMenu(self,parent):
    115237        parent.Append(menu=self.DrawAtomEdit, title='Edit')
    116         parent.Append(menu=MyHelp(helpType='Draw Atoms'),title='Help')
     238        parent.Append(menu=MyHelp(self,helpType='Draw Atoms'),title='&Help')
    117239
    118240    def _init_coll_PawleyMenu(self,parent):
    119241        parent.Append(menu=self.PawleyEdit,title='Operations')
    120         parent.Append(menu=MyHelp(helpType='Pawley'),title='Help')
     242        parent.Append(menu=MyHelp(self,helpType='Pawley'),title='&Help')
    121243     
    122244    def _init_coll_IndPeaksMenu(self,parent):
    123245        parent.Append(menu=self.IndPeaksEdit,title='Operations')
    124         parent.Append(menu=MyHelp(helpType='Index Peaks'),title='Help')
     246        parent.Append(menu=MyHelp(self,helpType='Index Peaks'),title='&Help')
    125247                   
    126248    def _init_coll_ImageMenu(self,parent):
    127249        parent.Append(menu=self.ImageEdit, title='Operations')
    128         parent.Append(menu=MyHelp(helpType='Images'),title='Help')
     250        parent.Append(menu=MyHelp(self,helpType='Images'),title='&Help')
    129251       
    130252    def _init_coll_BackMenu(self,parent):
    131253        parent.Append(menu=self.BackEdit, title='File')
    132         parent.Append(menu=MyHelp(helpType='Background'),title='Help')
     254        parent.Append(menu=MyHelp(self,helpType='Background'),title='&Help')
    133255       
    134256    def _init_coll_LimitMenu(self,parent):
    135257        parent.Append(menu=self.LimitEdit, title='File')
    136         parent.Append(menu=MyHelp(helpType='Limits'),title='Help')
     258        parent.Append(menu=MyHelp(self,helpType='Limits'),title='&Help')
    137259       
    138260    def _init_coll_InstMenu(self,parent):
    139261        parent.Append(menu=self.InstEdit, title='Operations')
    140         parent.Append(menu=MyHelp(helpType='Instrument Parameters'),title='Help')
     262        parent.Append(menu=MyHelp(self,helpType='Instrument Parameters'),title='&Help')
    141263       
    142264    def _init_coll_MaskMenu(self,parent):
    143265        parent.Append(menu=self.MaskEdit, title='Operations')
    144         parent.Append(menu=MyHelp(helpType='Image Masks'),title='Help')
     266        parent.Append(menu=MyHelp(self,helpType='Image Masks'),title='&Help')
    145267       
    146268    def _init_coll_SampleMenu(self,parent):
    147269        parent.Append(menu=self.SampleEdit, title='File')
    148         parent.Append(menu=MyHelp(helpType='Sample Parameters'),title='Help')
     270        parent.Append(menu=MyHelp(self,helpType='Sample Parameters'),title='&Help')
    149271       
    150272    def _init_coll_PeakMenu(self,parent):
    151273        parent.Append(menu=self.PeakEdit, title='Peak Fitting')
    152         parent.Append(menu=MyHelp(helpType='Powder Peaks'),title='Help')
     274        parent.Append(menu=MyHelp(self,helpType='Powder Peaks'),title='&Help')
    153275
    154276    def _init_coll_IndexMenu(self,parent):
    155277        parent.Append(menu=self.IndexEdit, title='Cell Index/Refine')
    156         parent.Append(menu=MyHelp(helpType='Cell Indexing/Refine'),title='Help')
     278        parent.Append(menu=MyHelp(self,helpType='Cell Indexing/Refine'),title='&Help')
    157279       
    158280    def _init_coll_ReflMenu(self,parent):
    159281        parent.Append(menu=self.ReflEdit, title='Reflection List')
    160         parent.Append(menu=MyHelp(helpType='Reflection List'),title='Help')
     282        parent.Append(menu=MyHelp(self,helpType='Reflection List'),title='&Help')
    161283
    162284    def _init_coll_TextureMenu(self,parent):
    163285        parent.Append(menu=self.TextureEdit, title='Texture')
    164         parent.Append(menu=MyHelp(helpType='Texture'),title='Help')
     286        parent.Append(menu=MyHelp(self,helpType='Texture'),title='&Help')
    165287
    166288    def _init_coll_PDFMenu(self,parent):
    167289        parent.Append(menu=self.PDFEdit, title='PDF Controls')
    168         parent.Append(menu=MyHelp(helpType='PDF Controls'),title='Help')
     290        parent.Append(menu=MyHelp(self,helpType='PDF Controls'),title='&Help')
    169291
    170292    def _init_coll_Atom_Items(self,parent):
     
    13791501        self.dataFrame.SetLabel('')
    13801502    else:
    1381         #it all starts here for dataFrame; universal Bind to the Help is here also
     1503        #create the frame for the data item window
    13821504        self.dataFrame = DataFrame(parent=self.mainPanel)
    1383         self.dataFrame.Bind(wx.EVT_MENU, OnHelp, id=wxID_HELP)
    13841505
    13851506    self.dataFrame.Raise()           
Note: See TracChangeset for help on using the changeset viewer.