Ignore:
Timestamp:
May 2, 2017 1:58:01 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
d66dbcc
Parents:
74d9780 (diff), 658dd57 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge with master

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/guiframe/gui_manager.py

    refe730d r914ba0a  
    33""" 
    44################################################################################ 
    5 #This software was developed by the University of Tennessee as part of the 
    6 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    7 #project funded by the US National Science Foundation. 
     5# This software was developed by the University of Tennessee as part of the 
     6# Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     7# project funded by the US National Science Foundation. 
    88# 
    9 #See the license text in license.txtz 
     9# See the license text in license.txtz 
    1010# 
    11 #copyright 2008, University of Tennessee 
     11# copyright 2008, University of Tennessee 
    1212################################################################################ 
    1313 
     
    2121import warnings 
    2222import re 
    23 warnings.simplefilter("ignore") 
    2423import logging 
    2524import traceback 
     
    5049from sas.sasgui.guiframe.customdir import setup_custom_config 
    5150 
     51logger = logging.getLogger(__name__) 
     52warnings.simplefilter("ignore") 
     53 
    5254config = get_local_config() 
    5355custom_config = setup_custom_config() 
    5456 
    55 #read some constants from config 
     57# read some constants from config 
    5658APPLICATION_STATE_EXTENSION = config.APPLICATION_STATE_EXTENSION 
    5759APPLICATION_NAME = config.__appname__ 
     
    6163SPLASH_SCREEN_HEIGHT = config.SPLASH_SCREEN_HEIGHT 
    6264SS_MAX_DISPLAY_TIME = config.SS_MAX_DISPLAY_TIME 
     65SAS_OPENCL = config.SAS_OPENCL 
    6366if not WELCOME_PANEL_ON: 
    6467    WELCOME_PANEL_SHOW = False 
     
    8184    # custom open_path 
    8285    open_folder = custom_config.DEFAULT_OPEN_FOLDER 
    83     if open_folder != None and os.path.isdir(open_folder): 
     86    if open_folder is not None and os.path.isdir(open_folder): 
    8487        DEFAULT_OPEN_FOLDER = os.path.abspath(open_folder) 
    8588    else: 
    8689        DEFAULT_OPEN_FOLDER = get_app_dir() 
     90    SAS_OPENCL = custom_config.SAS_OPENCL 
    8791except: 
    8892    DATALOADER_SHOW = True 
     
    99103    CLEANUP_PLOT = False 
    100104    DEFAULT_OPEN_FOLDER = get_app_dir() 
    101  
     105    DEFAULT_OPEN_FOLDER = PATH_APP 
     106    SAS_OPENCL = None 
    102107DEFAULT_STYLE = config.DEFAULT_STYLE 
    103108 
     
    134139        CHILD_FRAME = wx.Frame 
    135140 
     141#Initiliaze enviromental variable with custom setting but only if variable not set 
     142if SAS_OPENCL and not "SAS_OPENCL" in os.environ: 
     143    os.environ["SAS_OPENCL"] = SAS_OPENCL 
     144 
    136145class ViewerFrame(PARENT_FRAME): 
    137146    """ 
     
    147156        Initialize the Frame object 
    148157        """ 
    149         PARENT_FRAME.__init__(self, parent=parent, title=title, pos=pos, size=size) 
     158        PARENT_FRAME.__init__(self, parent=parent, title=title, 
     159                              pos=pos, size=size) 
    150160        # title 
    151161        self.title = title 
     
    168178        self.path = get_app_dir() 
    169179        self.application_name = APPLICATION_NAME 
    170         ## Application manager 
     180        # Application manager 
    171181        self._input_file = None 
    172182        self.app_manager = None 
    173183        self._mgr = None 
    174         #add current perpsective 
     184        # add current perpsective 
    175185        self._current_perspective = None 
    176186        self._plotting_plugin = None 
    177187        self._data_plugin = None 
    178         #Menu bar and item 
     188        # Menu bar and item 
    179189        self._menubar = None 
    180190        self._file_menu = None 
     
    190200        self._toolbar_menu = None 
    191201        self._save_appl_menu = None 
    192         #tool bar 
     202        # tool bar 
    193203        self._toolbar = None 
    194204        # Status bar 
     
    198208        # plot duck cleanup option 
    199209        self.cleanup_plots = CLEANUP_PLOT 
    200         ## Find plug-ins 
     210        # Find plug-ins 
    201211        # Modify this so that we can specify the directory to look into 
    202212        self.plugins = [] 
    203         #add local plugin 
     213        # add local plugin 
    204214        self.plugins += self._get_local_plugins() 
    205215        self.plugins += self._find_plugins() 
    206         ## List of panels 
     216        # List of panels 
    207217        self.panels = {} 
    208218        # List of plot panels 
     
    216226        self.defaultPanel = None 
    217227        self.welcome_panel_class = None 
    218         #panel on focus 
     228        # panel on focus 
    219229        self.panel_on_focus = None 
    220         #control_panel on focus 
     230        # control_panel on focus 
    221231        self.cpanel_on_focus = None 
    222232 
    223233        self.loader = Loader() 
    224         #data manager 
     234        # data manager 
    225235        self.batch_on = False 
    226236        from sas.sasgui.guiframe.data_manager import DataManager 
    227237        self._data_manager = DataManager() 
    228         self._data_panel = None#DataPanel(parent=self) 
     238        self._data_panel = None  # DataPanel(parent=self) 
    229239        if self.panel_on_focus is not None: 
    230             self._data_panel.set_panel_on_focus(self.panel_on_focus.window_caption) 
     240            self._data_panel.set_panel_on_focus( 
     241                self.panel_on_focus.window_caption) 
    231242        # list of plot panels in schedule to full redraw 
    232243        self.schedule = False 
    233         #self.callback = True 
     244        # self.callback = True 
    234245        self._idle_count = 0 
    235246        self.schedule_full_draw_list = [] 
     
    245256        # Register to status events 
    246257        self.Bind(EVT_STATUS, self._on_status_event) 
    247         #Register add extra data on the same panel event on load 
     258        # Register add extra data on the same panel event on load 
    248259        self.Bind(EVT_PANEL_ON_FOCUS, self.set_panel_on_focus) 
    249260        self.Bind(EVT_APPEND_BOOKMARK, self.append_bookmark) 
     
    275286                    frame.SetIcon(icon) 
    276287                except: 
    277                     logging.error("ViewerFrame.put_icon: could not set icon") 
     288                    logger.error("ViewerFrame.put_icon: could not set icon") 
    278289 
    279290    def get_client_size(self): 
     
    285296        # Adjust toolbar height 
    286297        toolbar = self.GetToolBar() 
    287         if toolbar != None: 
     298        if toolbar is not None: 
    288299            _, tb_h = toolbar.GetSizeTuple() 
    289300            height -= tb_h 
     
    298309                    fitpanel = item.fit_panel 
    299310 
    300         if fitpanel != None: 
     311        if fitpanel is not None: 
    301312            for i in range(0, fitpanel.GetPageCount()): 
    302313                fitpanel.GetPage(i)._populate_listbox() 
     
    325336        """ 
    326337        Display value of data into the application grid 
    327         :param data: dictionary of string and list of items 
     338        :param data_inputs: dictionary of string and list of items 
     339        :param details: descriptive string 
     340        :param file_name: file name 
     341        :param data_outputs: Data outputs 
    328342        """ 
    329343        self.batch_frame.set_data(data_inputs=data_inputs, 
     
    339353        """ 
    340354        path = None 
    341         if self._default_save_location == None: 
     355        if self._default_save_location is None: 
    342356            self._default_save_location = os.getcwd() 
    343357        wildcard = "(*.csv; *.txt)|*.csv; *.txt" 
     
    381395            line.strip() 
    382396            count = 0 
    383             if separator == None: 
     397            if separator is None: 
    384398                line.replace('\t', ' ') 
    385                 #found the first line containing the label 
     399                # found the first line containing the label 
    386400                col_name_toks = line.split() 
    387401                for item in col_name_toks: 
     
    392406            elif line.find(separator) != -1: 
    393407                if line.count(separator) >= 2: 
    394                     #found the first line containing the label 
     408                    # found the first line containing the label 
    395409                    col_name_toks = line.split(separator) 
    396410                    for item in col_name_toks: 
     
    446460            separator = "," 
    447461        fd.write(str(details)) 
    448         for col_name  in data.keys(): 
     462        for col_name in data.keys(): 
    449463            fd.write(str(col_name)) 
    450464            fd.write(separator) 
     
    509523        Set up custom configuration if exists 
    510524        """ 
    511         if custom_config == None: 
     525        if custom_config is None: 
    512526            return 
    513527 
     
    529543        Set default starting perspective 
    530544        """ 
    531         if custom_config == None: 
     545        if custom_config is None: 
    532546            return 
    533547        for plugin in self.plugins: 
     
    538552                    frame = plugin.get_frame() 
    539553                    frame.Show(True) 
    540                     #break 
     554                    # break 
    541555                else: 
    542556                    frame = plugin.get_frame() 
     
    589603        update edit menu if available 
    590604        """ 
    591         if event != None: 
     605        if event is not None: 
    592606            self.panel_on_focus = event.panel 
    593607        if self.panel_on_focus is not None: 
    594             #Disable save application if the current panel is in batch mode 
    595             flag = self.panel_on_focus.get_save_flag() 
    596             if self._save_appl_menu != None: 
    597                 self._save_appl_menu.Enable(flag) 
    598  
    599             if self.panel_on_focus not in self.plot_panels.values(): 
    600                 for ID in self.panels.keys(): 
    601                     if self.panel_on_focus != self.panels[ID]: 
    602                         self.panels[ID].on_kill_focus(None) 
    603  
    604             if self._data_panel is not None and \ 
    605                             self.panel_on_focus is not None: 
    606                 self.set_panel_on_focus_helper() 
    607                 #update toolbar 
    608                 self._update_toolbar_helper() 
    609                 #update edit menu 
    610                 self.enable_edit_menu() 
     608            # Disable save application if the current panel is in batch mode 
     609            try: 
     610                flag = self.panel_on_focus.get_save_flag() 
     611                if self._save_appl_menu is not None: 
     612                    self._save_appl_menu.Enable(flag) 
     613 
     614                if self.panel_on_focus not in self.plot_panels.values(): 
     615                    for ID in self.panels.keys(): 
     616                        if self.panel_on_focus != self.panels[ID]: 
     617                            self.panels[ID].on_kill_focus(None) 
     618 
     619                if self._data_panel is not None and \ 
     620                                self.panel_on_focus is not None: 
     621                    self.set_panel_on_focus_helper() 
     622                    # update toolbar 
     623                    self._update_toolbar_helper() 
     624                    # update edit menu 
     625                    self.enable_edit_menu() 
     626            except wx._core.PyDeadObjectError: 
     627                pass 
    611628 
    612629    def disable_app_menu(self, p_panel=None): 
     
    620637        Send focusing on ID to data explorer 
    621638        """ 
    622         if self._data_panel != None: 
     639        if self._data_panel is not None: 
    623640            self._data_panel.set_panel_on_focus(name) 
    624641 
     
    629646        caption = self.panel_on_focus.window_caption 
    630647        self.send_focus_to_datapanel(caption) 
    631         #update combo 
     648        # update combo 
    632649        if self.panel_on_focus in self.plot_panels.values(): 
    633650            combo = self._data_panel.cb_plotpanel 
     
    648665        """ 
    649666        cpanel = panel 
    650         if self._toolbar != None and cpanel._bookmark_flag: 
    651             for item in  self._toolbar.get_bookmark_items(): 
     667        if self._toolbar is not None and cpanel._bookmark_flag: 
     668            for item in self._toolbar.get_bookmark_items(): 
    652669                self._toolbar.remove_bookmark_item(item) 
    653670            self._toolbar.add_bookmark_default() 
     
    698715                                                str(self._input_file)) 
    699716            msg += str(sys.exc_value) + '\n' 
    700             logging.error(msg) 
     717            logger.error(msg) 
    701718        if self._data_panel is not None and len(self.plugins) > 0: 
    702719            self._data_panel.fill_cbox_analysis(self.plugins) 
     
    750767        field = self.sb.get_msg_position() 
    751768        wx.Frame.PushStatusText(self, field=field, 
    752                                 string="FIXME - PushStatusText called without text") 
     769                                string= 
     770                                "FIXME - PushStatusText called without text") 
    753771 
    754772    def add_perspective(self, plugin): 
     
    763781            if plugin.__class__ == item.__class__: 
    764782                msg = "Plugin %s already loaded" % plugin.sub_menu 
    765                 logging.info(msg) 
     783                logger.info(msg) 
    766784                is_loaded = True 
    767785        if not is_loaded: 
    768786            self.plugins.append(plugin) 
    769787            msg = "Plugin %s appended" % plugin.sub_menu 
    770             logging.info(msg) 
     788            logger.info(msg) 
    771789 
    772790    def _get_local_plugins(self): 
     
    775793        """ 
    776794        plugins = [] 
    777         #import guiframe local plugins 
    778         #check if the style contain guiframe.dataloader 
     795        # import guiframe local plugins 
     796        # check if the style contain guiframe.dataloader 
    779797        style1 = self.__gui_style & GUIFRAME.DATALOADER_ON 
    780798        style2 = self.__gui_style & GUIFRAME.PLOTTING_ON 
    781799        if style1 == GUIFRAME.DATALOADER_ON: 
    782800            try: 
    783                 from sas.sasgui.guiframe.local_perspectives.data_loader import data_loader 
     801                from sas.sasgui.guiframe.local_perspectives.data_loader \ 
     802                    import data_loader 
    784803                self._data_plugin = data_loader.Plugin() 
    785804                plugins.append(self._data_plugin) 
     
    787806                msg = "ViewerFrame._get_local_plugins:" 
    788807                msg += "cannot import dataloader plugin.\n %s" % sys.exc_value 
    789                 logging.error(msg) 
     808                logger.error(msg) 
    790809        if style2 == GUIFRAME.PLOTTING_ON: 
    791810            try: 
    792                 from sas.sasgui.guiframe.local_perspectives.plotting import plotting 
     811                from sas.sasgui.guiframe.local_perspectives.plotting \ 
     812                    import plotting 
    793813                self._plotting_plugin = plotting.Plugin() 
    794814                plugins.append(self._plotting_plugin) 
     
    796816                msg = "ViewerFrame._get_local_plugins:" 
    797817                msg += "cannot import plotting plugin.\n %s" % sys.exc_value 
    798                 logging.error(msg) 
     818                logger.error(msg) 
    799819 
    800820        return plugins 
     
    816836            else: 
    817837                file_list = [] 
    818             ## the default panel is the panel is the last plugin added 
     838            # the default panel is the panel is the last plugin added 
    819839            for item in file_list: 
    820840                toks = os.path.splitext(os.path.basename(item)) 
     
    823843                    if toks[1] == '.py' or toks[1] == '': 
    824844                        name = toks[0] 
    825                     #check the validity of the module name parsed 
    826                     #before trying to import it 
     845                    # check the validity of the module name parsed 
     846                    # before trying to import it 
    827847                    if name is None or name.strip() == '': 
    828848                        continue 
     
    841861                                plugins.append(module.Plugin()) 
    842862                                msg = "Found plug-in: %s" % module.PLUGIN_ID 
    843                                 logging.info(msg) 
     863                                logger.info(msg) 
    844864                            except: 
    845865                                msg = "Error accessing PluginPanel" 
     
    848868                    except: 
    849869                        msg = "ViewerFrame._find_plugins: %s" % sys.exc_value 
    850                         logging.error(msg) 
     870                        logger.error(msg) 
    851871                    finally: 
    852                         if not file == None: 
     872                        if file is not None: 
    853873                            file.close() 
    854874        except: 
    855875            # Should raise and catch at a higher level and 
    856876            # display error on status bar 
    857             logging.error(sys.exc_value) 
     877            logger.error(sys.exc_value) 
    858878 
    859879        return plugins 
     
    865885        """ 
    866886        self._window_width, self._window_height = self.get_client_size() 
    867         ## Default size 
     887        # Default size 
    868888        if DATAPANEL_WIDTH < 0: 
    869889            panel_width = int(self._window_width * 0.25) 
     
    871891            panel_width = DATAPANEL_WIDTH 
    872892        panel_height = int(self._window_height) 
    873         if self._data_panel is not None  and (p == self._data_panel): 
     893        if self._data_panel is not None and (p == self._data_panel): 
    874894            return panel_width, panel_height 
    875895        if hasattr(p, "CENTER_PANE") and p.CENTER_PANE: 
     
    903923        if self.welcome_panel_class is not None: 
    904924            welcome_panel = MDIFrame(self, None, 'None', (100, 200)) 
    905             self.defaultPanel = self.welcome_panel_class(welcome_panel, -1, style=wx.RAISED_BORDER) 
     925            self.defaultPanel = self.welcome_panel_class(welcome_panel, -1, 
     926                                                         style=wx.RAISED_BORDER) 
    906927            welcome_panel.set_panel(self.defaultPanel) 
    907928            self.defaultPanel.set_frame(welcome_panel) 
     
    919940                frame.SetPosition((0, mac_pos_y + size_t_bar)) 
    920941            frame.Show(True) 
    921         #add data panel 
     942        # add data panel 
    922943        win = MDIFrame(self, None, 'None', (100, 200)) 
    923944        data_panel = DataPanel(parent=win, id=-1) 
     
    927948        d_panel_width, h = self._get_panels_size(self._data_panel) 
    928949        win.SetSize((d_panel_width, h)) 
    929         is_visible = self.__gui_style & GUIFRAME.MANAGER_ON == GUIFRAME.MANAGER_ON 
     950        is_visible = self.__gui_style & \ 
     951                     GUIFRAME.MANAGER_ON == GUIFRAME.MANAGER_ON 
    930952        if IS_WIN: 
    931953            win.SetPosition((0, 0)) 
     
    973995        Update the data. 
    974996        """ 
    975         prev_id, data_state = self._data_manager.update_data( \ 
     997        prev_id, data_state = self._data_manager.update_data( 
    976998                              prev_data=prev_data, new_data=new_data) 
    977999 
     
    10241046        self._current_perspective.delete_data(data) 
    10251047 
    1026  
    10271048    def get_context_menu(self, plotpanel=None): 
    10281049        """ 
     
    10481069        menu_list = [] 
    10491070        item = self._current_perspective 
    1050         if item != None: 
     1071        if item is not None: 
    10511072            menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 
    10521073        return menu_list 
     
    10641085                self.delete_panel(ID) 
    10651086                break 
    1066         self.cpanel_on_focus.SetFocus() 
    1067  
     1087        if self.cpanel_on_focus is not None: 
     1088            self.cpanel_on_focus.SetFocus() 
    10681089 
    10691090    def popup_panel(self, p): 
     
    10781099        ID = wx.NewId() 
    10791100        self.panels[str(ID)] = p 
    1080         ## Check and set the size 
     1101        # Check and set the size 
    10811102        if PLOPANEL_WIDTH < 0: 
    10821103            p_panel_width = int(self._window_width * 0.45) 
     
    11171138        # Register for showing/hiding the panel 
    11181139        wx.EVT_MENU(self, ID, self.on_view) 
    1119         if p not in self.plot_panels.values() and p.group_id != None: 
     1140        if p not in self.plot_panels.values() and p.group_id is not None: 
    11201141            self.plot_panels[ID] = p 
    11211142            if len(self.plot_panels) == 1: 
     
    11231144                self.set_panel_on_focus(None) 
    11241145            if self._data_panel is not None and \ 
    1125                 self._plotting_plugin is not None: 
     1146                            self._plotting_plugin is not None: 
    11261147                ind = self._data_panel.cb_plotpanel.FindString('None') 
    11271148                if ind != wx.NOT_FOUND: 
     
    11661187        panel_name = 'No Panel on Focus' 
    11671188        c_panel = self.cpanel_on_focus 
    1168         if self._toolbar is  None: 
     1189        if self._toolbar is None: 
    11691190            return 
    11701191        if c_panel is not None: 
     
    12111232        """ 
    12121233        if self._menubar is None or self._current_perspective is None \ 
    1213             or self._menubar.GetMenuCount() == 0: 
     1234                or self._menubar.GetMenuCount() == 0: 
    12141235            return 
    1215         #replace or add a new menu for the current plugin 
     1236        # replace or add a new menu for the current plugin 
    12161237        pos = self._menubar.FindMenu(str(self._applications_menu_name)) 
    12171238        if pos == -1 and self._applications_menu_pos > 0: 
     
    12331254                for (menu, name) in menu_list: 
    12341255                    if self._applications_menu_pos == -1: 
    1235                         # Find the Analysis position and insert just after it if possible 
     1256                        # Find the Analysis position and insert just after it 
    12361257                        analysis_pos = self._menubar.FindMenu("Analysis") 
    12371258                        if analysis_pos == -1: 
     
    12421263                            self._applications_menu_pos = analysis_pos + 1 
    12431264                    else: 
    1244                         self._menubar.Insert(self._applications_menu_pos, menu, name) 
     1265                        self._menubar.Insert(self._applications_menu_pos, 
     1266                                             menu, name) 
    12451267                    self._applications_menu_name = name 
     1268 
     1269    def _on_marketplace_click(self, event): 
     1270        """ 
     1271            Click event for the help menu item linking to the Marketplace. 
     1272        """ 
     1273        import webbrowser 
     1274        webbrowser.open_new(config.marketplace_url) 
    12461275 
    12471276    def _add_help_menu(self): 
     
    12501279        tutorial PDF and documentation pages. 
    12511280        """ 
    1252         # Help menu 
    12531281        self._help_menu = wx.Menu() 
    1254         style = self.__gui_style & GUIFRAME.WELCOME_PANEL_ON 
    12551282 
    12561283        wx_id = wx.NewId() 
     
    12591286 
    12601287        if config._do_tutorial and (IS_WIN or sys.platform == 'darwin'): 
    1261             self._help_menu.AppendSeparator() 
    12621288            wx_id = wx.NewId() 
    12631289            self._help_menu.Append(wx_id, '&Tutorial', 'Software tutorial') 
     
    12651291 
    12661292        if config._do_acknowledge: 
    1267             self._help_menu.AppendSeparator() 
    12681293            wx_id = wx.NewId() 
    1269             self._help_menu.Append(wx_id, '&Acknowledge', 'Acknowledging SasView') 
     1294            self._help_menu.Append(wx_id, '&Acknowledge', 
     1295                                   'Acknowledging SasView') 
    12701296            wx.EVT_MENU(self, wx_id, self._onAcknowledge) 
    12711297 
    12721298        if config._do_aboutbox: 
    1273             self._help_menu.AppendSeparator() 
    1274             self._help_menu.Append(wx.ID_ABOUT, '&About', 'Software information') 
    1275             wx.EVT_MENU(self, wx.ID_ABOUT, self._onAbout) 
     1299            logger.info("Doing help menu") 
     1300            wx_id = wx.NewId() 
     1301            self._help_menu.Append(wx_id, '&About', 'Software information') 
     1302            wx.EVT_MENU(self, wx_id, self._onAbout) 
     1303 
     1304        if config.marketplace_url: 
     1305            wx_id = wx.NewId() 
     1306            self._help_menu.Append(wx_id, '&Model marketplace', '') 
     1307            wx.EVT_MENU(self, wx_id, self._on_marketplace_click) 
    12761308 
    12771309        # Checking for updates 
    12781310        wx_id = wx.NewId() 
    12791311        self._help_menu.Append(wx_id, '&Check for update', 
    1280                                'Check for the latest version of %s' % config.__appname__) 
     1312                               'Check for the latest version of %s' % 
     1313                               config.__appname__) 
    12811314        wx.EVT_MENU(self, wx_id, self._check_update) 
    12821315        self._menubar.Append(self._help_menu, '&Help') 
     
    12991332        wx_id = wx.NewId() 
    13001333        self._data_panel_menu = self._view_menu.Append(wx_id, 
    1301                                                        '&Show Data Explorer', '') 
     1334                                                       '&Show Data Explorer', 
     1335                                                       '') 
    13021336        wx.EVT_MENU(self, wx_id, self.show_data_panel) 
    13031337        if style == GUIFRAME.MANAGER_ON: 
     
    13101344        style1 = self.__gui_style & GUIFRAME.TOOLBAR_ON 
    13111345        if style1 == GUIFRAME.TOOLBAR_ON: 
    1312             self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', '') 
     1346            self._toolbar_menu = self._view_menu.Append(wx_id, '&Hide Toolbar', 
     1347                                                        '') 
    13131348        else: 
    1314             self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', '') 
     1349            self._toolbar_menu = self._view_menu.Append(wx_id, '&Show Toolbar', 
     1350                                                        '') 
    13151351        wx.EVT_MENU(self, wx_id, self._on_toggle_toolbar) 
    13161352 
    1317         if custom_config != None: 
     1353        if custom_config is not None: 
    13181354            self._view_menu.AppendSeparator() 
    13191355            wx_id = wx.NewId() 
     
    13261362        wx_id = wx.NewId() 
    13271363        self._view_menu.AppendSeparator() 
    1328         self._view_menu.Append(wx_id, 'Category Manager', 'Edit model categories') 
     1364        self._view_menu.Append(wx_id, 'Category Manager', 
     1365                               'Edit model categories') 
    13291366        wx.EVT_MENU(self, wx_id, self._on_category_manager) 
    13301367 
     
    13391376        self.batch_frame.Show(True) 
    13401377 
    1341     def  on_category_panel(self, event): 
     1378    def on_category_panel(self, event): 
    13421379        """ 
    13431380        On cat panel 
     
    13581395        """ 
    13591396        from sas.sasgui.guiframe.startup_configuration \ 
    1360         import StartupConfiguration as ConfDialog 
     1397            import StartupConfiguration as ConfDialog 
    13611398 
    13621399        dialog = ConfDialog(parent=self, gui=self.__gui_style) 
     
    13651402            dialog.write_custom_config() 
    13661403            # post event for info 
    1367             wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", info='info')) 
     1404            wx.PostEvent(self, StatusEvent(status="Wrote custom configuration", 
     1405                                           info='info')) 
    13681406        dialog.Destroy() 
    13691407 
     
    13841422                    id = wx.NewId() 
    13851423                    if plug.use_data(): 
    1386                         self._applications_menu.InsertCheckItem(pos, id, plug.sub_menu, \ 
    1387                             "Switch to analysis: %s" % plug.sub_menu) 
     1424                        self._applications_menu.InsertCheckItem(pos, id, 
     1425                                                                plug.sub_menu, 
     1426                                    "Switch to analysis: %s" % plug.sub_menu) 
    13881427                        plug_data_count = True 
    13891428                        pos += 1 
    13901429                    else: 
    13911430                        plug_no_data_count = True 
    1392                         self._applications_menu.AppendCheckItem(id, plug.sub_menu, \ 
     1431                        self._applications_menu.AppendCheckItem(id, 
     1432                                                                plug.sub_menu, 
    13931433                            "Switch to analysis: %s" % plug.sub_menu) 
    13941434                    wx.EVT_MENU(self, id, plug.on_perspective) 
     
    13961436            if not plug_data_count or not plug_no_data_count: 
    13971437                self._applications_menu.RemoveItem(separator) 
    1398             #Windows introduces a "Window" menu item during the layout process 
    1399             #somehow.  We want it to be next to the last item with Help as 
    1400             #last. However Analysis gets stuck after Window in normal ordering 
    1401             #so force it to be next after the Tools menu item.  Should we add 
    1402             #another menu item will need to check if this is still where we  
    1403             #want Analysis.  This is NOT an issue on the Mac which does not 
    1404             #have the extra Window menu item. 
    1405             #      March 2016 Code Camp  -- PDB  
     1438            # Windows introduces a "Window" menu item during the layout process 
     1439            # somehow.  We want it to be next to the last item with Help as 
     1440            # last. However Analysis gets stuck after Window in normal ordering 
     1441            # so force it to be next after the Tools menu item.  Should we add 
     1442            # another menu item will need to check if this is still where we 
     1443            # want Analysis.  This is NOT an issue on the Mac which does not 
     1444            # have the extra Window menu item. 
     1445            #      March 2016 Code Camp  -- PDB 
    14061446            Tools_pos = self._menubar.FindMenu("Tools") 
    1407             self._menubar.Insert(Tools_pos+1,self._applications_menu, 
     1447            self._menubar.Insert(Tools_pos+1, self._applications_menu, 
    14081448                                 '&Analysis') 
    14091449            self._check_applications_menu() 
     
    14261466            wx_id = wx.NewId() 
    14271467            hint_load_file = "read all analysis states saved previously" 
    1428             self._save_appl_menu = self._file_menu.Append(wx_id, '&Open Project', hint_load_file) 
     1468            self._save_appl_menu = self._file_menu.Append(wx_id, 
     1469                                                          '&Open Project', 
     1470                                                          hint_load_file) 
    14291471            wx.EVT_MENU(self, wx_id, self._on_open_state_project) 
    14301472 
     
    14351477            wx_id = wx.NewId() 
    14361478            self._save_appl_menu = self._file_menu.Append(wx_id, 
    1437                                                           '&Open Analysis', hint_load_file) 
     1479                                                          '&Open Analysis', 
     1480                                                          hint_load_file) 
    14381481            wx.EVT_MENU(self, wx_id, self._on_open_state_application) 
    14391482        if OPEN_SAVE_MENU: 
     
    14451488        if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 
    14461489            wx_id = wx.NewId() 
    1447             self._save_appl_menu = self._file_menu.Append(wx_id, \ 
    1448                 '&Save Analysis', 'Save state of the current active analysis panel') 
     1490            txt = '&Save Analysis' 
     1491            txt2 = 'Save state of the current active analysis panel' 
     1492            self._save_appl_menu = self._file_menu.Append(wx_id, txt, txt2) 
    14491493            wx.EVT_MENU(self, wx_id, self._on_save_application) 
    14501494        if not sys.platform == 'darwin': 
     
    14881532 
    14891533        self._edit_menu_copyas = wx.Menu() 
    1490         #Sub menu for Copy As... 
    1491         self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 'Copy current tab to Excel', 
     1534        # Sub menu for Copy As... 
     1535        self._edit_menu_copyas.Append(GUIFRAME_ID.COPYEX_ID, 
     1536                                      'Copy current tab to Excel', 
    14921537                                      'Copy parameter values in tabular format') 
    14931538        wx.EVT_MENU(self, GUIFRAME_ID.COPYEX_ID, self.on_copy_panel) 
    14941539 
    1495         self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 'Copy current tab to LaTeX', 
     1540        self._edit_menu_copyas.Append(GUIFRAME_ID.COPYLAT_ID, 
     1541                                      'Copy current tab to LaTeX', 
    14961542                                      'Copy parameter values in tabular format') 
    14971543        wx.EVT_MENU(self, GUIFRAME_ID.COPYLAT_ID, self.on_copy_panel) 
    1498  
    14991544 
    15001545        self._edit_menu.AppendMenu(GUIFRAME_ID.COPYAS_ID, 'Copy Params as...', 
     
    15191564        Return the gui style 
    15201565        """ 
    1521         return  self.__gui_style 
     1566        return self.__gui_style 
    15221567 
    15231568    def _add_menu_data(self): 
     
    15741619            return 
    15751620        frame = self.panels['default'].get_frame() 
    1576         if frame == None: 
     1621        if frame is None: 
    15771622            return 
    15781623        # Show default panel 
     
    16071652                self.schedule_full_draw_list.remove(panel) 
    16081653 
    1609             #delete uid number not str(uid) 
     1654            # delete uid number not str(uid) 
    16101655            if ID in self.plot_panels.keys(): 
    16111656                del self.plot_panels[ID] 
     
    16131658                del self.panels[ID] 
    16141659        else: 
    1615             logging.error("delete_panel: No such plot id as %s" % ID) 
     1660            logger.error("delete_panel: No such plot id as %s" % ID) 
    16161661 
    16171662    def create_gui_data(self, data, path=None): 
     
    16301675            log_msg += "load: %s\n" % str(basename) 
    16311676            log_msg += "Try Data opening...." 
    1632             logging.error(log_msg) 
     1677            logger.error(log_msg) 
    16331678            return 
    16341679 
    1635         #reading a state file 
     1680        # reading a state file 
    16361681        for plug in self.plugins: 
    16371682            reader, ext = plug.get_extensions() 
    16381683            if reader is not None: 
    1639                 #read the state of the single plugin 
     1684                # read the state of the single plugin 
    16401685                if extension == ext: 
    16411686                    reader.read(path) 
     
    16481693                        msg += "\n(%s)" % sys.exc_value 
    16491694                        wx.PostEvent(self, StatusEvent(status=msg, 
    1650                                                        info="error", type="stop")) 
     1695                                                       info="error", 
     1696                                                       type="stop")) 
    16511697                        return 
    16521698 
     
    16871733            basename = os.path.basename(path) 
    16881734            if APPLICATION_STATE_EXTENSION is not None \ 
    1689                 and basename.endswith(APPLICATION_STATE_EXTENSION): 
     1735                    and basename.endswith(APPLICATION_STATE_EXTENSION): 
    16901736                if is_project: 
    16911737                    for ID in self.plot_panels.keys(): 
     
    17091755            log_msg += "load: %s\n" % str(path) 
    17101756            log_msg += "Try File opening ...." 
    1711             logging.error(log_msg) 
     1757            logger.error(log_msg) 
    17121758            return 
    17131759        log_msg = '' 
     
    17151761        error_message = "" 
    17161762        try: 
    1717             logging.info("Loading Data...:\n" + str(path) + "\n") 
     1763            logger.info("Loading Data...:\n" + str(path) + "\n") 
    17181764            temp = self.loader.load(path) 
    17191765            if temp.__class__.__name__ == "list": 
     
    17301776            error_message += " Data from cmd:\n %s\n" % str(path) 
    17311777            error_message += str(sys.exc_value) + "\n" 
    1732             logging.error(error_message) 
     1778            logger.error(error_message) 
    17331779 
    17341780    def load_folder(self, path): 
     
    17511797            error_message += " Data folder from cmd:\n %s\n" % str(path) 
    17521798            error_message += str(sys.exc_value) + "\n" 
    1753             logging.error(error_message) 
     1799            logger.error(error_message) 
    17541800 
    17551801    def _on_open_state_application(self, event): 
     
    17571803        """ 
    17581804        path = None 
    1759         if self._default_save_location == None: 
     1805        if self._default_save_location is None: 
    17601806            self._default_save_location = os.getcwd() 
    17611807        wx.PostEvent(self, StatusEvent(status="Loading Analysis file...")) 
     
    17911837                    break 
    17921838            # Found the extension 
    1793             if ind != None: 
     1839            if ind is not None: 
    17941840                plug_wlist.remove(ind) 
    17951841                plug_wlist.insert(0, ind) 
     
    18061852    def _on_open_state_project(self, event): 
    18071853        """ 
     1854        Load in a .svs project file after removing all data from SasView 
    18081855        """ 
    18091856        path = None 
    1810         if self._default_save_location == None: 
     1857        if self._default_save_location is None: 
    18111858            self._default_save_location = os.getcwd() 
    1812         wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 
    1813         dlg = wx.FileDialog(self, 
    1814                             "Choose a file", 
    1815                             self._default_save_location, "", 
    1816                             APPLICATION_WLIST) 
    1817         if dlg.ShowModal() == wx.ID_OK: 
    1818             path = dlg.GetPath() 
     1859        msg = "This operation will set remove all data, plots and analyses from" 
     1860        msg += " SasView before loading the project. Do you wish to continue?" 
     1861        msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK | wx.CANCEL) 
     1862        if msg_box.ShowModal() == wx.ID_OK: 
     1863            self._data_panel.selection_cbox.SetValue('Select all Data') 
     1864            self._data_panel._on_selection_type(None) 
     1865            for _, theory_dict in self._data_panel.list_cb_theory.iteritems(): 
     1866                for key, value in theory_dict.iteritems(): 
     1867                    item, _, _ = value 
     1868                    item.Check(True) 
     1869 
     1870            wx.PostEvent(self, StatusEvent(status="Loading Project file...")) 
     1871            dlg = wx.FileDialog(self, "Choose a file", 
     1872                                self._default_save_location, "", 
     1873                                APPLICATION_WLIST) 
     1874            if dlg.ShowModal() == wx.ID_OK: 
     1875                path = dlg.GetPath() 
    18191876            if path is not None: 
    18201877                self._default_save_location = os.path.dirname(path) 
    1821         dlg.Destroy() 
    1822  
    1823         self.load_state(path=path, is_project=True) 
     1878                dlg.Destroy() 
     1879                # Reset to a base state 
     1880                self._on_reset_state() 
     1881                self._data_panel.on_remove(None, False) 
     1882                # Load the project file 
     1883                self.load_state(path=path, is_project=True) 
     1884 
     1885    def _on_reset_state(self): 
     1886        """ 
     1887        Resets SasView to its freshly opened state. 
     1888        :return: None 
     1889        """ 
     1890        # Reset all plugins to their base state 
     1891        self._data_panel.set_panel_on_focus() 
     1892        # Remove all loaded data 
     1893        for plugin in self.plugins: 
     1894            plugin.clear_panel() 
     1895        # Reset plot number to 0 
     1896        self.graph_num = 0 
    18241897 
    18251898    def _on_save_application(self, event): 
     
    18341907                wx.PostEvent(self, 
    18351908                             StatusEvent(status="Completed saving.")) 
    1836             except: 
     1909            except Exception: 
    18371910                msg = "Error occurred while saving: " 
     1911                msg += traceback.format_exc() 
    18381912                msg += "To save, the application panel should have a data set.." 
    18391913                wx.PostEvent(self, StatusEvent(status=msg)) 
     
    18431917        save the state of the SasView as *.svs 
    18441918        """ 
    1845         if self._current_perspective is  None: 
     1919        if self._current_perspective is None: 
    18461920            return 
    18471921        wx.PostEvent(self, StatusEvent(status="Saving Project file...")) 
     
    18711945            extens = APPLICATION_STATE_EXTENSION 
    18721946            fName = os.path.splitext(path)[0] + extens 
    1873             if doc != None: 
     1947            if doc is not None: 
    18741948                fd = open(fName, 'w') 
    18751949                fd.write(doc.toprettyxml()) 
     
    18821956                msg += "and model selected. " 
    18831957                msg += "No project was saved to %s" % (str(path)) 
    1884                 logging.warning(msg) 
     1958                logger.warning(msg) 
    18851959                wx.PostEvent(self, StatusEvent(status=msg, info="error")) 
    1886         except: 
     1960        except Exception: 
    18871961            msg = "Error occurred while saving: " 
     1962            msg += traceback.format_exc() 
    18881963            msg += "To save, at least one application panel " 
    18891964            msg += "should have a data set.." 
     
    19031978                    if data is not None: 
    19041979                        new_doc = reader.write_toXML(data, state) 
    1905                         if doc != None and hasattr(doc, "firstChild"): 
     1980                        if doc is not None and hasattr(doc, "firstChild"): 
    19061981                            child = new_doc.firstChild.firstChild 
    19071982                            doc.firstChild.appendChild(child) 
     
    19141989                if data is not None: 
    19151990                    new_doc = reader.write_toXML(data, state) 
    1916                     if doc != None and hasattr(doc, "firstChild"): 
     1991                    if doc is not None and hasattr(doc, "firstChild"): 
    19171992                        child = new_doc.firstChild.firstChild 
    19181993                        doc.firstChild.appendChild(child) 
     
    19462021        Quit the application 
    19472022        """ 
    1948         logging.info(" --- SasView session was closed --- \n") 
     2023        #IF SAS_OPENCL is set, settings are stored in the custom config file 
     2024        self._write_opencl_config_file() 
     2025        logger.info(" --- SasView session was closed --- \n") 
    19492026        wx.Exit() 
    19502027        sys.exit() 
     2028 
     2029    def _write_opencl_config_file(self): 
     2030        """ 
     2031        Writes OpenCL settings to custom config file, so they can be remmbered 
     2032        from session to session 
     2033        """ 
     2034        if custom_config is not None: 
     2035            sas_opencl = os.environ.get("SAS_OPENCL") 
     2036            new_config_lines = [] 
     2037            config_file = open(custom_config.__file__) 
     2038            config_lines = config_file.readlines() 
     2039            for line in config_lines: 
     2040                if "SAS_OPENCL" in line: 
     2041                    if sas_opencl: 
     2042                        new_config_lines.append("SAS_OPENCL = \"" + sas_opencl 
     2043                                                + "\"\n") 
     2044                    else: 
     2045                        new_config_lines.append("SAS_OPENCL = \"None\"\n") 
     2046                else: 
     2047                    new_config_lines.append(line) 
     2048            config_file.close() 
     2049 
     2050            #If custom_config is None, settings will not be remmbered 
     2051            new_config_file = open(custom_config.__file__,"w") 
     2052            new_config_file.writelines(new_config_lines) 
     2053            new_config_file.close() 
     2054        else: 
     2055            logger.info("Failed to save OPENCL settings in custom config file") 
     2056 
    19512057 
    19522058    def _check_update(self, event=None): 
     
    19622068        if response is not None: 
    19632069            try: 
    1964                 #  
    19652070                content = response.read().strip() 
    1966                 logging.info("Connected to www.sasview.org. Latest version: %s" 
    1967                              % (content)) 
     2071                logger.info("Connected to www.sasview.org. Latest version: %s", content) 
    19682072                version_info = json.loads(content) 
    19692073            except: 
    1970                 logging.info("Failed to connect to www.sasview.org") 
    1971         self._process_version(version_info, standalone=event == None)     
    1972  
    1973          
    1974          
    1975 #         import urllib2 
    1976 #         try: 
    1977 #             req = urllib2.Request(config.__update_URL__) 
    1978 #             res = urllib2.urlopen(req) 
    1979 #             content = res.read().strip() 
    1980 #             logging.info("Connected to www.sasview.org. Latest version: %s" 
    1981 #                          % (content)) 
    1982 #             version_info = json.loads(content) 
    1983 #         except: 
    1984 #             logging.info("Failed to connect to www.sasview.org") 
    1985 #             version_info = {"version": "0.0.0"} 
    1986 #         self._process_version(version_info, standalone=event == None) 
     2074                logger.info("Failed to connect to www.sasview.org") 
     2075        self._process_version(version_info, standalone=event is None) 
     2076 
    19872077 
    19882078    def _process_version(self, version_info, standalone=True): 
     
    20232113            msg = "guiframe: could not get latest application" 
    20242114            msg += " version number\n  %s" % sys.exc_value 
    2025             logging.error(msg) 
     2115            logger.error(msg) 
    20262116            if not standalone: 
    20272117                msg = "Could not connect to the application server." 
     
    20702160                    dialog.Show(True) 
    20712161                except: 
    2072                     logging.error("Error in _onTutorial: %s" % sys.exc_value) 
     2162                    logger.error("Error in _onTutorial: %s" % sys.exc_value) 
    20732163                    try: 
    20742164                        # Try an alternate method 
    2075                         logging.error("Could not open the tutorial pdf, trying xhtml2pdf") 
     2165                        logger.error( 
     2166                            "Could not open the tutorial pdf, trying xhtml2pdf") 
    20762167                        from xhtml2pdf import pisa 
    20772168                        pisa.startViewer(path) 
    20782169                    except: 
    2079                         logging.error("Could not open the tutorial pdf with xhtml2pdf") 
     2170                        logger.error( 
     2171                            "Could not open the tutorial pdf with xhtml2pdf") 
    20802172                        msg = "This feature requires 'PDF Viewer'\n" 
    20812173                        wx.MessageBox(msg, 'Error') 
     
    20872179                    try: 
    20882180                        # Try an alternate method 
    2089                         logging.error("Could not open the tutorial pdf, trying xhtml2pdf") 
     2181                        logger.error( 
     2182                            "Could not open the tutorial pdf, trying xhtml2pdf") 
    20902183                        from xhtml2pdf import pisa 
    20912184                        pisa.startViewer(path) 
    20922185                    except: 
    2093                         logging.error("Could not open the tutorial pdf with xhtml2pdf") 
    2094                         msg = "This feature requires the 'Preview' application\n" 
     2186                        logger.error( 
     2187                            "Could not open the tutorial pdf with xhtml2pdf") 
     2188                        msg = "This feature requires the Preview application\n" 
    20952189                        wx.MessageBox(msg, 'Error') 
    20962190 
     
    21072201        from documentation_window import DocumentationWindow 
    21082202        _TreeLocation = "user/user.html" 
    2109         DocumentationWindow(self, -1, _TreeLocation, "", "SasView Documentation") 
     2203        DocumentationWindow(self, -1, _TreeLocation, "", 
     2204                            "SasView Documentation") 
    21102205 
    21112206    def set_manager(self, manager): 
     
    21412236                if self.panels[item].ALWAYS_ON: 
    21422237                    continue 
    2143             if self.panels[item] == None: 
     2238            if self.panels[item] is None: 
    21442239                continue 
    21452240            if self.panels[item].window_name in panels: 
     
    21502245                # always show the data panel if enable 
    21512246                style = self.__gui_style & GUIFRAME.MANAGER_ON 
    2152                 if (style == GUIFRAME.MANAGER_ON) and self.panels[item] == self._data_panel: 
     2247                if (style == GUIFRAME.MANAGER_ON) \ 
     2248                        and self.panels[item] == self._data_panel: 
    21532249                    if 'data_panel' in self.panels.keys(): 
    21542250                        frame = self.panels['data_panel'].get_frame() 
    2155                         if frame == None: 
     2251                        if frame is None: 
    21562252                            continue 
    21572253                        flag = frame.IsShown() 
     
    21592255                else: 
    21602256                    frame = self.panels[item].get_frame() 
    2161                     if frame == None: 
     2257                    if frame is None: 
    21622258                        continue 
    21632259 
     
    21692265        show the data panel 
    21702266        """ 
    2171         if self._data_panel_menu == None: 
     2267        if self._data_panel_menu is None: 
    21722268            return 
    21732269        label = self._data_panel_menu.GetText() 
     
    21992295        :param data_list: dictionary of data's ID and value Data 
    22002296        """ 
    2201         #Store data into manager 
     2297        # Store data into manager 
    22022298        self.add_data_helper(data_list) 
    22032299        # set data in the data panel 
     
    22052301            data_state = self._data_manager.get_data_state(data_list.keys()) 
    22062302            self._data_panel.load_data_list(data_state) 
    2207         #if the data panel is shown wait for the user to press a button 
    2208         #to send data to the current perspective. if the panel is not 
    2209         #show  automatically send the data to the current perspective 
     2303        # if the data panel is shown wait for the user to press a button 
     2304        # to send data to the current perspective. if the panel is not 
     2305        # show  automatically send the data to the current perspective 
    22102306        style = self.__gui_style & GUIFRAME.MANAGER_ON 
    22112307        if style == GUIFRAME.MANAGER_ON: 
    2212             #wait for button press from the data panel to set_data 
     2308            # wait for button press from the data panel to set_data 
    22132309            if self._data_panel is not None: 
    22142310                self._data_panel.frame.Show(True) 
    22152311        else: 
    2216             #automatically send that to the current perspective 
     2312            # automatically send that to the current perspective 
    22172313            self.set_data(data_id=data_list.keys()) 
    22182314 
     
    22272323        else: 
    22282324            msg = "Guiframe does not have a current perspective" 
    2229             logging.info(msg) 
     2325            logger.info(msg) 
    22302326 
    22312327    def set_theory(self, state_id, theory_id=None): 
     
    22382334            except: 
    22392335                msg = "Guiframe set_theory: \n" + str(sys.exc_value) 
    2240                 logging.info(msg) 
     2336                logger.info(msg) 
    22412337                wx.PostEvent(self, StatusEvent(status=msg, info="error")) 
    22422338        else: 
    22432339            msg = "Guiframe does not have a current perspective" 
    2244             logging.info(msg) 
     2340            logger.info(msg) 
    22452341 
    22462342    def plot_data(self, state_id, data_id=None, 
     
    22752371                                                       info='warning')) 
    22762372            else: 
    2277                 #if not append then new plot 
     2373                # if not append then new plot 
    22782374                from sas.sasgui.guiframe.dataFitting import Data2D 
    22792375                if issubclass(Data2D, new_plot.__class__): 
    2280                     #for 2 D always plot in a separated new plot 
     2376                    # for 2 D always plot in a separated new plot 
    22812377                    new_plot.group_id = wx.NewId() 
    22822378                else: 
     
    23092405                                                group_id=group_id, 
    23102406                                                action='remove')) 
    2311                 #remove res plot: Todo: improve 
    23122407                wx.CallAfter(self._remove_res_plot, new_plot.id) 
    23132408        self._data_manager.delete_data(data_id=data_id, 
     
    23252420                                            action='remove')) 
    23262421        except: 
    2327             logging.error(sys.exc_value) 
     2422            logger.error(sys.exc_value) 
    23282423 
    23292424    def save_data1d(self, data, fname): 
     
    23512446            mypath = os.path.basename(path) 
    23522447 
    2353             #Instantiate a loader 
     2448            # Instantiate a loader 
    23542449            loader = Loader() 
    23552450            ext_format = ".txt" 
     
    23712466        dlg.Destroy() 
    23722467 
    2373  
    23742468    def _onsaveTXT(self, data, path): 
    23752469        """ 
     
    23782472        .. todo:: Refactor and remove this method. See 'TODO' in _onSave. 
    23792473        """ 
    2380         if not path == None: 
     2474        if path is not None: 
    23812475            out = open(path, 'w') 
    23822476            has_errors = True 
    2383             if data.dy == None or data.dy == []: 
     2477            if data.dy is None or data.dy == []: 
    23842478                has_errors = False 
    23852479            # Sanity check 
     
    23912485                    has_errors = False 
    23922486            if has_errors: 
    2393                 if data.dx != None and data.dx != []: 
     2487                if data.dx is not None and data.dx != []: 
    23942488                    out.write("<X>   <Y>   <dY>   <dX>\n") 
    23952489                else: 
     
    24002494            for i in range(len(data.x)): 
    24012495                if has_errors: 
    2402                     if data.dx != None and data.dx != []: 
    2403                         if  data.dx[i] != None: 
     2496                    if data.dx is not None and data.dx != []: 
     2497                        if data.dx[i] is not None: 
    24042498                            out.write("%g  %g  %g  %g\n" % (data.x[i], 
    24052499                                                            data.y[i], 
     
    24322526                                           info="error")) 
    24332527            raise ValueError, msg 
    2434         ## text = str(data) 
     2528        # text = str(data) 
    24352529        text = data.__str__() 
    24362530        text += 'Data Min Max:\n' 
    24372531        text += 'X_min = %s:  X_max = %s\n' % (xmin, max(data.x)) 
    24382532        text += 'Y_min = %s:  Y_max = %s\n' % (ymin, max(data.y)) 
    2439         if data.dy != None: 
     2533        if data.dy is not None: 
    24402534            text += 'dY_min = %s:  dY_max = %s\n' % (min(data.dy), max(data.dy)) 
    24412535        text += '\nData Points:\n' 
    24422536        x_st = "X" 
    24432537        for index in range(len(data.x)): 
    2444             if data.dy != None and len(data.dy) > index: 
     2538            if data.dy is not None and len(data.dy) > index: 
    24452539                dy_val = data.dy[index] 
    24462540            else: 
    24472541                dy_val = 0.0 
    2448             if data.dx != None and len(data.dx) > index: 
     2542            if data.dx is not None and len(data.dx) > index: 
    24492543                dx_val = data.dx[index] 
    24502544            else: 
    24512545                dx_val = 0.0 
    2452             if data.dxl != None and len(data.dxl) > index: 
     2546            if data.dxl is not None and len(data.dxl) > index: 
    24532547                if index == 0: 
    24542548                    x_st = "Xl" 
    24552549                dx_val = data.dxl[index] 
    2456             elif data.dxw != None and len(data.dxw) > index: 
     2550            elif data.dxw is not None and len(data.dxw) > index: 
    24572551                if index == 0: 
    24582552                    x_st = "Xw" 
     
    24942588            mypath = os.path.basename(path) 
    24952589 
    2496             #Instantiate a loader 
     2590            # Instantiate a loader 
    24972591            loader = Loader() 
    24982592 
     
    25312625            y_val = data.qy_data[index] 
    25322626            i_val = data.data[index] 
    2533             if data.err_data != None: 
     2627            if data.err_data is not None: 
    25342628                di_val = data.err_data[index] 
    2535             if data.dqx_data != None: 
     2629            if data.dqx_data is not None: 
    25362630                dx_val = data.dqx_data[index] 
    2537             if data.dqy_data != None: 
     2631            if data.dqy_data is not None: 
    25382632                dy_val = data.dqy_data[index] 
    25392633 
     
    25702664                    for name in self._current_perspective.get_perspective(): 
    25712665                        frame = panel.get_frame() 
    2572                         if frame != None: 
     2666                        if frame is not None: 
    25732667                            if name == panel.window_name: 
    25742668                                panel.on_set_focus(event=None) 
     
    25802674                self._data_panel.set_active_perspective(name) 
    25812675                self._check_applications_menu() 
    2582             #Set the SasView title 
     2676            # Set the SasView title 
    25832677            self._set_title_name(name) 
    25842678 
     
    26122706        """ 
    26132707 
    2614         if self.panel_on_focus not in self._plotting_plugin.plot_panels.values(): 
     2708        if self.panel_on_focus \ 
     2709                not in self._plotting_plugin.plot_panels.values(): 
    26152710            return 
     2711        check = "Theory1D" 
    26162712        is_theory = len(self.panel_on_focus.plots) <= 1 and \ 
    2617             self.panel_on_focus.plots.values()[0].__class__.__name__ == "Theory1D" 
     2713            self.panel_on_focus.plots.values()[0].__class__.__name__ == check 
    26182714 
    26192715        is_data2d = hasattr(new_plot, 'data') 
     
    26232719        has_meta_data = hasattr(new_plot, 'meta_data') 
    26242720 
    2625         #disable_add_data if the data is being recovered from  a saved state file. 
     2721        # disable_add_data if the data is being recovered from  a saved state 
    26262722        is_state_data = False 
    26272723        if has_meta_data: 
    26282724            if 'invstate' in new_plot.meta_data: 
    26292725                is_state_data = True 
    2630             if  'prstate' in new_plot.meta_data: 
     2726            if 'prstate' in new_plot.meta_data: 
    26312727                is_state_data = True 
    2632             if  'fitstate' in new_plot.meta_data: 
     2728            if 'fitstate' in new_plot.meta_data: 
    26332729                is_state_data = True 
    26342730 
    2635         return is_data1d and not is_data2d and not is_theory and not is_state_data 
     2731        return is_data1d and not is_data2d and not is_theory \ 
     2732               and not is_state_data 
    26362733 
    26372734    def check_multimode(self, perspective=None): 
     
    26392736        Check the perspective have batch mode capablitity 
    26402737        """ 
    2641         if perspective == None or self._data_panel == None: 
     2738        if perspective is None or self._data_panel is None: 
    26422739            return 
    26432740        flag = perspective.get_batch_capable() 
     
    26662763            self._edit_menu.Enable(GUIFRAME_ID.PASTE_ID, flag) 
    26672764 
    2668             #Copy menu 
     2765            # Copy menu 
    26692766            flag = self.cpanel_on_focus.get_copy_flag() 
    26702767            self._edit_menu_copyas.Enable(GUIFRAME_ID.COPYEX_ID, flag) 
     
    27972894            if data_panel.cb_plotpanel is not None: 
    27982895                # Check if any panel has the same caption 
    2799                 has_newstring = data_panel.cb_plotpanel.FindString\ 
    2800                                                             (str(new_caption)) 
     2896                has_newstring = data_panel.cb_plotpanel.FindString( 
     2897                    str(new_caption)) 
    28012898                caption = new_caption 
    28022899                if has_newstring != wx.NOT_FOUND: 
     
    29153012        drag 
    29163013        """ 
    2917         #Not implemeted 
     3014        # Not implemeted 
    29183015 
    29193016    def enable_reset(self): 
     
    29283025        """ 
    29293026        size_y = 0 
    2930         if self.GetToolBar() != None and self.GetToolBar().IsShown(): 
     3027        if self.GetToolBar() is not None and self.GetToolBar().IsShown(): 
    29313028            if not IS_LINUX: 
    29323029                _, size_y = self.GetToolBar().GetSizeTuple() 
     
    29433040        # append this panel in the schedule list if not in yet 
    29443041        if func == 'append': 
    2945             if not panel in self.schedule_full_draw_list: 
     3042            if panel not in self.schedule_full_draw_list: 
    29463043                self.schedule_full_draw_list.append(panel) 
    29473044        # remove this panel from schedule list 
     
    29633060 
    29643061        count = len(self.schedule_full_draw_list) 
    2965         #if not self.schedule: 
     3062        # if not self.schedule: 
    29663063        if count < 1: 
    29673064            self.set_schedule(False) 
     
    29783075                if ind == count: 
    29793076                    return 
    2980         #Simple redraw only for a panel shown 
     3077        # Simple redraw only for a panel shown 
     3078 
    29813079        def f_draw(panel): 
    29823080            """ 
     
    29913089                    # draw if possible 
    29923090                    panel.set_resizing(False) 
    2993                     #panel.Show(True) 
     3091                    # panel.Show(True) 
    29943092                    panel.draw_plot() 
    29953093                # Check if the panel is not shown 
     
    30263124        Set focus on a plot panel 
    30273125        """ 
    3028         if panel == None: 
     3126        if panel is None: 
    30293127            return 
    3030         #self.set_plot_unfocus() 
     3128        # self.set_plot_unfocus() 
    30313129        panel.on_set_focus(None) 
    30323130        # set focusing panel 
     
    30613159        try: 
    30623160            # check if it is time to redraw 
    3063             if self.GetCapture() == None: 
     3161            if self.GetCapture() is None: 
    30643162                # Draw plot, changes resizing too 
    30653163                self.full_draw() 
     
    30693167        # restart idle 
    30703168        self._redraw_idle(*args, **kwargs) 
    3071  
    30723169 
    30733170    def _redraw_idle(self, *args, **kwargs): 
     
    30843181    the GUI manager 
    30853182    """ 
    3086     ## Internal nickname for the window, used by the AUI manager 
     3183    # Internal nickname for the window, used by the AUI manager 
    30873184    window_name = "default" 
    3088     ## Name to appear on the window title bar 
     3185    # Name to appear on the window title bar 
    30893186    window_caption = "Welcome panel" 
    3090     ## Flag to tell the AUI manager to put this panel in the center pane 
     3187    # Flag to tell the AUI manager to put this panel in the center pane 
    30913188    CENTER_PANE = True 
     3189 
    30923190    def __init__(self, parent, *args, **kwds): 
    30933191        wx.Panel.__init__(self, parent, *args, **kwds) 
    30943192        PanelBase.__init__(self, parent) 
    3095  
    30963193 
    30973194 
     
    31213218            msg = "%s Could not load " % str(APPLICATION_NAME) 
    31223219            msg += "input file from command line.\n" 
    3123             logging.error(msg) 
     3220            logger.error(msg) 
    31243221        # Display a splash screen on top of the frame. 
    31253222        try: 
    31263223            if os.path.isfile(SPLASH_SCREEN_PATH): 
    3127                 self.s_screen = self.display_splash_screen(parent=self.frame, 
    3128                                                            path=SPLASH_SCREEN_PATH) 
     3224                self.s_screen = \ 
     3225                    self.display_splash_screen(parent=self.frame, 
     3226                                               path=SPLASH_SCREEN_PATH) 
    31293227            else: 
    31303228                self.frame.Show() 
     
    31343232            msg = "Cannot display splash screen\n" 
    31353233            msg += str(sys.exc_value) 
    3136             logging.error(msg) 
     3234            logger.error(msg) 
    31373235            self.frame.Show() 
    31383236 
     
    31893287                            os.remove(file_path) 
    31903288                except: 
    3191                     logging.error("gui_manager.clean_plugin_models:\n  %s" \ 
     3289                    logger.error("gui_manager.clean_plugin_models:\n  %s" 
    31923290                                  % sys.exc_value) 
    31933291 
     
    32033301        Build the GUI 
    32043302        """ 
    3205         #try to load file at the start 
     3303        # try to load file at the start 
    32063304        self.open_file() 
    32073305        self.frame.build_gui() 
     
    32793377        # Return the suggested position and size for the application frame. 
    32803378        return (posX, posY), (customWidth, customHeight), is_maximized 
    3281  
    32823379 
    32833380    def display_splash_screen(self, parent, 
     
    33163413        return s_screen 
    33173414 
    3318  
    33193415    def on_close_splash_screen(self, event): 
    33203416        """ 
     
    33363432        """ 
    33373433        # Initialize the Frame object 
    3338         CHILD_FRAME.__init__(self, parent=parent, id=wx.ID_ANY, title=title, size=size) 
     3434        CHILD_FRAME.__init__(self, parent=parent, id=wx.ID_ANY, 
     3435                             title=title, size=size) 
    33393436        self.parent = parent 
    33403437        self.name = "Untitled" 
    33413438        self.batch_on = self.parent.batch_on 
    33423439        self.panel = panel 
    3343         if panel != None: 
     3440        if panel is not None: 
    33443441            self.set_panel(panel) 
    33453442        self.Show(False) 
Note: See TracChangeset for help on using the changeset viewer.