Changeset 9e426c1 in sasview for src/sas/qtgui/GuiManager.py


Ignore:
Timestamp:
Jun 21, 2016 6:07:33 AM (8 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
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
Children:
f82ab8c
Parents:
1042dba
Message:

More main window items, system close, update checker, doc viewer etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/GuiManager.py

    r1042dba r9e426c1  
    11import sys 
     2import subprocess 
     3import logging 
     4import json 
     5import webbrowser 
    26 
    37from PyQt4 import QtCore 
     
    913# General SAS imports 
    1014from sas.sasgui.guiframe.data_manager import DataManager 
     15from sas.sasgui.guiframe.proxy import Connection 
     16 
    1117import LocalConfig 
    1218from GuiUtils import * 
     19from UI.AcknowledgementsUI import Acknowledgements 
    1320 
    1421# Perspectives 
     
    2128    Main SasView window functionality 
    2229    """ 
     30    HELP_DIRECTORY_LOCATION="html" 
     31 
    2332    def __init__(self, mainWindow=None, reactor=None, parent=None): 
    2433        """ 
     
    5665        self.dockedFilesWidget.setWidget(self.filesWidget) 
    5766        self._workspace.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.dockedFilesWidget) 
     67 
     68        self.ackWidget = Acknowledgements() 
     69 
    5870        # Disable the close button (?) 
     71 
    5972        # Show the Welcome panel 
    6073        self.welcomePanel = WelcomePanel() 
     
    6376        # Current help file 
    6477        self._helpView = QtWebKit.QWebView() 
    65         self._helpLocation = "html/index.html" 
     78        # Needs URL like path, so no path.join() here 
     79        self._helpLocation = self.HELP_DIRECTORY_LOCATION + "/index.html" 
     80 
     81        # Current tutorial location 
     82        self._tutorialLocation = os.path.join(self.HELP_DIRECTORY_LOCATION, 
     83                                              "_downloads", 
     84                                              "Tutorial.pdf") 
    6685 
    6786        #========================================================== 
     
    7796        """ 
    7897        """ 
    79         print("FILE %s "%data) 
    8098        pass 
    8199     
     
    161179            logging.info(msg) 
    162180 
     181    def quitApplication(self): 
     182        """ 
     183        Close the reactor and exit nicely. 
     184        """ 
     185        # Display confirmation messagebox 
     186        quit_msg = "Are you sure you want to exit the application?" 
     187        reply = QtGui.QMessageBox.question( 
     188                        self._parent, 
     189                        'Warning', 
     190                        quit_msg, 
     191                        QtGui.QMessageBox.Yes, 
     192                        QtGui.QMessageBox.No) 
     193 
     194        if reply == QtGui.QMessageBox.No: 
     195            return 
     196 
     197        # Exit if yes 
     198        reactor.callFromThread(reactor.stop) 
     199        reactor.stop 
     200        sys.exit() 
     201 
     202    def checkUpdate(self): 
     203        """ 
     204        Check with the deployment server whether a new version 
     205        of the application is available. 
     206        A thread is started for the connecting with the server. The thread calls 
     207        a call-back method when the current version number has been obtained. 
     208        """ 
     209        version_info = {"version": "0.0.0"} 
     210        c = Connection(LocalConfig.__update_URL__, LocalConfig.UPDATE_TIMEOUT) 
     211        response = c.connect() 
     212        if response is not None: 
     213            try: 
     214                content = response.read().strip() 
     215                logging.info("Connected to www.sasview.org. Latest version: %s" 
     216                             % (content)) 
     217                version_info = json.loads(content) 
     218            except: 
     219                logging.info("Failed to connect to www.sasview.org") 
     220        self.processVersion(version_info)   
     221   
     222    def processVersion(self, version_info, standalone=False): 
     223        """ 
     224        Call-back method for the process of checking for updates. 
     225        This methods is called by a VersionThread object once the current 
     226        version number has been obtained. If the check is being done in the 
     227        background, the user will not be notified unless there's an update. 
     228 
     229        :param version: version string 
     230        :param standalone: True of the update is being checked in 
     231           the background, False otherwise. 
     232 
     233        """ 
     234        try: 
     235            version = version_info["version"] 
     236            if version == "0.0.0": 
     237                msg = "Could not connect to the application server." 
     238                msg += " Please try again later." 
     239                #self.SetStatusText(msg) 
     240                self.communicate.statusBarUpdateSignal.emit(msg) 
     241 
     242            elif cmp(version, LocalConfig.__version__) > 0: 
     243                msg = "Version %s is available! " % str(version) 
     244                if not standalone: 
     245                    if "download_url" in version_info: 
     246                        webbrowser.open(version_info["download_url"]) 
     247                    else: 
     248                        webbrowser.open(LocalConfig.__download_page__) 
     249                else: 
     250                    msg += "See the help menu to download it." 
     251                self.communicate.statusBarUpdateSignal.emit(msg) 
     252            else: 
     253                msg = "You have the latest version" 
     254                msg += " of %s" % str(LocalConfig.__appname__) 
     255                self.communicate.statusBarUpdateSignal.emit(msg) 
     256        except: 
     257            msg = "guiframe: could not get latest application" 
     258            msg += " version number\n  %s" % sys.exc_value 
     259            logging.error(msg) 
     260            if not standalone: 
     261                msg = "Could not connect to the application server." 
     262                msg += " Please try again later." 
     263                self.communicate.statusBarUpdateSignal.emit(msg) 
     264 
    163265    def addCallbacks(self): 
    164266        """ 
     267        Method defining all signal connections for the gui manager 
    165268        """ 
    166269        self.communicate = Communicate() 
     
    234337    def actionLoadData(self): 
    235338        """ 
    236         Load file from Data Explorer 
     339        Menu File/Load Data File(s) 
    237340        """ 
    238341        self.filesWidget.loadFile() 
     
    240343    def actionLoad_Data_Folder(self): 
    241344        """ 
     345        Menu File/Load Data Folder 
    242346        """ 
    243347        self.filesWidget.loadFolder() 
     
    272376        Close the reactor, exit the application. 
    273377        """ 
    274         # display messagebox 
    275         quit_msg = "Are you sure you want to exit the application?" 
    276         reply = QtGui.QMessageBox.question(self._parent, 'Warning', quit_msg, 
    277                 QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) 
    278  
    279         if reply == QtGui.QMessageBox.No: 
    280             return 
    281  
    282         # exit if yes 
    283         reactor.callFromThread(reactor.stop) 
    284         sys.exit() 
     378        self.quitApplication() 
    285379 
    286380    #============ EDIT ================= 
     
    509603    def actionDocumentation(self): 
    510604        """ 
     605        Display the documentation 
     606 
     607        TODO: use QNetworkAccessManager to assure _helpLocation is valid 
    511608        """ 
    512609        self._helpView.load(QtCore.QUrl(self._helpLocation)) 
     
    515612    def actionTutorial(self): 
    516613        """ 
    517         """ 
    518         print("actionTutorial TRIGGERED") 
    519         pass 
     614        Open the tutorial PDF file with default PDF renderer 
     615        """ 
     616        # Not terribly safe here. Shell injection warning. 
     617        # isfile() helps but this probably needs a better solution. 
     618        if os.path.isfile(self._tutorialLocation): 
     619            result = subprocess.Popen([self._tutorialLocation], shell=True) 
    520620 
    521621    def actionAcknowledge(self): 
    522622        """ 
    523         """ 
    524         print("actionAcknowledge TRIGGERED") 
    525         pass 
     623        Open the Acknowledgements widget 
     624        """ 
     625        self.ackWidget.show() 
    526626 
    527627    def actionAbout(self): 
    528628        """ 
    529         """ 
     629        Open the About box 
     630        """ 
     631         
    530632        print("actionAbout TRIGGERED") 
    531633        pass 
     
    533635    def actionCheck_for_update(self): 
    534636        """ 
    535         """ 
    536         print("actionCheck_for_update TRIGGERED") 
    537         pass 
    538  
     637        Menu Help/Check for Update 
     638        """ 
     639        self.checkUpdate() 
     640 
     641        pass 
     642 
Note: See TracChangeset for help on using the changeset viewer.