Ignore:
File:
1 edited

Legend:

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

    r78f75d02 r957af0d  
    2727import urllib 
    2828import urllib2 
    29  
     29import json 
    3030 
    3131from sas.guiframe.events import EVT_CATEGORY 
     
    4646from sas.guiframe.CategoryManager import CategoryManager 
    4747from sas.dataloader.loader import Loader 
     48from sas.guiframe.proxy import Connection 
    4849from matplotlib import _pylab_helpers 
     50 
    4951 
    5052def get_app_dir(): 
     
    5254        The application directory is the one where the default custom_config.py 
    5355        file resides. 
     56 
     57        :returns: app_path - the path to the applicatin directory 
    5458    """ 
    5559    # First, try the directory of the executable we are running 
     
    6872 
    6973    # Finally, try the directory of the sasview module 
    70     #TODO: gui_manager will have to know about sasview until we 
     74    # TODO: gui_manager will have to know about sasview until we 
    7175    # clean all these module variables and put them into a config class 
    7276    # that can be passed by sasview.py. 
     
    231235        Initialize the Frame object 
    232236        """ 
     237 
    233238        PARENT_FRAME.__init__(self, parent=parent, title=title, pos=pos, size=size) 
    234239        # title 
     
    359364                    frame.SetIcon(icon) 
    360365                except: 
    361                     logging.error("ViewerFrame.put_icon: could not set icon") 
     366                    pass 
    362367 
    363368    def get_client_size(self): 
     
    747752            self._toolbar.Realize() 
    748753 
     754 
    749755    def build_gui(self): 
    750756        """ 
     
    772778        # Append item from plugin under menu file if necessary 
    773779        self._populate_file_menu() 
     780 
    774781 
    775782        if not wx.VERSION_STRING >= '3.0.0.0': 
     
    815822        # Load panels 
    816823        self._load_panels() 
     824        self.set_default_perspective() 
    817825 
    818826    def SetStatusText(self, *args, **kwds): 
     
    830838    def PushStatusText(self, *args, **kwds): 
    831839        """ 
    832             FIXME: No message is passed. What is this supposed to do? 
     840        .. todo:: No message is passed. What is this supposed to do? 
    833841        """ 
    834842        field = self.sb.get_msg_position() 
    835843        wx.Frame.PushStatusText(self, field=field, 
    836                                 string="FIXME: PushStatusText called without text") 
     844                                string="FIXME - PushStatusText called without text") 
    837845 
    838846    def add_perspective(self, plugin): 
     
    890898        :param dir: directory in which to look for plug-ins 
    891899 
    892         :return: list of plug-ins 
     900        :returns: list of plug-ins 
    893901 
    894902        """ 
     
    923931                        if hasattr(module, "PLUGIN_ID"): 
    924932                            try: 
    925                                 plugins.append(module.Plugin()) 
     933                                plug = module.Plugin() 
     934                                if plug.set_default_perspective(): 
     935                                    self._current_perspective = plug 
     936                                plugins.append(plug) 
     937 
    926938                                msg = "Found plug-in: %s" % module.PLUGIN_ID 
    927939                                logging.info(msg) 
     
    937949                            file.close() 
    938950        except: 
    939             # Should raise and catch at a higher level and  
     951            # Should raise and catch at a higher level and 
    940952            # display error on status bar 
    941953            logging.error(sys.exc_value) 
     
    984996 
    985997        # Set up welcome panel 
    986         #TODO: this needs serious simplification 
     998        # TODO: this needs serious simplification 
    987999        if self.welcome_panel_class is not None: 
    9881000            welcome_panel = MDIFrame(self, None, 'None', (100, 200)) 
     
    10741086    def onfreeze(self, theory_id): 
    10751087        """ 
     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 
    10761092        """ 
    10771093        data_state_list = self._data_manager.freeze(theory_id) 
     
    10851101    def freeze(self, data_id, theory_id): 
    10861102        """ 
     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 
    10871107        """ 
    10881108        data_state_list = self._data_manager.freeze_theory(data_id=data_id, 
     
    11491169        :param p: panel object to add to the AUI manager 
    11501170 
    1151         :return: ID of the event associated with the new panel [int] 
     1171        :returns: ID of the event associated with the new panel [int] 
    11521172 
    11531173        """ 
     
    11701190        # Append nummber 
    11711191        captions = self._get_plotpanel_captions() 
    1172         #FIXME: Fix this aweful loop 
     1192        # FIXME: Fix this awful loop 
    11731193        while (1): 
    11741194            caption = windowcaption + '%s' % str(self.graph_num) 
     
    14911511                for item in plugin.populate_file_menu(): 
    14921512                    m_name, m_hint, m_handler = item 
    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) 
     1513                    id = wx.NewId() 
     1514                    self._file_menu.Append(id, m_name, m_hint) 
     1515                    wx.EVT_MENU(self, id, m_handler) 
    14961516                self._file_menu.AppendSeparator() 
    14971517 
    14981518        style1 = self.__gui_style & GUIFRAME.MULTIPLE_APPLICATIONS 
    14991519        if OPEN_SAVE_MENU: 
    1500             wx_id = wx.NewId() 
     1520            id = wx.NewId() 
    15011521            hint_load_file = "read all analysis states saved previously" 
    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) 
     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) 
    15041524 
    15051525        if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 
     
    15071527            hint_load_file = "Read a status files and load" 
    15081528            hint_load_file += " them into the analysis" 
    1509             wx_id = wx.NewId() 
    1510             self._save_appl_menu = self._file_menu.Append(wx_id, 
     1529            id = wx.NewId() 
     1530            self._save_appl_menu = self._file_menu.Append(id, 
    15111531                                                          '&Open Analysis', hint_load_file) 
    1512             wx.EVT_MENU(self, wx_id, self._on_open_state_application) 
     1532            wx.EVT_MENU(self, id, self._on_open_state_application) 
    15131533        if OPEN_SAVE_MENU: 
    15141534            self._file_menu.AppendSeparator() 
    1515             wx_id = wx.NewId() 
    1516             self._file_menu.Append(wx_id, '&Save Project', 
     1535            id = wx.NewId() 
     1536            self._file_menu.Append(id, '&Save Project', 
    15171537                                   'Save the state of the whole analysis') 
    1518             wx.EVT_MENU(self, wx_id, self._on_save_project) 
     1538            wx.EVT_MENU(self, id, self._on_save_project) 
    15191539        if style1 == GUIFRAME.MULTIPLE_APPLICATIONS: 
    1520             wx_id = wx.NewId() 
    1521             self._save_appl_menu = self._file_menu.Append(wx_id, \ 
     1540            id = wx.NewId() 
     1541            self._save_appl_menu = self._file_menu.Append(id, \ 
    15221542                '&Save Analysis', 'Save state of the current active analysis panel') 
    1523             wx.EVT_MENU(self, wx_id, self._on_save_application) 
     1543            wx.EVT_MENU(self, id, self._on_save_application) 
    15241544        if not sys.platform == 'darwin': 
    15251545            self._file_menu.AppendSeparator() 
    1526             wx_id = wx.NewId() 
    1527             self._file_menu.Append(wx_id, '&Quit', 'Exit') 
    1528             wx.EVT_MENU(self, wx_id, self.Close) 
     1546            id = wx.NewId() 
     1547            self._file_menu.Append(id, '&Quit', 'Exit') 
     1548            wx.EVT_MENU(self, id, self.Close) 
    15291549 
    15301550    def _add_menu_file(self): 
     
    16971717        """ 
    16981718        """ 
     1719        message = "" 
    16991720        log_msg = '' 
     1721        output = [] 
     1722        error_message = "" 
    17001723        basename = os.path.basename(path) 
    1701         _, extension = os.path.splitext(basename) 
     1724        root, extension = os.path.splitext(basename) 
    17021725        if extension.lower() not in EXTENSIONS: 
    17031726            log_msg = "File Loader cannot " 
     
    20312054        a call-back method when the current version number has been obtained. 
    20322055        """ 
    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): 
     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): 
    20532086        """ 
    20542087        Call-back method for the process of checking for updates. 
     
    20632096        """ 
    20642097        try: 
     2098            version = version_info["version"] 
    20652099            if version == "0.0.0": 
    20662100                msg = "Could not connect to the application server." 
     
    20712105                if not standalone: 
    20722106                    import webbrowser 
    2073                     webbrowser.open(config.__download_page__) 
     2107                    if "download_url" in version_info: 
     2108                        webbrowser.open(version_info["download_url"]) 
     2109                    else: 
     2110                        webbrowser.open(config.__download_page__) 
    20742111                else: 
    20752112                    msg += "See the help menu to download it." 
     
    21872224            if hasattr(item, "post_init"): 
    21882225                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 
    21892238 
    21902239    def set_perspective(self, panels): 
     
    23652414            total_plot_list.append(theory_data) 
    23662415        for new_plot in total_plot_list: 
     2416            id = new_plot.id 
    23672417            for group_id in new_plot.list_group_id: 
    2368                 wx.PostEvent(self, NewPlotEvent(id=new_plot.id, 
     2418                wx.PostEvent(self, NewPlotEvent(id=id, 
    23692419                                                group_id=group_id, 
    23702420                                                action='remove')) 
    23712421                #remove res plot: Todo: improve 
    2372                 wx.CallAfter(self._remove_res_plot, new_plot.id) 
     2422                wx.CallAfter(self._remove_res_plot, id) 
    23732423        self._data_manager.delete_data(data_id=data_id, 
    23742424                                       theory_id=theory_id) 
     
    24052455            ext_num = dlg.GetFilterIndex() 
    24062456            if ext_num == 0: 
    2407                 ext_format = '.txt' 
     2457                format = '.txt' 
    24082458            else: 
    2409                 ext_format = '.xml' 
    2410             path = os.path.splitext(path)[0] + ext_format 
     2459                format = '.xml' 
     2460            path = os.path.splitext(path)[0] + format 
    24112461            mypath = os.path.basename(path) 
    24122462 
    24132463            #Instantiate a loader 
    24142464            loader = Loader() 
    2415             ext_format = ".txt" 
    2416             if os.path.splitext(mypath)[1].lower() == ext_format: 
     2465            format = ".txt" 
     2466            if os.path.splitext(mypath)[1].lower() == format: 
    24172467                # Make sure the ext included in the file name 
    24182468                # especially on MAC 
    2419                 fName = os.path.splitext(path)[0] + ext_format 
     2469                fName = os.path.splitext(path)[0] + format 
    24202470                self._onsaveTXT(data, fName) 
    2421             ext_format = ".xml" 
    2422             if os.path.splitext(mypath)[1].lower() == ext_format: 
     2471            format = ".xml" 
     2472            if os.path.splitext(mypath)[1].lower() == format: 
    24232473                # Make sure the ext included in the file name 
    24242474                # especially on MAC 
    2425                 fName = os.path.splitext(path)[0] + ext_format 
    2426                 loader.save(fName, data, ext_format) 
     2475                fName = os.path.splitext(path)[0] + format 
     2476                loader.save(fName, data, format) 
    24272477            try: 
    24282478                self._default_save_location = os.path.dirname(path) 
     
    24352485        """ 
    24362486        Save file as txt 
    2437         :TODO: Refactor and remove this method. See TODO in _onSave. 
     2487 
     2488        .. todo:: Refactor and remove this method. See 'TODO' in _onSave. 
    24382489        """ 
    24392490        if not path == None: 
     
    25472598            ext_num = dlg.GetFilterIndex() 
    25482599            if ext_num == 0: 
    2549                 ext_format = '.dat' 
     2600                format = '.dat' 
    25502601            else: 
    2551                 ext_format = '' 
    2552             path = os.path.splitext(path)[0] + ext_format 
     2602                format = '' 
     2603            path = os.path.splitext(path)[0] + format 
    25532604            mypath = os.path.basename(path) 
    25542605 
     
    25562607            loader = Loader() 
    25572608 
    2558             ext_format = ".dat" 
    2559             if os.path.splitext(mypath)[1].lower() == ext_format: 
     2609            format = ".dat" 
     2610            if os.path.splitext(mypath)[1].lower() == format: 
    25602611                # Make sure the ext included in the file name 
    25612612                # especially on MAC 
    2562                 fileName = os.path.splitext(path)[0] + ext_format 
    2563                 loader.save(fileName, data, ext_format) 
     2613                fileName = os.path.splitext(path)[0] + format 
     2614                loader.save(fileName, data, format) 
    25642615            try: 
    25652616                self._default_save_location = os.path.dirname(path) 
     
    28632914                    # Append nummber 
    28642915                    inc = 1 
    2865                     #FIXME: fix this terrible loop 
     2916                    # FIXME: fix this terrible loop 
    28662917                    while (1): 
    28672918                        caption = new_caption + '_%s' % str(inc) 
     
    28862937 
    28872938        :param name: window_name in AuiPaneInfo 
    2888         :return: AuiPaneInfo of the name 
     2939        :returns: AuiPaneInfo of the name 
    28892940        """ 
    28902941        for panel in self.plot_panels.values(): 
     
    30583109                pass 
    30593110 
    3060         # Draw all panels  
     3111        # Draw all panels 
    30613112        if count == 1: 
    30623113            f_draw(self.schedule_full_draw_list[0]) 
    30633114        else: 
    30643115            map(f_draw, self.schedule_full_draw_list) 
    3065         # Reset the attr   
     3116        # Reset the attr 
    30663117        if len(self.schedule_full_draw_list) == 0: 
    30673118            self.set_schedule(False) 
     
    31043155        Get window size 
    31053156 
    3106         :return size: tuple 
     3157        :returns: size 
     3158        :rtype: tuple 
    31073159        """ 
    31083160        width, height = self.GetSizeTuple() 
     
    31253177            pass 
    31263178 
    3127         # restart idle         
     3179        # restart idle 
    31283180        self._redraw_idle(*args, **kwargs) 
    31293181 
     
    31333185        Restart Idle 
    31343186        """ 
    3135         # restart idle    
     3187        # restart idle 
    31363188        self.idletimer.Restart(100 * TIME_FACTOR, *args, **kwargs) 
    31373189 
     
    31543206 
    31553207 
    3156 class SasViewApp(wx.App): 
     3208class ViewApp(wx.App): 
    31573209    """ 
    3158     SasView application 
     3210    Toy application to test this Frame 
    31593211    """ 
    31603212    def OnInit(self): 
     
    32423294            if len(os.listdir(model_folder)) > 0: 
    32433295                try: 
    3244                     for filename in os.listdir(model_folder): 
    3245                         file_path = os.path.join(model_folder, filename) 
     3296                    for file in os.listdir(model_folder): 
     3297                        file_path = os.path.join(model_folder, file) 
    32463298                        if os.path.isfile(file_path): 
    32473299                            os.remove(file_path) 
     
    32623314        """ 
    32633315        #try to load file at the start 
    3264         self.open_file() 
     3316        try: 
     3317            self.open_file() 
     3318        except: 
     3319            raise 
    32653320        self.frame.build_gui() 
    32663321 
     
    32903345        """ 
    32913346        is_maximized = False 
    3292         # Get size of screen without  
     3347        # Get size of screen without 
    32933348        for screenCount in range(wx.Display().GetCount()): 
    32943349            screen = wx.Display(screenCount) 
     
    33073362            customHeight = displayHeight * 0.9 
    33083363        else: 
    3309             # If the custom screen is bigger than the  
     3364            # If the custom screen is bigger than the 
    33103365            # window screen than make maximum size 
    33113366            if customWidth > displayWidth: 
     
    34053460    def show_data_panel(self, action): 
    34063461        """ 
     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. 
    34073466        """ 
    34083467        self.parent.show_data_panel(action) 
Note: See TracChangeset for help on using the changeset viewer.