Changeset 8faef63 in sasview for src


Ignore:
Timestamp:
May 14, 2018 2:41:00 AM (6 years ago)
Author:
wojciech
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, unittest-saveload
Children:
e979ad4
Parents:
d55e750
Message:

Moved dialog to SasView? class to avoid calling wx.App twice

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasview/sasview.py

    rd55e750 r8faef63  
    4343        from sas.sasgui.guiframe.gui_manager import SasViewApp 
    4444        self.gui = SasViewApp(0) 
     45        if sys.platform == "darwin": 
     46            self.check_sasmodels_compiler() 
    4547        # Set the application manager for the GUI 
    4648        self.gui.set_manager(self) 
     
    130132        self.gui.MainLoop() 
    131133 
     134    def check_sasmodels_compiler(self): 
     135        """ 
     136        Checking c compiler for sasmodels and raises xcode command line 
     137        tools for installation 
     138        """ 
     139        import wx 
     140        import subprocess 
     141        #Generic message box created becuase standard MessageBox is not moveable 
     142        class GenericMessageBox(wx.Dialog): 
     143            def __init__(self, parent, text, title = ''): 
     144 
     145                wx.Dialog.__init__(self, parent, -1, title = title, 
     146                               size = (360,180), pos=(20,60), 
     147                               style = wx.STAY_ON_TOP | wx.DEFAULT_DIALOG_STYLE) 
     148                panel = wx.Panel(self, -1) 
     149                top_row_sizer = wx.BoxSizer(wx.HORIZONTAL) 
     150 
     151                error_bitmap = wx.ArtProvider.GetBitmap( 
     152                    wx.ART_ERROR, wx.ART_MESSAGE_BOX 
     153                ) 
     154                error_bitmap_ctrl = wx.StaticBitmap(panel, -1) 
     155                error_bitmap_ctrl.SetBitmap(error_bitmap) 
     156                label = wx.StaticText(panel, -1, text) 
     157                top_row_sizer.Add(error_bitmap_ctrl, flag=wx.ALL, border=10) 
     158                top_row_sizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL) 
     159 
     160                #Create the OK button in the bottom row. 
     161                #ok_button = wx.Button(panel, wx.ID_OK ) 
     162                ok_button = wx.Button(panel, wx.ID_OK ) 
     163                self.Bind(wx.EVT_BUTTON, self.on_ok, source=ok_button) 
     164                ok_button.SetFocus() 
     165                ok_button.SetDefault() 
     166 
     167                sizer = wx.BoxSizer(wx.VERTICAL) 
     168                sizer.Add(top_row_sizer) 
     169                sizer.Add(ok_button, flag=wx.ALIGN_CENTER | wx.ALL, border=5) 
     170                panel.SetSizer(sizer) 
     171 
     172            def on_ok(self, event): 
     173                self.Destroy() 
     174        logger = logging.getLogger(__name__) 
     175        try: 
     176            subprocess.check_output(["cc","--version"], stderr=subprocess.STDOUT) 
     177            dlg = GenericMessageBox(parent=None, 
     178            text='No compiler installed. Please follow instruction for\n' 
     179                'command line developers tools installation and restart SasView\n\n' 
     180                'Alternatively one can use OpenCL compiler,\n' 
     181                 'which can be setup from menu Fitting->OpenCL Options\n\n', 
     182            title = 'Compiler Info') 
     183            dlg.Show(1) 
     184 
     185        except subprocess.CalledProcessError as exc: 
     186 
     187            dlg = GenericMessageBox(parent=None, 
     188            text='No compiler installed. Please follow instruction for\n' 
     189                'command line developers tools installation and restart SasView\n\n' 
     190                'Alternatively one can use OpenCL compiler,\n' 
     191                 'which can be setup from menu Fitting->OpenCL Options\n\n', 
     192            title = 'Compiler Info') 
     193            dlg.ShowModal() 
     194 
     195            logger.error("No compiler installed. %s\n"%(exc)) 
     196            logger.error(traceback.format_exc()) 
     197 
     198        #raise RuntimeError("Terminating sasview") 
    132199 
    133200def setup_logging(): 
     
    196263    backend_bases.FigureCanvasBase.filetypes.pop('pgf', None) 
    197264 
    198 def check_sasmodels_compiler(): 
    199     """ 
    200     Checking c compiler for sasmodels and raises xcode command line 
    201     tools for installation 
    202     """ 
    203     import wx 
    204     import subprocess 
    205     #Generic message box created becuase standard MessageBox is not moveable 
    206     class GenericMessageBox(wx.Dialog): 
    207         def __init__(self, parent, text, title = ''): 
    208             wx.Dialog.__init__(self, parent, -1, title = title, 
    209                                size = (360,180), pos=(20,20), 
    210                                style = wx.DEFAULT_DIALOG_STYLE ) 
    211             panel = wx.Panel(self, -1) 
    212             top_row_sizer = wx.BoxSizer(wx.HORIZONTAL) 
    213  
    214             error_bitmap = wx.ArtProvider.GetBitmap( 
    215                 wx.ART_ERROR, wx.ART_MESSAGE_BOX 
    216             ) 
    217             error_bitmap_ctrl = wx.StaticBitmap(panel, -1) 
    218             error_bitmap_ctrl.SetBitmap(error_bitmap) 
    219             label = wx.StaticText(panel, -1, text) 
    220             top_row_sizer.Add(error_bitmap_ctrl, flag=wx.ALL, border=10) 
    221             top_row_sizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL) 
    222  
    223             #Create the OK button in the bottom row. 
    224             ok_button = wx.Button(panel, wx.ID_OK ) 
    225             ok_button.SetFocus() 
    226             ok_button.SetDefault() 
    227  
    228             sizer = wx.BoxSizer(wx.VERTICAL) 
    229             sizer.Add(top_row_sizer) 
    230             sizer.Add(ok_button, flag=wx.ALIGN_CENTER | wx.ALL, border=5) 
    231             panel.SetSizer(sizer) 
    232  
    233     logger = logging.getLogger(__name__) 
    234     try: 
    235         subprocess.check_output(["cc","--version"], stderr=subprocess.STDOUT) 
    236     except subprocess.CalledProcessError as exc: 
    237         app = wx.App() 
    238         dlg = GenericMessageBox(parent=None, 
    239             text='No compiler installed. Please follow instruction for\n' 
    240                 'command line developers tools installation and restart SasView\n\n' 
    241                 'Alternatively one can use OpenCL compiler,\n' 
    242                  'which can be setup from menu Fitting->OpenCL Options\n\n' 
    243                 'SasView is terminating now\n', 
    244             title = 'Compiler Info') 
    245         dlg.ShowModal() 
    246  
    247         logger.error("No compiler installed. %s\n"%(exc)) 
    248         logger.error(traceback.format_exc()) 
    249  
    250         #raise RuntimeError("Terminating sasview") 
    251  
    252265def setup_sasmodels(): 
    253266    """ 
     
    272285    setup_sasmodels() 
    273286    setup_wx() 
    274     if sys.platform == "darwin": 
    275         check_sasmodels_compiler() 
    276287    SasView() 
    277288 
Note: See TracChangeset for help on using the changeset viewer.