Changeset 1657


Ignore:
Timestamp:
Feb 16, 2015 2:46:06 PM (9 years ago)
Author:
toby
Message:

migrate help from G2grid; set instparms in Powder imports; seach for imports in data path; start on tutorial migration

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1655 r1657  
    8484
    8585__version__ = '0.2.0'
    86 G2gd.__version__ = __version__
    8786
    8887# PATCH: for Mavericks (OS X 10.9.x), wx produces an annoying warning about LucidaGrandeUI.
     
    257256        pathlist = sys.path[:]
    258257        #if path2GSAS2 not in pathlist: pathlist.append(path2GSAS2)
     258        if '.' not in pathlist: pathlist.append('.') # insert the directory where G2 is started
    259259
    260260        filelist = []
     
    12811281                if rd.repeat_instparm:
    12821282                    lastIparmfile = rd.instfile
     1283                # override any keys in read instrument parameters with ones set in import
     1284                for key in Iparm1: 
     1285                    if key in rd.instdict:
     1286                        Iparm1[key] = rd.instdict[key]
    12831287            else:
    12841288                Iparm1,Iparm2 = rd.pwdparms['Instrument Parameters']
     
    20032007            menubar.Append(menu=self.MacroMenu, title='Macro')
    20042008            self._init_Macro()
    2005         HelpMenu=G2gd.MyHelp(self,helpType='Data tree',
     2009        HelpMenu=G2G.MyHelp(self,helpType='Data tree',
    20062010            morehelpitems=[('&Tutorials','Tutorials')])
    20072011        menubar.Append(menu=HelpMenu,title='&Help')
  • trunk/GSASIIconstrGUI.py

    r1625 r1657  
    835835            constSizer.Add(constDel,0,wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER,1)             # delete button
    836836            if helptext:
    837                 ch = G2gd.HelpButton(pageDisplay,helptext)
     837                ch = G2G.HelpButton(pageDisplay,helptext)
    838838                constSizer.Add(ch,0,wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER,1)
    839839            else:
  • trunk/GSASIIctrls.py

    r1619 r1657  
    2222# import wx.aui
    2323import wx.lib.scrolledpanel as wxscroll
    24 # import time
     24import time
    2525import copy
    2626# import cPickle
    27 # import sys
    28 # import os
     27import sys
     28import os
    2929# import numpy as np
    3030# import numpy.ma as ma
    3131# import scipy.optimize as so
    32 # import wx.html        # could postpone this for quicker startup
    33 # import webbrowser     # could postpone this for quicker startup
     32import wx.html        # could postpone this for quicker startup
     33import webbrowser     # could postpone this for quicker startup
    3434
    3535import GSASIIpath
     
    5252import GSASIIlog as log
    5353
    54 # globals we will use later
     54# Define a short names for convenience
    5555WHITE = (255,255,255)
    5656DULL_YELLOW = (230,230,190)
    5757VERY_LIGHT_GREY = wx.Colour(235,235,235)
     58WACV = wx.ALIGN_CENTER_VERTICAL
    5859
    5960################################################################################
     
    13111312    val = dlg.ShowModal()
    13121313
     1314################################################################################
     1315####
     1316################################################################################
    13131317class OrderBox(wxscroll.ScrolledPanel):
    13141318    '''Creates a panel with scrollbars where items can be ordered into columns
     
    14161420        self.GBsizer.Layout()
    14171421        self.FitInside()
    1418        
     1422
     1423################################################################################
     1424#### Help support routines
     1425################################################################################
     1426################################################################################
     1427class MyHelp(wx.Menu):
     1428    '''
     1429    A class that creates the contents of a help menu.
     1430    The menu will start with two entries:
     1431
     1432    * 'Help on <helpType>': where helpType is a reference to an HTML page to
     1433      be opened
     1434    * About: opens an About dialog using OnHelpAbout. N.B. on the Mac this
     1435      gets moved to the App menu to be consistent with Apple style.
     1436
     1437    NOTE: for this to work properly with respect to system menus, the title
     1438    for the menu must be &Help, or it will not be processed properly:
     1439
     1440    ::
     1441
     1442       menu.Append(menu=MyHelp(self,...),title="&Help")
     1443
     1444    '''
     1445    def __init__(self,frame,helpType=None,helpLbl=None,morehelpitems=[],title=''):
     1446        wx.Menu.__init__(self,title)
     1447        self.HelpById = {}
     1448        self.frame = frame
     1449        self.Append(help='', id=wx.ID_ABOUT, kind=wx.ITEM_NORMAL,
     1450            text='&About GSAS-II')
     1451        frame.Bind(wx.EVT_MENU, self.OnHelpAbout, id=wx.ID_ABOUT)
     1452        if GSASIIpath.whichsvn():
     1453            helpobj = self.Append(
     1454                help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
     1455                text='&Check for updates')
     1456            frame.Bind(wx.EVT_MENU, self.OnCheckUpdates, helpobj)
     1457            helpobj = self.Append(
     1458                help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
     1459                text='&Regress to an old GSAS-II version')
     1460            frame.Bind(wx.EVT_MENU, self.OnSelectVersion, helpobj)
     1461        for lbl,indx in morehelpitems:
     1462            helpobj = self.Append(text=lbl,
     1463                id=wx.ID_ANY, kind=wx.ITEM_NORMAL)
     1464            frame.Bind(wx.EVT_MENU, self.OnHelpById, helpobj)
     1465            self.HelpById[helpobj.GetId()] = indx
     1466        # add a help item only when helpType is specified
     1467        if helpType is not None:
     1468            self.AppendSeparator()
     1469            if helpLbl is None: helpLbl = helpType
     1470            helpobj = self.Append(text='Help on '+helpLbl,
     1471                                  id=wx.ID_ANY, kind=wx.ITEM_NORMAL)
     1472            frame.Bind(wx.EVT_MENU, self.OnHelpById, helpobj)
     1473            self.HelpById[helpobj.GetId()] = helpType
     1474       
     1475    def OnHelpById(self,event):
     1476        '''Called when Help on... is pressed in a menu. Brings up
     1477        a web page for documentation.
     1478        '''
     1479        helpType = self.HelpById.get(event.GetId())
     1480        if helpType is None:
     1481            print 'Error: help lookup failed!',event.GetEventObject()
     1482            print 'id=',event.GetId()
     1483        else:
     1484            if helpType == 'Tutorials':
     1485                self.frame.Tutorials = True
     1486            ShowHelp(helpType,self.frame)
     1487
     1488    def OnHelpAbout(self, event):
     1489        "Display an 'About GSAS-II' box"
     1490        import GSASII
     1491        info = wx.AboutDialogInfo()
     1492        info.Name = 'GSAS-II'
     1493        ver = GSASIIpath.svnGetRev()
     1494        if ver:
     1495            info.Version = 'Revision '+str(ver)+' (svn), version '+GSASII.__version__
     1496        else:
     1497            info.Version = 'Revision '+str(GSASIIpath.GetVersionNumber())+' (.py files), version '+GSASII.__version__
     1498        #info.Developers = ['Robert B. Von Dreele','Brian H. Toby']
     1499        info.Copyright = ('(c) ' + time.strftime('%Y') +
     1500''' Argonne National Laboratory
     1501This product includes software developed
     1502by the UChicago Argonne, LLC, as
     1503Operator of Argonne National Laboratory.''')
     1504        info.Description = '''General Structure Analysis System-II (GSAS-II)
     1505Robert B. Von Dreele and Brian H. Toby
     1506
     1507Please cite as:
     1508B.H. Toby & R.B. Von Dreele, J. Appl. Cryst. 46, 544-549 (2013) '''
     1509
     1510        info.WebSite = ("https://subversion.xray.aps.anl.gov/trac/pyGSAS","GSAS-II home page")
     1511        wx.AboutBox(info)
     1512
     1513    def OnCheckUpdates(self,event):
     1514        '''Check if the GSAS-II repository has an update for the current source files
     1515        and perform that update if requested.
     1516        '''
     1517        if not GSASIIpath.whichsvn():
     1518            dlg = wx.MessageDialog(self.frame,
     1519                                   'No Subversion','Cannot update GSAS-II because subversion (svn) was not found.',
     1520                                   wx.OK)
     1521            dlg.ShowModal()
     1522            dlg.Destroy()
     1523            return
     1524        wx.BeginBusyCursor()
     1525        local = GSASIIpath.svnGetRev()
     1526        if local is None:
     1527            wx.EndBusyCursor()
     1528            dlg = wx.MessageDialog(self.frame,
     1529                                   'Unable to run subversion on the GSAS-II current directory. Is GSAS-II installed correctly?',
     1530                                   'Subversion error',
     1531                                   wx.OK)
     1532            dlg.ShowModal()
     1533            dlg.Destroy()
     1534            return
     1535        print 'Installed GSAS-II version: '+local
     1536        repos = GSASIIpath.svnGetRev(local=False)
     1537        wx.EndBusyCursor()
     1538        if repos is None:
     1539            dlg = wx.MessageDialog(self.frame,
     1540                                   'Unable to access the GSAS-II server. Is this computer on the internet?',
     1541                                   'Server unavailable',
     1542                                   wx.OK)
     1543            dlg.ShowModal()
     1544            dlg.Destroy()
     1545            return
     1546        print 'GSAS-II version on server: '+repos
     1547        if local == repos:
     1548            dlg = wx.MessageDialog(self.frame,
     1549                                   'GSAS-II is up-to-date. Version '+local+' is already loaded.',
     1550                                   'GSAS-II Up-to-date',
     1551                                   wx.OK)
     1552            dlg.ShowModal()
     1553            dlg.Destroy()
     1554            return
     1555        mods = GSASIIpath.svnFindLocalChanges()
     1556        if mods:
     1557            dlg = wx.MessageDialog(self.frame,
     1558                                   'You have version '+local+
     1559                                   ' of GSAS-II installed, but the current version is '+repos+
     1560                                   '. However, '+str(len(mods))+
     1561                                   ' file(s) on your local computer have been modified.'
     1562                                   ' Updating will attempt to merge your local changes with '
     1563                                   'the latest GSAS-II version, but if '
     1564                                   'conflicts arise, local changes will be '
     1565                                   'discarded. It is also possible that the '
     1566                                   'local changes my prevent GSAS-II from running. '
     1567                                   'Press OK to start an update if this is acceptable:',
     1568                                   'Local GSAS-II Mods',
     1569                                   wx.OK|wx.CANCEL)
     1570            if dlg.ShowModal() != wx.ID_OK:
     1571                dlg.Destroy()
     1572                return
     1573            else:
     1574                dlg.Destroy()
     1575        else:
     1576            dlg = wx.MessageDialog(self.frame,
     1577                                   'You have version '+local+
     1578                                   ' of GSAS-II installed, but the current version is '+repos+
     1579                                   '. Press OK to start an update:',
     1580                                   'GSAS-II Updates',
     1581                                   wx.OK|wx.CANCEL)
     1582            if dlg.ShowModal() != wx.ID_OK:
     1583                dlg.Destroy()
     1584                return
     1585            dlg.Destroy()
     1586        print 'start updates'
     1587        dlg = wx.MessageDialog(self.frame,
     1588                               'Your project will now be saved, GSAS-II will exit and an update '
     1589                               'will be performed and GSAS-II will restart. Press Cancel to '
     1590                               'abort the update',
     1591                               'Start update?',
     1592                               wx.OK|wx.CANCEL)
     1593        if dlg.ShowModal() != wx.ID_OK:
     1594            dlg.Destroy()
     1595            return
     1596        dlg.Destroy()
     1597        self.frame.OnFileSave(event)
     1598        GSASIIpath.svnUpdateProcess(projectfile=self.frame.GSASprojectfile)
     1599        return
     1600
     1601    def OnSelectVersion(self,event):
     1602        '''Allow the user to select a specific version of GSAS-II
     1603        '''
     1604        if not GSASIIpath.whichsvn():
     1605            dlg = wx.MessageDialog(self,'No Subversion','Cannot update GSAS-II because subversion (svn) '+
     1606                                   'was not found.'
     1607                                   ,wx.OK)
     1608            dlg.ShowModal()
     1609            return
     1610        local = GSASIIpath.svnGetRev()
     1611        if local is None:
     1612            dlg = wx.MessageDialog(self.frame,
     1613                                   'Unable to run subversion on the GSAS-II current directory. Is GSAS-II installed correctly?',
     1614                                   'Subversion error',
     1615                                   wx.OK)
     1616            dlg.ShowModal()
     1617            return
     1618        mods = GSASIIpath.svnFindLocalChanges()
     1619        if mods:
     1620            dlg = wx.MessageDialog(self.frame,
     1621                                   'You have version '+local+
     1622                                   ' of GSAS-II installed'
     1623                                   '. However, '+str(len(mods))+
     1624                                   ' file(s) on your local computer have been modified.'
     1625                                   ' Downdating will attempt to merge your local changes with '
     1626                                   'the selected GSAS-II version. '
     1627                                   'Downdating is not encouraged because '
     1628                                   'if merging is not possible, your local changes will be '
     1629                                   'discarded. It is also possible that the '
     1630                                   'local changes my prevent GSAS-II from running. '
     1631                                   'Press OK to continue anyway.',
     1632                                   'Local GSAS-II Mods',
     1633                                   wx.OK|wx.CANCEL)
     1634            if dlg.ShowModal() != wx.ID_OK:
     1635                dlg.Destroy()
     1636                return
     1637            dlg.Destroy()
     1638        dlg = downdate(parent=self.frame)
     1639        if dlg.ShowModal() == wx.ID_OK:
     1640            ver = dlg.getVersion()
     1641        else:
     1642            dlg.Destroy()
     1643            return
     1644        dlg.Destroy()
     1645        print('start regress to '+str(ver))
     1646        GSASIIpath.svnUpdateProcess(
     1647            projectfile=self.frame.GSASprojectfile,
     1648            version=str(ver)
     1649            )
     1650        self.frame.OnFileSave(event)
     1651        return
     1652
     1653################################################################################
     1654class AddHelp(wx.Menu):
     1655    '''For the Mac: creates an entry to the help menu of type
     1656    'Help on <helpType>': where helpType is a reference to an HTML page to
     1657    be opened.
     1658
     1659    NOTE: when appending this menu (menu.Append) be sure to set the title to
     1660    '&Help' so that wx handles it correctly.
     1661    '''
     1662    def __init__(self,frame,helpType,helpLbl=None,title=''):
     1663        wx.Menu.__init__(self,title)
     1664        self.frame = frame
     1665        if helpLbl is None: helpLbl = helpType
     1666        # add a help item only when helpType is specified
     1667        helpobj = self.Append(text='Help on '+helpLbl,
     1668                              id=wx.ID_ANY, kind=wx.ITEM_NORMAL)
     1669        frame.Bind(wx.EVT_MENU, self.OnHelpById, helpobj)
     1670        self.HelpById = helpType
     1671       
     1672    def OnHelpById(self,event):
     1673        '''Called when Help on... is pressed in a menu. Brings up
     1674        a web page for documentation.
     1675        '''
     1676        ShowHelp(self.HelpById,self.frame)
     1677
     1678################################################################################
     1679class HelpButton(wx.Button):
     1680    '''Create a help button that displays help information.
     1681    The text is displayed in a modal message window.
     1682
     1683    TODO: it might be nice if it were non-modal: e.g. it stays around until
     1684    the parent is deleted or the user closes it, but this did not work for
     1685    me.
     1686
     1687    :param parent: the panel which will be the parent of the button
     1688    :param str msg: the help text to be displayed
     1689    '''
     1690    def __init__(self,parent,msg):
     1691        if sys.platform == "darwin":
     1692            wx.Button.__init__(self,parent,wx.ID_HELP)
     1693        else:
     1694            wx.Button.__init__(self,parent,wx.ID_ANY,'?',style=wx.BU_EXACTFIT)
     1695        self.Bind(wx.EVT_BUTTON,self._onPress)
     1696        self.msg=msg
     1697        self.parent = parent
     1698    def _onClose(self,event):
     1699        self.dlg.EndModal(wx.ID_CANCEL)
     1700    def _onPress(self,event):
     1701        'Respond to a button press by displaying the requested text'
     1702        #dlg = wx.MessageDialog(self.parent,self.msg,'Help info',wx.OK)
     1703        self.dlg = wx.Dialog(self.parent,wx.ID_ANY,'Help information',
     1704                        style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
     1705        #self.dlg.SetBackgroundColour(wx.WHITE)
     1706        mainSizer = wx.BoxSizer(wx.VERTICAL)
     1707        txt = wx.StaticText(self.dlg,wx.ID_ANY,self.msg)
     1708        mainSizer.Add(txt,1,wx.ALL|wx.EXPAND,10)
     1709        txt.SetBackgroundColour(wx.WHITE)
     1710
     1711        btnsizer = wx.BoxSizer(wx.HORIZONTAL)
     1712        btn = wx.Button(self.dlg, wx.ID_CLOSE)
     1713        btn.Bind(wx.EVT_BUTTON,self._onClose)
     1714        btnsizer.Add(btn)
     1715        mainSizer.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
     1716        self.dlg.SetSizer(mainSizer)
     1717        mainSizer.Fit(self.dlg)
     1718        self.dlg.ShowModal()
     1719        self.dlg.Destroy()
     1720################################################################################
     1721class MyHtmlPanel(wx.Panel):
     1722    '''Defines a panel to display HTML help information, as an alternative to
     1723    displaying help information in a web browser.
     1724    '''
     1725    def __init__(self, frame, id):
     1726        self.frame = frame
     1727        wx.Panel.__init__(self, frame, id)
     1728        sizer = wx.BoxSizer(wx.VERTICAL)
     1729        back = wx.Button(self, -1, "Back")
     1730        back.Bind(wx.EVT_BUTTON, self.OnBack)
     1731        self.htmlwin = G2HtmlWindow(self, id, size=(750,450))
     1732        sizer.Add(self.htmlwin, 1,wx.EXPAND)
     1733        sizer.Add(back, 0, wx.ALIGN_LEFT, 0)
     1734        self.SetSizer(sizer)
     1735        sizer.Fit(frame)       
     1736        self.Bind(wx.EVT_SIZE,self.OnHelpSize)
     1737    def OnHelpSize(self,event):         #does the job but weirdly!!
     1738        anchor = self.htmlwin.GetOpenedAnchor()
     1739        if anchor:           
     1740            self.htmlwin.ScrollToAnchor(anchor)
     1741            wx.CallAfter(self.htmlwin.ScrollToAnchor,anchor)
     1742            event.Skip()
     1743    def OnBack(self, event):
     1744        self.htmlwin.HistoryBack()
     1745    def LoadFile(self,file):
     1746        pos = file.rfind('#')
     1747        if pos != -1:
     1748            helpfile = file[:pos]
     1749            helpanchor = file[pos+1:]
     1750        else:
     1751            helpfile = file
     1752            helpanchor = None
     1753        self.htmlwin.LoadPage(helpfile)
     1754        if helpanchor is not None:
     1755            self.htmlwin.ScrollToAnchor(helpanchor)
     1756            xs,ys = self.htmlwin.GetViewStart()
     1757            self.htmlwin.Scroll(xs,ys-1)
     1758
     1759class G2HtmlWindow(wx.html.HtmlWindow):
     1760    '''Displays help information in a primitive HTML browser type window
     1761    '''
     1762    def __init__(self, parent, *args, **kwargs):
     1763        self.parent = parent
     1764        wx.html.HtmlWindow.__init__(self, parent, *args, **kwargs)
     1765    def LoadPage(self, *args, **kwargs):
     1766        wx.html.HtmlWindow.LoadPage(self, *args, **kwargs)
     1767        self.TitlePage()
     1768    def OnLinkClicked(self, *args, **kwargs):
     1769        wx.html.HtmlWindow.OnLinkClicked(self, *args, **kwargs)
     1770        xs,ys = self.GetViewStart()
     1771        self.Scroll(xs,ys-1)
     1772        self.TitlePage()
     1773    def HistoryBack(self, *args, **kwargs):
     1774        wx.html.HtmlWindow.HistoryBack(self, *args, **kwargs)
     1775        self.TitlePage()
     1776    def TitlePage(self):
     1777        self.parent.frame.SetTitle(self.GetOpenedPage() + ' -- ' +
     1778            self.GetOpenedPageTitle())
     1779################################################################################
     1780class downdate(wx.Dialog):
     1781    '''Dialog to allow a user to select a version of GSAS-II to install
     1782    '''
     1783    def __init__(self,parent=None):
     1784        style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
     1785        wx.Dialog.__init__(self, parent, wx.ID_ANY, 'Select Version', style=style)
     1786        pnl = wx.Panel(self)
     1787        sizer = wx.BoxSizer(wx.VERTICAL)
     1788        insver = GSASIIpath.svnGetRev(local=True)
     1789        curver = int(GSASIIpath.svnGetRev(local=False))
     1790        label = wx.StaticText(
     1791            pnl,  wx.ID_ANY,
     1792            'Select a specific GSAS-II version to install'
     1793            )
     1794        sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
     1795        sizer1 = wx.BoxSizer(wx.HORIZONTAL)
     1796        sizer1.Add(
     1797            wx.StaticText(pnl,  wx.ID_ANY,
     1798                          'Currently installed version: '+str(insver)),
     1799            0, wx.ALIGN_CENTRE|wx.ALL, 5)
     1800        sizer.Add(sizer1)
     1801        sizer1 = wx.BoxSizer(wx.HORIZONTAL)
     1802        sizer1.Add(
     1803            wx.StaticText(pnl,  wx.ID_ANY,
     1804                          'Select GSAS-II version to install: '),
     1805            0, wx.ALIGN_CENTRE|wx.ALL, 5)
     1806        self.spin = wx.SpinCtrl(pnl, wx.ID_ANY,size=(150,-1))
     1807        self.spin.SetRange(1, curver)
     1808        self.spin.SetValue(curver)
     1809        self.Bind(wx.EVT_SPINCTRL, self._onSpin, self.spin)
     1810        self.Bind(wx.EVT_KILL_FOCUS, self._onSpin, self.spin)
     1811        sizer1.Add(self.spin)
     1812        sizer.Add(sizer1)
     1813
     1814        line = wx.StaticLine(pnl,-1, size=(-1,3), style=wx.LI_HORIZONTAL)
     1815        sizer.Add(line, 0, wx.EXPAND|wx.ALIGN_CENTER|wx.ALL, 10)
     1816
     1817        self.text = wx.StaticText(pnl,  wx.ID_ANY, "")
     1818        sizer.Add(self.text, 0, wx.ALIGN_LEFT|wx.EXPAND|wx.ALL, 5)
     1819
     1820        line = wx.StaticLine(pnl,-1, size=(-1,3), style=wx.LI_HORIZONTAL)
     1821        sizer.Add(line, 0, wx.EXPAND|wx.ALIGN_CENTER|wx.ALL, 10)
     1822        sizer.Add(
     1823            wx.StaticText(
     1824                pnl,  wx.ID_ANY,
     1825                'If "Install" is pressed, your project will be saved;\n'
     1826                'GSAS-II will exit; The specified version will be loaded\n'
     1827                'and GSAS-II will restart. Press "Cancel" to abort.'),
     1828            0, wx.EXPAND|wx.ALL, 10)
     1829        btnsizer = wx.StdDialogButtonSizer()
     1830        btn = wx.Button(pnl, wx.ID_OK, "Install")
     1831        btn.SetDefault()
     1832        btnsizer.AddButton(btn)
     1833        btn = wx.Button(pnl, wx.ID_CANCEL)
     1834        btnsizer.AddButton(btn)
     1835        btnsizer.Realize()
     1836        sizer.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
     1837        pnl.SetSizer(sizer)
     1838        sizer.Fit(self)
     1839        self.topsizer=sizer
     1840        self.CenterOnParent()
     1841        self._onSpin(None)
     1842
     1843    def _onSpin(self,event):
     1844        'Called to load info about the selected version in the dialog'
     1845        ver = self.spin.GetValue()
     1846        d = GSASIIpath.svnGetLog(version=ver)
     1847        date = d.get('date','?').split('T')[0]
     1848        s = '(Version '+str(ver)+' created '+date
     1849        s += ' by '+d.get('author','?')+')'
     1850        msg = d.get('msg')
     1851        if msg: s += '\n\nComment: '+msg
     1852        self.text.SetLabel(s)
     1853        self.topsizer.Fit(self)
     1854
     1855    def getVersion(self):
     1856        'Get the version number in the dialog'
     1857        return self.spin.GetValue()
     1858################################################################################
     1859#### Display Help information
     1860################################################################################
     1861# define some globals
     1862htmlPanel = None
     1863htmlFrame = None
     1864htmlFirstUse = True
     1865helpLocDict = {}
     1866path2GSAS2 = os.path.dirname(os.path.realpath(__file__)) # save location of this file
     1867def ShowHelp(helpType,frame):
     1868    '''Called to bring up a web page for documentation.'''
     1869    global htmlFirstUse
     1870    # look up a definition for help info from dict
     1871    helplink = helpLocDict.get(helpType)
     1872    if helplink is None:
     1873        # no defined link to use, create a default based on key
     1874        helplink = 'gsasII.html#'+helpType.replace(' ','_')
     1875    helplink = os.path.join(path2GSAS2,'help',helplink)
     1876    # determine if a web browser or the internal viewer should be used for help info
     1877    if GSASIIpath.GetConfigValue('Help_mode'):
     1878        helpMode = GSASIIpath.GetConfigValue('Help_mode')
     1879    else:
     1880        helpMode = 'browser'
     1881    if helpMode == 'internal':
     1882        try:
     1883            htmlPanel.LoadFile(helplink)
     1884            htmlFrame.Raise()
     1885        except:
     1886            htmlFrame = wx.Frame(frame, -1, size=(610, 510))
     1887            htmlFrame.Show(True)
     1888            htmlFrame.SetTitle("HTML Window") # N.B. reset later in LoadFile
     1889            htmlPanel = MyHtmlPanel(htmlFrame,-1)
     1890            htmlPanel.LoadFile(helplink)
     1891    else:
     1892        pfx = "file://"
     1893        if sys.platform.lower().startswith('win'):
     1894            pfx = ''
     1895        if htmlFirstUse:
     1896            webbrowser.open_new(pfx+helplink)
     1897            htmlFirstUse = False
     1898        else:
     1899            webbrowser.open(pfx+helplink, new=0, autoraise=True)
     1900################################################################################
     1901#### Tutorials selector
     1902################################################################################
     1903               
    14191904if __name__ == '__main__':
    14201905    app = wx.PySimpleApp()
  • trunk/GSASIIgrid.py

    r1656 r1657  
    1111*GSASIIgrid: Basic GUI routines*
    1212--------------------------------
     13
     14Note that a number of routines here should be moved to GSASIIctrls eventually, such as
     15G2LoggedButton, EnumSelector, G2ChoiceButton, SingleFloatDialog, SingleStringDialog,
     16MultiStringDialog, G2MultiChoiceDialog, G2SingleChoiceDialog, G2ColumnIDDialog, ItemSelector, GridFractionEditor
     17
     18Probably SGMessageBox, SymOpDialog, DisAglDialog, too.
    1319
    1420'''
     
    2632import numpy.ma as ma
    2733import scipy.optimize as so
    28 import wx.html        # could postpone this for quicker startup
    29 import webbrowser     # could postpone this for quicker startup
    3034import GSASIIpath
    3135GSASIIpath.SetVersionNumber("$Revision$")
     
    5357cosd = lambda x: np.cos(x*np.pi/180.)
    5458
    55 # globals we will use later
    56 __version__ = None # gets overridden in GSASII.py
    57 path2GSAS2 = os.path.dirname(os.path.realpath(__file__)) # save location of this file
    58 helpLocDict = {}
    59 htmlPanel = None
    60 htmlFrame = None
    61 helpMode = 'browser'
    62 #if sys.platform.lower().startswith('win'): helpMode = 'internal' # need a global control to set this
    63    
    64 htmlFirstUse = True
     59# Define a short name for convenience
    6560WACV = wx.ALIGN_CENTER_VERTICAL
    6661
     
    235230        log.MakeButtonLog(self.locationcode,self.label)
    236231        self.handler(event)
     232       
     233################################################################################
     234################################################################################
    237235class EnumSelector(wx.ComboBox):
    238236    '''A customized :class:`wxpython.ComboBox` that selects items from a list
     
    13621360                subSizer.Add((-1,-1))
    13631361            else:               
    1364                 ch = HelpButton(panel,G2obj.fmtVarDescr(name))
     1362                ch = G2G.HelpButton(panel,G2obj.fmtVarDescr(name))
    13651363                subSizer.Add(ch,0,wx.LEFT|wx.RIGHT|WACV|wx.ALIGN_CENTER,1)
    13661364            subSizer.Add(wx.StaticText(panel,wx.ID_ANY,str(name)))
     
    14011399 
    14021400################################################################################
    1403 class downdate(wx.Dialog):
    1404     '''Dialog to allow a user to select a version of GSAS-II to install
    1405     '''
    1406     def __init__(self,parent=None):
    1407         style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
    1408         wx.Dialog.__init__(self, parent, wx.ID_ANY, 'Select Version', style=style)
    1409         pnl = wx.Panel(self)
    1410         sizer = wx.BoxSizer(wx.VERTICAL)
    1411         insver = GSASIIpath.svnGetRev(local=True)
    1412         curver = int(GSASIIpath.svnGetRev(local=False))
    1413         label = wx.StaticText(
    1414             pnl,  wx.ID_ANY,
    1415             'Select a specific GSAS-II version to install'
    1416             )
    1417         sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
    1418         sizer1 = wx.BoxSizer(wx.HORIZONTAL)
    1419         sizer1.Add(
    1420             wx.StaticText(pnl,  wx.ID_ANY,
    1421                           'Currently installed version: '+str(insver)),
    1422             0, wx.ALIGN_CENTRE|wx.ALL, 5)
    1423         sizer.Add(sizer1)
    1424         sizer1 = wx.BoxSizer(wx.HORIZONTAL)
    1425         sizer1.Add(
    1426             wx.StaticText(pnl,  wx.ID_ANY,
    1427                           'Select GSAS-II version to install: '),
    1428             0, wx.ALIGN_CENTRE|wx.ALL, 5)
    1429         self.spin = wx.SpinCtrl(pnl, wx.ID_ANY,size=(150,-1))
    1430         self.spin.SetRange(1, curver)
    1431         self.spin.SetValue(curver)
    1432         self.Bind(wx.EVT_SPINCTRL, self._onSpin, self.spin)
    1433         self.Bind(wx.EVT_KILL_FOCUS, self._onSpin, self.spin)
    1434         sizer1.Add(self.spin)
    1435         sizer.Add(sizer1)
    1436 
    1437         line = wx.StaticLine(pnl,-1, size=(-1,3), style=wx.LI_HORIZONTAL)
    1438         sizer.Add(line, 0, wx.EXPAND|wx.ALIGN_CENTER|wx.ALL, 10)
    1439 
    1440         self.text = wx.StaticText(pnl,  wx.ID_ANY, "")
    1441         sizer.Add(self.text, 0, wx.ALIGN_LEFT|wx.EXPAND|wx.ALL, 5)
    1442 
    1443         line = wx.StaticLine(pnl,-1, size=(-1,3), style=wx.LI_HORIZONTAL)
    1444         sizer.Add(line, 0, wx.EXPAND|wx.ALIGN_CENTER|wx.ALL, 10)
    1445         sizer.Add(
    1446             wx.StaticText(
    1447                 pnl,  wx.ID_ANY,
    1448                 'If "Install" is pressed, your project will be saved;\n'
    1449                 'GSAS-II will exit; The specified version will be loaded\n'
    1450                 'and GSAS-II will restart. Press "Cancel" to abort.'),
    1451             0, wx.EXPAND|wx.ALL, 10)
    1452         btnsizer = wx.StdDialogButtonSizer()
    1453         btn = wx.Button(pnl, wx.ID_OK, "Install")
    1454         btn.SetDefault()
    1455         btnsizer.AddButton(btn)
    1456         btn = wx.Button(pnl, wx.ID_CANCEL)
    1457         btnsizer.AddButton(btn)
    1458         btnsizer.Realize()
    1459         sizer.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    1460         pnl.SetSizer(sizer)
    1461         sizer.Fit(self)
    1462         self.topsizer=sizer
    1463         self.CenterOnParent()
    1464         self._onSpin(None)
    1465 
    1466     def _onSpin(self,event):
    1467         'Called to load info about the selected version in the dialog'
    1468         ver = self.spin.GetValue()
    1469         d = GSASIIpath.svnGetLog(version=ver)
    1470         date = d.get('date','?').split('T')[0]
    1471         s = '(Version '+str(ver)+' created '+date
    1472         s += ' by '+d.get('author','?')+')'
    1473         msg = d.get('msg')
    1474         if msg: s += '\n\nComment: '+msg
    1475         self.text.SetLabel(s)
    1476         self.topsizer.Fit(self)
    1477 
    1478     def getVersion(self):
    1479         'Get the version number in the dialog'
    1480         return self.spin.GetValue()
    1481 
    1482 ################################################################################
    1483 class MyHelp(wx.Menu):
    1484     '''
    1485     A class that creates the contents of a help menu.
    1486     The menu will start with two entries:
    1487 
    1488     * 'Help on <helpType>': where helpType is a reference to an HTML page to
    1489       be opened
    1490     * About: opens an About dialog using OnHelpAbout. N.B. on the Mac this
    1491       gets moved to the App menu to be consistent with Apple style.
    1492 
    1493     NOTE: for this to work properly with respect to system menus, the title
    1494     for the menu must be &Help, or it will not be processed properly:
    1495 
    1496     ::
    1497 
    1498        menu.Append(menu=MyHelp(self,...),title="&Help")
    1499 
    1500     '''
    1501     def __init__(self,frame,helpType=None,helpLbl=None,morehelpitems=[],title=''):
    1502         wx.Menu.__init__(self,title)
    1503         self.HelpById = {}
    1504         self.frame = frame
    1505         self.Append(help='', id=wx.ID_ABOUT, kind=wx.ITEM_NORMAL,
    1506             text='&About GSAS-II')
    1507         frame.Bind(wx.EVT_MENU, self.OnHelpAbout, id=wx.ID_ABOUT)
    1508         if GSASIIpath.whichsvn():
    1509             helpobj = self.Append(
    1510                 help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
    1511                 text='&Check for updates')
    1512             frame.Bind(wx.EVT_MENU, self.OnCheckUpdates, helpobj)
    1513             helpobj = self.Append(
    1514                 help='', id=wx.ID_ANY, kind=wx.ITEM_NORMAL,
    1515                 text='&Regress to an old GSAS-II version')
    1516             frame.Bind(wx.EVT_MENU, self.OnSelectVersion, helpobj)
    1517         for lbl,indx in morehelpitems:
    1518             helpobj = self.Append(text=lbl,
    1519                 id=wx.ID_ANY, kind=wx.ITEM_NORMAL)
    1520             frame.Bind(wx.EVT_MENU, self.OnHelpById, helpobj)
    1521             self.HelpById[helpobj.GetId()] = indx
    1522         # add a help item only when helpType is specified
    1523         if helpType is not None:
    1524             self.AppendSeparator()
    1525             if helpLbl is None: helpLbl = helpType
    1526             helpobj = self.Append(text='Help on '+helpLbl,
    1527                                   id=wx.ID_ANY, kind=wx.ITEM_NORMAL)
    1528             frame.Bind(wx.EVT_MENU, self.OnHelpById, helpobj)
    1529             self.HelpById[helpobj.GetId()] = helpType
    1530        
    1531     def OnHelpById(self,event):
    1532         '''Called when Help on... is pressed in a menu. Brings up
    1533         a web page for documentation.
    1534         '''
    1535         helpType = self.HelpById.get(event.GetId())
    1536         if helpType is None:
    1537             print 'Error: help lookup failed!',event.GetEventObject()
    1538             print 'id=',event.GetId()
    1539         else:
    1540             if helpType == 'Tutorials':
    1541                 self.frame.Tutorials = True
    1542             ShowHelp(helpType,self.frame)
    1543 
    1544     def OnHelpAbout(self, event):
    1545         "Display an 'About GSAS-II' box"
    1546         global __version__
    1547         info = wx.AboutDialogInfo()
    1548         info.Name = 'GSAS-II'
    1549         ver = GSASIIpath.svnGetRev()
    1550         if ver:
    1551             info.Version = 'Revision '+str(ver)+' (svn), version '+__version__
    1552         else:
    1553             info.Version = 'Revision '+str(GSASIIpath.GetVersionNumber())+' (.py files), version '+__version__
    1554         #info.Developers = ['Robert B. Von Dreele','Brian H. Toby']
    1555         info.Copyright = ('(c) ' + time.strftime('%Y') +
    1556 ''' Argonne National Laboratory
    1557 This product includes software developed
    1558 by the UChicago Argonne, LLC, as
    1559 Operator of Argonne National Laboratory.''')
    1560         info.Description = '''General Structure Analysis System-II (GSAS-II)
    1561 Robert B. Von Dreele and Brian H. Toby
    1562 
    1563 Please cite as:
    1564 B.H. Toby & R.B. Von Dreele, J. Appl. Cryst. 46, 544-549 (2013) '''
    1565 
    1566         info.WebSite = ("https://subversion.xray.aps.anl.gov/trac/pyGSAS","GSAS-II home page")
    1567         wx.AboutBox(info)
    1568 
    1569     def OnCheckUpdates(self,event):
    1570         '''Check if the GSAS-II repository has an update for the current source files
    1571         and perform that update if requested.
    1572         '''
    1573         if not GSASIIpath.whichsvn():
    1574             dlg = wx.MessageDialog(self.frame,
    1575                                    'No Subversion','Cannot update GSAS-II because subversion (svn) was not found.',
    1576                                    wx.OK)
    1577             dlg.ShowModal()
    1578             dlg.Destroy()
    1579             return
    1580         wx.BeginBusyCursor()
    1581         local = GSASIIpath.svnGetRev()
    1582         if local is None:
    1583             wx.EndBusyCursor()
    1584             dlg = wx.MessageDialog(self.frame,
    1585                                    'Unable to run subversion on the GSAS-II current directory. Is GSAS-II installed correctly?',
    1586                                    'Subversion error',
    1587                                    wx.OK)
    1588             dlg.ShowModal()
    1589             dlg.Destroy()
    1590             return
    1591         print 'Installed GSAS-II version: '+local
    1592         repos = GSASIIpath.svnGetRev(local=False)
    1593         wx.EndBusyCursor()
    1594         if repos is None:
    1595             dlg = wx.MessageDialog(self.frame,
    1596                                    'Unable to access the GSAS-II server. Is this computer on the internet?',
    1597                                    'Server unavailable',
    1598                                    wx.OK)
    1599             dlg.ShowModal()
    1600             dlg.Destroy()
    1601             return
    1602         print 'GSAS-II version on server: '+repos
    1603         if local == repos:
    1604             dlg = wx.MessageDialog(self.frame,
    1605                                    'GSAS-II is up-to-date. Version '+local+' is already loaded.',
    1606                                    'GSAS-II Up-to-date',
    1607                                    wx.OK)
    1608             dlg.ShowModal()
    1609             dlg.Destroy()
    1610             return
    1611         mods = GSASIIpath.svnFindLocalChanges()
    1612         if mods:
    1613             dlg = wx.MessageDialog(self.frame,
    1614                                    'You have version '+local+
    1615                                    ' of GSAS-II installed, but the current version is '+repos+
    1616                                    '. However, '+str(len(mods))+
    1617                                    ' file(s) on your local computer have been modified.'
    1618                                    ' Updating will attempt to merge your local changes with '
    1619                                    'the latest GSAS-II version, but if '
    1620                                    'conflicts arise, local changes will be '
    1621                                    'discarded. It is also possible that the '
    1622                                    'local changes my prevent GSAS-II from running. '
    1623                                    'Press OK to start an update if this is acceptable:',
    1624                                    'Local GSAS-II Mods',
    1625                                    wx.OK|wx.CANCEL)
    1626             if dlg.ShowModal() != wx.ID_OK:
    1627                 dlg.Destroy()
    1628                 return
    1629             else:
    1630                 dlg.Destroy()
    1631         else:
    1632             dlg = wx.MessageDialog(self.frame,
    1633                                    'You have version '+local+
    1634                                    ' of GSAS-II installed, but the current version is '+repos+
    1635                                    '. Press OK to start an update:',
    1636                                    'GSAS-II Updates',
    1637                                    wx.OK|wx.CANCEL)
    1638             if dlg.ShowModal() != wx.ID_OK:
    1639                 dlg.Destroy()
    1640                 return
    1641             dlg.Destroy()
    1642         print 'start updates'
    1643         dlg = wx.MessageDialog(self.frame,
    1644                                'Your project will now be saved, GSAS-II will exit and an update '
    1645                                'will be performed and GSAS-II will restart. Press Cancel to '
    1646                                'abort the update',
    1647                                'Start update?',
    1648                                wx.OK|wx.CANCEL)
    1649         if dlg.ShowModal() != wx.ID_OK:
    1650             dlg.Destroy()
    1651             return
    1652         dlg.Destroy()
    1653         self.frame.OnFileSave(event)
    1654         GSASIIpath.svnUpdateProcess(projectfile=self.frame.GSASprojectfile)
    1655         return
    1656 
    1657     def OnSelectVersion(self,event):
    1658         '''Allow the user to select a specific version of GSAS-II
    1659         '''
    1660         if not GSASIIpath.whichsvn():
    1661             dlg = wx.MessageDialog(self,'No Subversion','Cannot update GSAS-II because subversion (svn) '+
    1662                                    'was not found.'
    1663                                    ,wx.OK)
    1664             dlg.ShowModal()
    1665             return
    1666         local = GSASIIpath.svnGetRev()
    1667         if local is None:
    1668             dlg = wx.MessageDialog(self.frame,
    1669                                    'Unable to run subversion on the GSAS-II current directory. Is GSAS-II installed correctly?',
    1670                                    'Subversion error',
    1671                                    wx.OK)
    1672             dlg.ShowModal()
    1673             return
    1674         mods = GSASIIpath.svnFindLocalChanges()
    1675         if mods:
    1676             dlg = wx.MessageDialog(self.frame,
    1677                                    'You have version '+local+
    1678                                    ' of GSAS-II installed'
    1679                                    '. However, '+str(len(mods))+
    1680                                    ' file(s) on your local computer have been modified.'
    1681                                    ' Downdating will attempt to merge your local changes with '
    1682                                    'the selected GSAS-II version. '
    1683                                    'Downdating is not encouraged because '
    1684                                    'if merging is not possible, your local changes will be '
    1685                                    'discarded. It is also possible that the '
    1686                                    'local changes my prevent GSAS-II from running. '
    1687                                    'Press OK to continue anyway.',
    1688                                    'Local GSAS-II Mods',
    1689                                    wx.OK|wx.CANCEL)
    1690             if dlg.ShowModal() != wx.ID_OK:
    1691                 dlg.Destroy()
    1692                 return
    1693             dlg.Destroy()
    1694         dlg = downdate(parent=self.frame)
    1695         if dlg.ShowModal() == wx.ID_OK:
    1696             ver = dlg.getVersion()
    1697         else:
    1698             dlg.Destroy()
    1699             return
    1700         dlg.Destroy()
    1701         print('start regress to '+str(ver))
    1702         GSASIIpath.svnUpdateProcess(
    1703             projectfile=self.frame.GSASprojectfile,
    1704             version=str(ver)
    1705             )
    1706         self.frame.OnFileSave(event)
    1707         return
    1708 
    1709 ################################################################################
    1710 class AddHelp(wx.Menu):
    1711     '''For the Mac: creates an entry to the help menu of type
    1712     'Help on <helpType>': where helpType is a reference to an HTML page to
    1713     be opened.
    1714 
    1715     NOTE: when appending this menu (menu.Append) be sure to set the title to
    1716     '&Help' so that wx handles it correctly.
    1717     '''
    1718     def __init__(self,frame,helpType,helpLbl=None,title=''):
    1719         wx.Menu.__init__(self,title)
    1720         self.frame = frame
    1721         if helpLbl is None: helpLbl = helpType
    1722         # add a help item only when helpType is specified
    1723         helpobj = self.Append(text='Help on '+helpLbl,
    1724                               id=wx.ID_ANY, kind=wx.ITEM_NORMAL)
    1725         frame.Bind(wx.EVT_MENU, self.OnHelpById, helpobj)
    1726         self.HelpById = helpType
    1727        
    1728     def OnHelpById(self,event):
    1729         '''Called when Help on... is pressed in a menu. Brings up
    1730         a web page for documentation.
    1731         '''
    1732         ShowHelp(self.HelpById,self.frame)
    1733 
    1734 ################################################################################
    1735 class HelpButton(wx.Button):
    1736     '''Create a help button that displays help information.
    1737     The text is displayed in a modal message window.
    1738 
    1739     TODO: it might be nice if it were non-modal: e.g. it stays around until
    1740     the parent is deleted or the user closes it, but this did not work for
    1741     me.
    1742 
    1743     :param parent: the panel which will be the parent of the button
    1744     :param str msg: the help text to be displayed
    1745     '''
    1746     def __init__(self,parent,msg):
    1747         if sys.platform == "darwin":
    1748             wx.Button.__init__(self,parent,wx.ID_HELP)
    1749         else:
    1750             wx.Button.__init__(self,parent,wx.ID_ANY,'?',style=wx.BU_EXACTFIT)
    1751         self.Bind(wx.EVT_BUTTON,self._onPress)
    1752         self.msg=msg
    1753         self.parent = parent
    1754     def _onClose(self,event):
    1755         self.dlg.EndModal(wx.ID_CANCEL)
    1756     def _onPress(self,event):
    1757         'Respond to a button press by displaying the requested text'
    1758         #dlg = wx.MessageDialog(self.parent,self.msg,'Help info',wx.OK)
    1759         self.dlg = wx.Dialog(self.parent,wx.ID_ANY,'Help information',
    1760                         style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
    1761         #self.dlg.SetBackgroundColour(wx.WHITE)
    1762         mainSizer = wx.BoxSizer(wx.VERTICAL)
    1763         txt = wx.StaticText(self.dlg,wx.ID_ANY,self.msg)
    1764         mainSizer.Add(txt,1,wx.ALL|wx.EXPAND,10)
    1765         txt.SetBackgroundColour(wx.WHITE)
    1766 
    1767         btnsizer = wx.BoxSizer(wx.HORIZONTAL)
    1768         btn = wx.Button(self.dlg, wx.ID_CLOSE)
    1769         btn.Bind(wx.EVT_BUTTON,self._onClose)
    1770         btnsizer.Add(btn)
    1771         mainSizer.Add(btnsizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    1772         self.dlg.SetSizer(mainSizer)
    1773         mainSizer.Fit(self.dlg)
    1774         self.dlg.ShowModal()
    1775         self.dlg.Destroy()
    1776 ################################################################################
    1777 class MyHtmlPanel(wx.Panel):
    1778     '''Defines a panel to display HTML help information, as an alternative to
    1779     displaying help information in a web browser.
    1780     '''
    1781     def __init__(self, frame, id):
    1782         self.frame = frame
    1783         wx.Panel.__init__(self, frame, id)
    1784         sizer = wx.BoxSizer(wx.VERTICAL)
    1785         back = wx.Button(self, -1, "Back")
    1786         back.Bind(wx.EVT_BUTTON, self.OnBack)
    1787         self.htmlwin = G2HtmlWindow(self, id, size=(750,450))
    1788         sizer.Add(self.htmlwin, 1,wx.EXPAND)
    1789         sizer.Add(back, 0, wx.ALIGN_LEFT, 0)
    1790         self.SetSizer(sizer)
    1791         sizer.Fit(frame)       
    1792         self.Bind(wx.EVT_SIZE,self.OnHelpSize)
    1793     def OnHelpSize(self,event):         #does the job but weirdly!!
    1794         anchor = self.htmlwin.GetOpenedAnchor()
    1795         if anchor:           
    1796             self.htmlwin.ScrollToAnchor(anchor)
    1797             wx.CallAfter(self.htmlwin.ScrollToAnchor,anchor)
    1798             event.Skip()
    1799     def OnBack(self, event):
    1800         self.htmlwin.HistoryBack()
    1801     def LoadFile(self,file):
    1802         pos = file.rfind('#')
    1803         if pos != -1:
    1804             helpfile = file[:pos]
    1805             helpanchor = file[pos+1:]
    1806         else:
    1807             helpfile = file
    1808             helpanchor = None
    1809         self.htmlwin.LoadPage(helpfile)
    1810         if helpanchor is not None:
    1811             self.htmlwin.ScrollToAnchor(helpanchor)
    1812             xs,ys = self.htmlwin.GetViewStart()
    1813             self.htmlwin.Scroll(xs,ys-1)
    1814 
    1815 class G2HtmlWindow(wx.html.HtmlWindow):
    1816     '''Displays help information in a primitive HTML browser type window
    1817     '''
    1818     def __init__(self, parent, *args, **kwargs):
    1819         self.parent = parent
    1820         wx.html.HtmlWindow.__init__(self, parent, *args, **kwargs)
    1821     def LoadPage(self, *args, **kwargs):
    1822         wx.html.HtmlWindow.LoadPage(self, *args, **kwargs)
    1823         self.TitlePage()
    1824     def OnLinkClicked(self, *args, **kwargs):
    1825         wx.html.HtmlWindow.OnLinkClicked(self, *args, **kwargs)
    1826         xs,ys = self.GetViewStart()
    1827         self.Scroll(xs,ys-1)
    1828         self.TitlePage()
    1829     def HistoryBack(self, *args, **kwargs):
    1830         wx.html.HtmlWindow.HistoryBack(self, *args, **kwargs)
    1831         self.TitlePage()
    1832     def TitlePage(self):
    1833         self.parent.frame.SetTitle(self.GetOpenedPage() + ' -- ' +
    1834             self.GetOpenedPageTitle())
    1835 
    1836 ################################################################################
    18371401class DataFrame(wx.Frame):
    18381402    '''Create the data item window and all the entries in menus used in
     
    18931457            if not empty:
    18941458                menu.Append(wx.Menu(title=''),title='|') # add another separator
    1895             menu.Append(AddHelp(self.G2frame,helpType=helpType, helpLbl=helpLbl),
     1459            menu.Append(G2G.AddHelp(self.G2frame,helpType=helpType, helpLbl=helpLbl),
    18961460                        title='&Help')
    18971461        else: # other
    1898             menu.Append(menu=MyHelp(self,helpType=helpType, helpLbl=helpLbl),
     1462            menu.Append(menu=G2G.MyHelp(self,helpType=helpType, helpLbl=helpLbl),
    18991463                        title='&Help')
    19001464
     
    29282492                self.data[row][col] = value
    29292493        innerSetValue(row, col, value)
    2930        
    2931 ################################################################################
    2932 #### Help
    2933 ################################################################################
    2934 
    2935 def ShowHelp(helpType,frame):
    2936     '''Called to bring up a web page for documentation.'''
    2937     global htmlFirstUse
    2938     # look up a definition for help info from dict
    2939     helplink = helpLocDict.get(helpType)
    2940     if helplink is None:
    2941         # no defined link to use, create a default based on key
    2942         helplink = 'gsasII.html#'+helpType.replace(' ','_')
    2943     helplink = os.path.join(path2GSAS2,'help',helplink)
    2944     if helpMode == 'internal':
    2945         try:
    2946             htmlPanel.LoadFile(helplink)
    2947             htmlFrame.Raise()
    2948         except:
    2949             htmlFrame = wx.Frame(frame, -1, size=(610, 510))
    2950             htmlFrame.Show(True)
    2951             htmlFrame.SetTitle("HTML Window") # N.B. reset later in LoadFile
    2952             htmlPanel = MyHtmlPanel(htmlFrame,-1)
    2953             htmlPanel.LoadFile(helplink)
    2954     else:
    2955         pfx = "file://"
    2956         if sys.platform.lower().startswith('win'):
    2957             pfx = ''
    2958         if htmlFirstUse:
    2959             webbrowser.open_new(pfx+helplink)
    2960             htmlFirstUse = False
    2961         else:
    2962             webbrowser.open(pfx+helplink, new=0, autoraise=True)
    29632494
    29642495################################################################################
  • trunk/GSASIIpath.py

    r1566 r1657  
    309309    sys.exit()
    310310
     311def svnSwitchDir(rpath,URL):
     312    '''This performs a switch command to move files between subversion trees.
     313
     314    This is currently used for moving tutorial web pages and demo files
     315    into the GSAS-II source tree.
     316   
     317    :param str rpath: path to locate files, relative to the GSAS-II
     318      installation path (path2GSAS2)
     319    :param str URL: the repository URL
     320    '''
     321    import subprocess
     322    svn = whichsvn()
     323    if not svn: return
     324    fpath = os.path.join(path2GSAS2,rpath)
     325    cmd = [svn,'switch','--ignore-ancestry',URL,fpath,
     326           '--non-interactive',
     327           '--accept','theirs-conflict','--force']
     328    print("Loading files from "+URL)
     329    s = subprocess.Popen(cmd+['--trust-server-cert'],
     330                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     331    out,err = s.communicate()
     332    print out
     333    if err:
     334        s = subprocess.Popen(cmd,
     335                         stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     336        out,err = s.communicate()
     337        if err:
     338            print(60*"=")
     339            print ("****** An error was noted, see below *********")
     340            print(60*"=")
     341            print err
     342
    311343def IPyBreak_base():
    312344    '''A routine that invokes an IPython session at the calling location
  • trunk/GSASIIphsGUI.py

    r1655 r1657  
    4949import GSASIIpy3 as G2py3
    5050import GSASIIobj as G2obj
     51import GSASIIctrls as G2G
    5152import numpy as np
    5253import numpy.linalg as nl
     
    19441945                                             ISO['IsoModeList'],modeVals,ISO['G2ModeList']):
    19451946                if G2var in constDict:
    1946                     ch = G2gd.HelpButton(panel2,fmtHelp(constDict[G2var],var))
     1947                    ch = G2G.HelpButton(panel2,fmtHelp(constDict[G2var],var))
    19471948                    subSizer2.Add(ch,0,wx.LEFT|wx.RIGHT|WACV|wx.ALIGN_CENTER,1)
    19481949                else:
     
    19781979                                             ISO['OccModeList'],modeVals,ISO['G2OccModeList']):
    19791980                if G2var in constDict:
    1980                     ch = G2gd.HelpButton(panel2,fmtHelp(constDict[G2var],var))
     1981                    ch = G2G.HelpButton(panel2,fmtHelp(constDict[G2var],var))
    19811982                    subSizer2.Add(ch,0,wx.LEFT|wx.RIGHT|WACV|wx.ALIGN_CENTER,1)
    19821983                else:
  • trunk/GSASIIplot.py

    r1656 r1657  
    3737import GSASIIspc as G2spc
    3838import GSASIImath as G2mth
     39import GSASIIctrls as G2G
    3940import pytexture as ptx
    4041from  OpenGL.GL import *
     
    296297        bookmark = Page.GetPageText(pageNo)
    297298        bookmark = bookmark.strip(')').replace('(','_')
    298         G2gd.ShowHelp(bookmark,self.TopLevelParent)
     299        G2G.ShowHelp(bookmark,self.TopLevelParent)
    299300    def OnKey(self,event):
    300301        '''Provide user with list of keystrokes defined for plot as well as an
  • trunk/config_example.py

    r1560 r1657  
    3333logging_debug = None
    3434'Set to True to enable debug for logging'
     35
     36Help_mode = None
     37'Set to "internal" to use a Python-based web viewer rather than a web browser'
Note: See TracChangeset for help on using the changeset viewer.