Ignore:
File:
1 edited

Legend:

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

    r957af0d r78f75d02  
    2727import urllib 
    2828import urllib2 
    29 import json 
     29 
    3030 
    3131from sas.guiframe.events import EVT_CATEGORY 
     
    4646from sas.guiframe.CategoryManager import CategoryManager 
    4747from sas.dataloader.loader import Loader 
    48 from sas.guiframe.proxy import Connection 
    4948from matplotlib import _pylab_helpers 
    50  
    5149 
    5250def get_app_dir(): 
     
    5452        The application directory is the one where the default custom_config.py 
    5553        file resides. 
    56  
    57         :returns: app_path - the path to the applicatin directory 
    5854    """ 
    5955    # First, try the directory of the executable we are running 
     
    7268 
    7369    # Finally, try the directory of the sasview module 
    74     # TODO: gui_manager will have to know about sasview until we 
     70    #TODO: gui_manager will have to know about sasview until we 
    7571    # clean all these module variables and put them into a config class 
    7672    # that can be passed by sasview.py. 
     
    235231        Initialize the Frame object 
    236232        """ 
    237  
    238233        PARENT_FRAME.__init__(self, parent=parent, title=title, pos=pos, size=size) 
    239234        # title 
     
    364359                    frame.SetIcon(icon) 
    365360                except: 
    366                     pass 
     361                    logging.error("ViewerFrame.put_icon: could not set icon") 
    367362 
    368363    def get_client_size(self): 
     
    752747            self._toolbar.Realize() 
    753748 
    754  
    755749    def build_gui(self): 
    756750        """ 
     
    778772        # Append item from plugin under menu file if necessary 
    779773        self._populate_file_menu() 
    780  
    781774 
    782775        if not wx.VERSION_STRING >= '3.0.0.0': 
     
    822815        # Load panels 
    823816        self._load_panels() 
    824         self.set_default_perspective() 
    825817 
    826818    def SetStatusText(self, *args, **kwds): 
     
    838830    def PushStatusText(self, *args, **kwds): 
    839831        """ 
    840         .. todo:: No message is passed. What is this supposed to do? 
     832            FIXME: No message is passed. What is this supposed to do? 
    841833        """ 
    842834        field = self.sb.get_msg_position() 
    843835        wx.Frame.PushStatusText(self, field=field, 
    844                                 string="FIXME - PushStatusText called without text") 
     836                                string="FIXME: PushStatusText called without text") 
    845837 
    846838    def add_perspective(self, plugin): 
     
    898890        :param dir: directory in which to look for plug-ins 
    899891 
    900         :returns: list of plug-ins 
     892        :return: list of plug-ins 
    901893 
    902894        """ 
     
    931923                        if hasattr(module, "PLUGIN_ID"): 
    932924                            try: 
    933                                 plug = module.Plugin() 
    934                                 if plug.set_default_perspective(): 
    935                                     self._current_perspective = plug 
    936                                 plugins.append(plug) 
    937  
     925                                plugins.append(module.Plugin()) 
    938926                                msg = "Found plug-in: %s" % module.PLUGIN_ID 
    939927                                logging.info(msg) 
     
    949937                            file.close() 
    950938        except: 
    951             # Should raise and catch at a higher level and 
     939            # Should raise and catch at a higher level and  
    952940            # display error on status bar 
    953941            logging.error(sys.exc_value) 
     
    996984 
    997985        # Set up welcome panel 
    998         # TODO: this needs serious simplification 
     986        #TODO: this needs serious simplification 
    999987        if self.welcome_panel_class is not None: 
    1000988            welcome_panel = MDIFrame(self, None, 'None', (100, 200)) 
     
    10861074    def onfreeze(self, theory_id): 
    10871075        """ 
    1088         Saves theory/model and passes to data loader. 
    1089  
    1090         ..warning:: This seems to be the exact same code as the next 
    1091         function called simply freeze. This probably needs fixing 
    10921076        """ 
    10931077        data_state_list = self._data_manager.freeze(theory_id) 
     
    11011085    def freeze(self, data_id, theory_id): 
    11021086        """ 
    1103         Saves theory/model and passes to data loader. 
    1104  
    1105         ..warning:: This seems to be the exact same code as the next 
    1106         function called simply freeze. This probably needs fixing 
    11071087        """ 
    11081088        data_state_list = self._data_manager.freeze_theory(data_id=data_id, 
     
    11691149        :param p: panel object to add to the AUI manager 
    11701150 
    1171         :returns: ID of the event associated with the new panel [int] 
     1151        :return: ID of the event associated with the new panel [int] 
    11721152 
    11731153        """ 
     
    11901170        # Append nummber 
    11911171        captions = self._get_plotpanel_captions() 
    1192         # FIXME: Fix this awful loop 
     1172        #FIXME: Fix this aweful loop 
    11931173        while (1): 
    11941174            caption = windowcaption + '%s' % str(self.graph_num) 
     
    15111491                for item in plugin.populate_file_menu(): 
    15121492                    m_name, m_hint, m_handler = item 
    1513                     id = wx.NewId() 
    1514                     self._file_menu.Append(id, m_name, m_hint) 
    1515                     wx.EVT_MENU(self, id, m_handler) 
     1493                    wx_id = wx.NewId() 
     1494                    self._file_menu.Append(wx_id, m_name, m_hint) 
     1495                    wx.EVT_MENU(self, wx_id, m_handler) 
    15161496                self._file_menu.AppendSeparator() 
    15171497 
    15181498        style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS 
    15191499        if OPEN_SAVE_MENU: 
    1520             id = wx.NewId() 
     1500            wx_id = wx.NewId() 
    15211501            hint_load_file = "read all analysis states saved previously" 
    1522             self._save_appl_menu = self._file_menu.Append(id, '&Open Project', hint_load_file) 
    1523             wx.EVT_MENU(self, id, self._on_open_state_project) 
     1502            self._save_appl_menu = self._file_menu.Append(wx_id, '&Open Project', hint_load_file) 
     1503            wx.EVT_MENU(self, wx_id, self._on_open_state_project) 
    15241504 
    15251505        if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 
     
    15271507            hint_load_file = "Read a status files and load" 
    15281508            hint_load_file += " them into the analysis" 
    1529             id = wx.NewId() 
    1530             self._save_appl_menu = self._file_menu.Append(id, 
     1509            wx_id = wx.NewId() 
     1510            self._save_appl_menu = self._file_menu.Append(wx_id, 
    15311511                                                          '&Open Analysis', hint_load_file) 
    1532             wx.EVT_MENU(self, id, self._on_open_state_application) 
     1512            wx.EVT_MENU(self, wx_id, self._on_open_state_application) 
    15331513        if OPEN_SAVE_MENU: 
    15341514            self._file_menu.AppendSeparator() 
    1535             id = wx.NewId() 
    1536             self._file_menu.Append(id, '&Save Project', 
     1515            wx_id = wx.NewId() 
     1516            self._file_menu.Append(wx_id, '&Save Project', 
    15371517                                   'Save the state of the whole analysis') 
    1538             wx.EVT_MENU(self, id, self._on_save_project) 
     1518            wx.EVT_MENU(self, wx_id, self._on_save_project) 
    15391519        if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 
    1540             id = wx.NewId() 
    1541             self._save_appl_menu = self._file_menu.Append(id, \ 
     1520            wx_id = wx.NewId() 
     1521            self._save_appl_menu = self._file_menu.Append(wx_id, \ 
    15421522                '&Save Analysis', 'Save state of the current active analysis panel') 
    1543             wx.EVT_MENU(self, id, self._on_save_application) 
     1523            wx.EVT_MENU(self, wx_id, self._on_save_application) 
    15441524        if not sys.platform == 'darwin': 
    15451525            self._file_menu.AppendSeparator() 
    1546             id = wx.NewId() 
    1547             self._file_menu.Append(id, '&Quit', 'Exit') 
    1548             wx.EVT_MENU(self, id, self.Close) 
     1526            wx_id = wx.NewId() 
     1527            self._file_menu.Append(wx_id, '&Quit', 'Exit') 
     1528            wx.EVT_MENU(self, wx_id, self.Close) 
    15491529 
    15501530    def _add_menu_file(self): 
     
    17171697        """ 
    17181698        """ 
    1719         message = "" 
    17201699        log_msg = '' 
    1721         output = [] 
    1722         error_message = "" 
    17231700        basename = os.path.basename(path) 
    1724         root, extension = os.path.splitext(basename) 
     1701        _, extension = os.path.splitext(basename) 
    17251702        if extension.lower() not in EXTENSIONS: 
    17261703            log_msg = "File Loader cannot " 
     
    20542031        a call-back method when the current version number has been obtained. 
    20552032        """ 
    2056         version_info = {"version": "0.0.0"} 
    2057         c = Connection(config.__update_URL__, config.UPDATE_TIMEOUT) 
    2058         response = c.connect() 
    2059         if response is not None: 
    2060             try: 
    2061                 #  
    2062                 content = response.read().strip() 
    2063                 logging.info("Connected to www.sasview.org. Latest version: %s" 
    2064                              % (content)) 
    2065                 version_info = json.loads(content) 
    2066             except: 
    2067                 logging.info("Failed to connect to www.sasview.org") 
    2068         self._process_version(version_info, standalone=event == None)     
    2069  
    2070          
    2071          
    2072 #          
    2073 #         try: 
    2074 #             req = urllib2.Request(config.__update_URL__) 
    2075 #             res = urllib2.urlopen(req) 
    2076 #             content = res.read().strip() 
    2077 #             logging.info("Connected to www.sasview.org. Latest version: %s" 
    2078 #                          % (content)) 
    2079 #             version_info = json.loads(content) 
    2080 #         except: 
    2081 #             logging.info("Failed to connect to www.sasview.org") 
    2082 #             version_info = {"version": "0.0.0"} 
    2083 #         self._process_version(version_info, standalone=event == None) 
    2084  
    2085     def _process_version(self, version_info, standalone=True): 
     2033        try: 
     2034            req = urllib2.Request('https://github.com/SasView/sasview/releases/latest') 
     2035            res = urllib2.urlopen(req) 
     2036            get_url= res.geturl() 
     2037            content = get_url.partition('/v')[2] 
     2038            logging.info("connected to GitHub. sasview.latestversion = %s" 
     2039                         % (content)) 
     2040        except: 
     2041            msg = traceback.format_exc() 
     2042            logging.info(msg) 
     2043            logging.info("failed to connect to GitHub") 
     2044            content = "0.0.0" 
     2045 
     2046        version = content.strip() 
     2047        logging.info("Latest SasView version number: %s" % (version)) 
     2048        if len(re.findall('\d+\.\d+\.\d+$', version)) < 0: 
     2049            content = "0.0.0" 
     2050        self._process_version(content, standalone=event == None) 
     2051 
     2052    def _process_version(self, version, standalone=True): 
    20862053        """ 
    20872054        Call-back method for the process of checking for updates. 
     
    20962063        """ 
    20972064        try: 
    2098             version = version_info["version"] 
    20992065            if version == "0.0.0": 
    21002066                msg = "Could not connect to the application server." 
     
    21052071                if not standalone: 
    21062072                    import webbrowser 
    2107                     if "download_url" in version_info: 
    2108                         webbrowser.open(version_info["download_url"]) 
    2109                     else: 
    2110                         webbrowser.open(config.__download_page__) 
     2073                    webbrowser.open(config.__download_page__) 
    21112074                else: 
    21122075                    msg += "See the help menu to download it." 
     
    22242187            if hasattr(item, "post_init"): 
    22252188                item.post_init() 
    2226  
    2227     def set_default_perspective(self): 
    2228         """ 
    2229         Choose among the plugin the first plug-in that has 
    2230         "set_default_perspective" method and its return value is True will be 
    2231         as a default perspective when the welcome page is closed 
    2232         """ 
    2233         for item in self.plugins: 
    2234             if hasattr(item, "set_default_perspective"): 
    2235                 if item.set_default_perspective(): 
    2236                     item.on_perspective(event=None) 
    2237                     return 
    22382189 
    22392190    def set_perspective(self, panels): 
     
    24142365            total_plot_list.append(theory_data) 
    24152366        for new_plot in total_plot_list: 
    2416             id = new_plot.id 
    24172367            for group_id in new_plot.list_group_id: 
    2418                 wx.PostEvent(self, NewPlotEvent(id=id, 
     2368                wx.PostEvent(self, NewPlotEvent(id=new_plot.id, 
    24192369                                                group_id=group_id, 
    24202370                                                action='remove')) 
    24212371                #remove res plot: Todo: improve 
    2422                 wx.CallAfter(self._remove_res_plot, id) 
     2372                wx.CallAfter(self._remove_res_plot, new_plot.id) 
    24232373        self._data_manager.delete_data(data_id=data_id, 
    24242374                                       theory_id=theory_id) 
     
    24552405            ext_num = dlg.GetFilterIndex() 
    24562406            if ext_num == 0: 
    2457                 format = '.txt' 
     2407                ext_format = '.txt' 
    24582408            else: 
    2459                 format = '.xml' 
    2460             path = os.path.splitext(path)[0] + format 
     2409                ext_format = '.xml' 
     2410            path = os.path.splitext(path)[0] + ext_format 
    24612411            mypath = os.path.basename(path) 
    24622412 
    24632413            #Instantiate a loader 
    24642414            loader = Loader() 
    2465             format = ".txt" 
    2466             if os.path.splitext(mypath)[1].lower() == format: 
     2415            ext_format = ".txt" 
     2416            if os.path.splitext(mypath)[1].lower() == ext_format: 
    24672417                # Make sure the ext included in the file name 
    24682418                # especially on MAC 
    2469                 fName = os.path.splitext(path)[0] + format 
     2419                fName = os.path.splitext(path)[0] + ext_format 
    24702420                self._onsaveTXT(data, fName) 
    2471             format = ".xml" 
    2472             if os.path.splitext(mypath)[1].lower() == format: 
     2421            ext_format = ".xml" 
     2422            if os.path.splitext(mypath)[1].lower() == ext_format: 
    24732423                # Make sure the ext included in the file name 
    24742424                # especially on MAC 
    2475                 fName = os.path.splitext(path)[0] + format 
    2476                 loader.save(fName, data, format) 
     2425                fName = os.path.splitext(path)[0] + ext_format 
     2426                loader.save(fName, data, ext_format) 
    24772427            try: 
    24782428                self._default_save_location = os.path.dirname(path) 
     
    24852435        """ 
    24862436        Save file as txt 
    2487  
    2488         .. todo:: Refactor and remove this method. See 'TODO' in _onSave. 
     2437        :TODO: Refactor and remove this method. See TODO in _onSave. 
    24892438        """ 
    24902439        if not path == None: 
     
    25982547            ext_num = dlg.GetFilterIndex() 
    25992548            if ext_num == 0: 
    2600                 format = '.dat' 
     2549                ext_format = '.dat' 
    26012550            else: 
    2602                 format = '' 
    2603             path = os.path.splitext(path)[0] + format 
     2551                ext_format = '' 
     2552            path = os.path.splitext(path)[0] + ext_format 
    26042553            mypath = os.path.basename(path) 
    26052554 
     
    26072556            loader = Loader() 
    26082557 
    2609             format = ".dat" 
    2610             if os.path.splitext(mypath)[1].lower() == format: 
     2558            ext_format = ".dat" 
     2559            if os.path.splitext(mypath)[1].lower() == ext_format: 
    26112560                # Make sure the ext included in the file name 
    26122561                # especially on MAC 
    2613                 fileName = os.path.splitext(path)[0] + format 
    2614                 loader.save(fileName, data, format) 
     2562                fileName = os.path.splitext(path)[0] + ext_format 
     2563                loader.save(fileName, data, ext_format) 
    26152564            try: 
    26162565                self._default_save_location = os.path.dirname(path) 
     
    29142863                    # Append nummber 
    29152864                    inc = 1 
    2916                     # FIXME: fix this terrible loop 
     2865                    #FIXME: fix this terrible loop 
    29172866                    while (1): 
    29182867                        caption = new_caption + '_%s' % str(inc) 
     
    29372886 
    29382887        :param name: window_name in AuiPaneInfo 
    2939         :returns: AuiPaneInfo of the name 
     2888        :return: AuiPaneInfo of the name 
    29402889        """ 
    29412890        for panel in self.plot_panels.values(): 
     
    31093058                pass 
    31103059 
    3111         # Draw all panels 
     3060        # Draw all panels  
    31123061        if count == 1: 
    31133062            f_draw(self.schedule_full_draw_list[0]) 
    31143063        else: 
    31153064            map(f_draw, self.schedule_full_draw_list) 
    3116         # Reset the attr 
     3065        # Reset the attr   
    31173066        if len(self.schedule_full_draw_list) == 0: 
    31183067            self.set_schedule(False) 
     
    31553104        Get window size 
    31563105 
    3157         :returns: size 
    3158         :rtype: tuple 
     3106        :return size: tuple 
    31593107        """ 
    31603108        width, height = self.GetSizeTuple() 
     
    31773125            pass 
    31783126 
    3179         # restart idle 
     3127        # restart idle         
    31803128        self._redraw_idle(*args, **kwargs) 
    31813129 
     
    31853133        Restart Idle 
    31863134        """ 
    3187         # restart idle 
     3135        # restart idle    
    31883136        self.idletimer.Restart(100 * TIME_FACTOR, *args, **kwargs) 
    31893137 
     
    32063154 
    32073155 
    3208 class ViewApp(wx.App): 
     3156class SasViewApp(wx.App): 
    32093157    """ 
    3210     Toy application to test this Frame 
     3158    SasView application 
    32113159    """ 
    32123160    def OnInit(self): 
     
    32943242            if len(os.listdir(model_folder)) > 0: 
    32953243                try: 
    3296                     for file in os.listdir(model_folder): 
    3297                         file_path = os.path.join(model_folder, file) 
     3244                    for filename in os.listdir(model_folder): 
     3245                        file_path = os.path.join(model_folder, filename) 
    32983246                        if os.path.isfile(file_path): 
    32993247                            os.remove(file_path) 
     
    33143262        """ 
    33153263        #try to load file at the start 
    3316         try: 
    3317             self.open_file() 
    3318         except: 
    3319             raise 
     3264        self.open_file() 
    33203265        self.frame.build_gui() 
    33213266 
     
    33453290        """ 
    33463291        is_maximized = False 
    3347         # Get size of screen without 
     3292        # Get size of screen without  
    33483293        for screenCount in range(wx.Display().GetCount()): 
    33493294            screen = wx.Display(screenCount) 
     
    33623307            customHeight = displayHeight * 0.9 
    33633308        else: 
    3364             # If the custom screen is bigger than the 
     3309            # If the custom screen is bigger than the  
    33653310            # window screen than make maximum size 
    33663311            if customWidth > displayWidth: 
     
    34603405    def show_data_panel(self, action): 
    34613406        """ 
    3462         Turns on the data panel 
    3463  
    3464         The the data panel is optional.  Most of its functions can be 
    3465         performed from the menu bar and from the plots. 
    34663407        """ 
    34673408        self.parent.show_data_panel(action) 
Note: See TracChangeset for help on using the changeset viewer.