Ignore:
Timestamp:
Jan 2, 2017 7:18:34 AM (7 years ago)
Author:
wojciech
Children:
2a1b92eb
Parents:
b39debba
Message:

Added message dialog for testing results

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/gpu_options.py

    r6c6aa83 r25594ca  
    1414from sas.sasgui.guiframe.documentation_window import DocumentationWindow 
    1515import imp 
     16 
     17 
     18class CustomMessageBox(wx.Dialog): 
     19    def __init__(self, parent, msg, title): 
     20        wx.Dialog.__init__(self, parent, title=title) 
     21        text = wx.TextCtrl(self, style=wx.TE_READONLY|wx.BORDER_NONE) 
     22        text.SetValue(msg) 
     23        text.SetBackgroundColour(self.GetBackgroundColour()) 
     24        self.ShowModal() 
     25        self.Destroy() 
     26 
    1627 
    1728class GpuOptions(wx.Dialog): 
     
    137148        return clinfo 
    138149 
    139     def write_to_config_file(self): 
     150 
     151    def _write_to_config_file(self): 
    140152        from sas.sasgui.guiframe.customdir import SetupCustom 
    141         from sas.sasgui.guiframe.gui_manager import get_app_dir, _find_local_config 
    142  
    143         PATH_APP = get_app_dir() 
    144         c_conf_dir = SetupCustom().setup_dir(PATH_APP) 
     153        from sas.sasgui.guiframe.gui_manager import _find_local_config 
     154 
     155        c_conf_dir = SetupCustom().find_dir() 
    145156        self.custom_config = _find_local_config('custom_config', c_conf_dir) 
    146157        if self.custom_config is None: 
    147158            self.custom_config = _find_local_config('custom_config', os.getcwd()) 
    148             if self.custom_config is None: 
    149                 msgConfig = "Custom_config file was not imported" 
    150                 logging.info(msgConfig) 
    151             else: 
    152                 logging.info("using custom_config in %s" % os.getcwd()) 
    153         else: 
    154             logging.info("using custom_config from %s" % c_conf_dir) 
    155159 
    156160        #How to store it in file 
    157         self.custom_config.SAS_OPENCL = self.sas_opencl 
     161        new_config_lines = [] 
     162        config_file = open(self.custom_config.__file__[:-1]) 
     163        if self.custom_config is not None: 
     164            config_lines = config_file.readlines() 
     165            for line in config_lines: 
     166                if "SAS_OPENCL" in line: 
     167                    if self.sas_opencl: 
     168                        new_config_lines.append("SAS_OPENCL = \""+self.sas_opencl+"\"") 
     169                    else: 
     170                        new_config_lines.append("SAS_OPENCL = None") 
     171                else: 
     172                    new_config_lines.append(line) 
     173        config_file.close() 
     174        new_config_file = open(self.custom_config.__file__[:-1],"w") 
     175        new_config_file.writelines(new_config_lines) 
     176        new_config_file.close() 
     177 
     178        #After file is touched module needs to be reloaded 
     179        self.custom_config = _find_local_config('custom_config', c_conf_dir) 
     180        if self.custom_config is None: 
     181            self.custom_config = _find_local_config('custom_config', os.getcwd()) 
    158182 
    159183    def on_check(self, event): 
     
    183207            if "SAS_OPENCL" in os.environ: 
    184208                del(os.environ["SAS_OPENCL"]) 
    185  
    186209        try: 
    187210            imp.find_module('sasmodels.kernelcl') 
     
    191214        if kernelcl_exist: 
    192215            sasmodels.kernelcl.ENV = None 
    193             #self.custom_config.SAS_OPENCL = self.sas_opencl 
    194  
     216 
     217        self._write_to_config_file() 
    195218        #Need to reload sasmodels.core module to account SAS_OPENCL = "None" 
    196219        reload(sasmodels.core) 
     
    201224        Close window on accpetance 
    202225        """ 
     226        import sasmodels 
    203227        for btn in self.buttons: 
    204228            btn.SetValue(0) 
     229 
    205230        self.sas_opencl=None 
     231        del(os.environ["SAS_OPENCL"]) 
     232 
     233        try: 
     234            imp.find_module('sasmodels.kernelcl') 
     235            kernelcl_exist = True 
     236        except: 
     237            kernelcl_exist = False 
     238        if kernelcl_exist: 
     239            sasmodels.kernelcl.ENV = None 
     240 
     241        self._write_to_config_file() 
     242        reload(sasmodels.core) 
     243        event.Skip() 
    206244 
    207245    def on_test(self, event): 
     
    211249        import json 
    212250        import platform 
    213  
    214251        import sasmodels 
    215252        from sasmodels.model_test import model_tests 
     253 
    216254        try: 
    217255            from sasmodels.kernelcl import environment 
     
    239277            'failing tests': failures, 
    240278        } 
    241         print(json.dumps(info['failing tests'])) 
     279 
     280        msg_info = "OpenCL tests" 
     281        msg = "OpenCL test completed!\n" 
     282        msg += "Sasmodels version: " 
     283        msg += info['version']+"\n" 
     284        msg += "Platform used: " 
     285        msg += json.dumps(info['platform'])+"\n" 
     286        msg += "OpenCL driver: " 
     287        msg += json.dumps(info['opencl'])+"\n" 
     288        if len(failures) > 0: 
     289            msg += 'Failing tests:\n' 
     290            msg += json.dumps(info['failing tests']) 
     291        else: 
     292            msg+="All tests passed\n" 
     293 
     294        CustomMessageBox(self.panel1, msg, msg_info) 
    242295 
    243296    def on_help(self, event): 
Note: See TracChangeset for help on using the changeset viewer.