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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.