Changeset 4148


Ignore:
Timestamp:
Sep 13, 2019 5:06:45 PM (2 years ago)
Author:
toby
Message:

refactor to create wx app before anything else gets done

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r3858 r4148  
    1414
    1515This is the script to start the GSAS-II graphical user interface (GUI).
    16 This script imports GSASIIpath, does some minor initialization
    17 and then launches :func:`GSASIIdataGUI.GSASIImain`,
    18 which creates a wx.Application that in turns creates the GUI.
    19 If the GSAS-II binaries are not installed or are incompatible with
    20 the OS/Python packages, the user is asked if they should be updated
    21 from the subversion site.
     16This script imports GSASIIpath, which does some minor initialization
     17and then (before any wxPython calls can be made) creates a wx.App application.
     18A this point :func:`GSASIIpath.SetBinaryPath` is called to establish
     19the directory where GSAS-II binaries are found. If the binaries
     20are not installed or are incompatible with the OS/Python packages,
     21the user is asked if they should be updated from the subversion site.
     22The wxPython app is then passed to :func:`GSASIIdataGUI.GSASIImain`,
     23which creates the GSAS-II GUI and finally the event loop is started.
    2224'''
    2325
    2426import platform
     27import wx
    2528import GSASIIpath
     29GSASIIpath.SetVersionNumber("$Revision$")
    2630
    2731__version__ = '1.0.0'
    2832
    2933if __name__ == '__main__':
     34    application = wx.App(0) # create the GUI framework
    3035    try:
    3136        GSASIIpath.SetBinaryPath(True)
     
    4550        print('Updating...')
    4651        GSASIIpath.svnUpdateProcess()
    47     GSASIIpath.SetVersionNumber("$Revision$")
    4852    GSASIIpath.InvokeDebugOpts()
    4953    import GSASIIdataGUI as G2gd   
    50     G2gd.GSASIImain() # start the GUI
     54    G2gd.GSASIImain(application) # start the GUI
     55    application.MainLoop()
  • trunk/GSASIIdataGUI.py

    r4136 r4148  
    366366        pass
    367367    print ("This is GSAS-II revision %s"%str(GSASIIpath.GetVersionNumber())+'\n')
    368    
     368
     369def warnNumpyVersion(application):
     370    dlg = wx.MessageDialog(application.main,
     371                'version '+ np.__version__ +
     372                ' of numpy produces .gpx files that are not compatible with older versions: please upgrade or downgrade numpy to avoid this version',
     373                'numpy Warning',wx.OK)
     374    try:
     375        dlg.CenterOnParent()
     376        dlg.ShowModal()
     377    finally:
     378        dlg.Destroy()
     379       
    369380###############################################################################
    370 # Main application
     381# GUI creation
    371382###############################################################################
    372 def GSASIImain():
    373     '''Start up the GSAS-II application'''
     383def GSASIImain(application):
     384    '''Start up the GSAS-II GUI'''                       
    374385    ShowVersions()
    375386    GUIpatches()
    376     #GSASIIpath.InvokeDebugOpts()
    377     #application = GSASIImain() # don't redirect output, someday we
    378     # may want to do this if we can
    379     application = GSASIIGUI(0)
     387    knownVersions = ['2.7','3.6','3.7','3.8']
     388    if platform.python_version()[:3] not in knownVersions:
     389        dlg = wx.MessageDialog(None,
     390                'GSAS-II requires Python 2.7.x or 3.6+\n Yours is '+sys.version.split()[0],
     391                'Python version error',  wx.OK)
     392        try:
     393            dlg.ShowModal()
     394        finally:
     395            dlg.Destroy()
     396        sys.exit()
     397           
     398    application.main = GSASII(None)  # application.main is the main wx.Frame (G2frame in most places)
     399    application.SetTopWindow(application.main)
     400    # save the current package versions
     401    application.main.PackageVersions = G2fil.get_python_versions([wx, mpl, np, sp, ogl])
     402    if np.__version__ == '1.16.0':
     403        wx.CallLater(100,warnNumpyVersion,application)
    380404    if GSASIIpath.GetConfigValue('wxInspector'):
    381405        import wx.lib.inspection as wxeye
    382406        wxeye.InspectionTool().Show()
    383407
    384     #application.main.OnRefine(None)
    385408    try:
    386409        application.SetAppDisplayName('GSAS-II')
     
    389412    #application.GetTopWindow().SendSizeEvent()
    390413    application.GetTopWindow().Show(True)
    391     application.MainLoop()
    392 
    393 class GSASIIGUI(wx.App):
    394     '''Defines a wxApp for GSAS-II
    395 
    396     Creates a wx frame (self.main) which contains the display of the
    397     data tree.
    398     '''
    399     def OnInit(self):
    400         '''Called automatically when the app is created.'''
    401         knownVersions = ['2.7','3.6','3.7','3.8']
    402         if platform.python_version()[:3] not in knownVersions:
    403             dlg = wx.MessageDialog(None,
    404                 'GSAS-II requires Python 2.7.x or 3.6+\n Yours is '+sys.version.split()[0],
    405                 'Python version error',  wx.OK)
    406             try:
    407                 dlg.ShowModal()
    408             finally:
    409                 dlg.Destroy()
    410             sys.exit()
    411         self.main = GSASII(None)
    412         self.SetTopWindow(self.main)
    413         # save the current package versions
    414         self.main.PackageVersions = G2fil.get_python_versions([wx, mpl, np, sp, ogl])
    415         if np.__version__ == '1.16.0':
    416             wx.CallLater(100,self.warnNumpyVersion)
    417         return True
    418     def warnNumpyVersion(self):
    419         dlg = wx.MessageDialog(self.main,
    420                 'version '+ np.__version__ +
    421                 ' of numpy produces .gpx files that are not compatible with older versions: please upgrade or downgrade numpy to avoid this version',
    422                 'numpy Warning',wx.OK)
    423         try:
    424             dlg.CenterOnParent()
    425             dlg.ShowModal()
    426         finally:
    427             dlg.Destroy()
    428    
    429     # def MacOpenFile(self, filename):
    430     #     '''Called on Mac every time a file is dropped on the app when it is running,
    431     #     treat this like a File/Open project menu action.
    432     #     Should be ignored on other platforms
    433     #     '''
    434     #     # PATCH: Canopy 1.4 script main seems dropped on app; ignore .py files
    435     #     print 'MacOpen',filename
    436     #     if os.path.splitext(filename)[1] == '.py': return
    437     #     # end PATCH
    438     #     self.main.OnFileOpen(None,filename)
    439     # removed because this gets triggered when a file is on the command line in canopy 1.4 -- not likely used anyway
    440414
    441415################################################################################
Note: See TracChangeset for help on using the changeset viewer.