source: sasview/src/sas/qtgui/MainWindow/GuiManager.py @ f84d793

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since f84d793 was f84d793, checked in by Torin Cooper-Bennun <torin.cooper-bennun@…>, 6 years ago

reduce initial width of Data Explorer dock

  • Property mode set to 100644
File size: 35.0 KB
RevLine 
[f721030]1import sys
[0cd8612]2import os
[9e426c1]3import subprocess
4import logging
5import json
6import webbrowser
[f721030]7
[4992ff2]8from PyQt5.QtWidgets import *
9from PyQt5.QtGui import *
[d6b8a1d]10from PyQt5.QtCore import Qt, QLocale, QUrl
[1042dba]11
12from twisted.internet import reactor
[dc5ef15]13# General SAS imports
14from sas.qtgui.Utilities.ConnectionProxy import ConnectionProxy
[e4335ae]15from sas.qtgui.Utilities.SasviewLogger import setup_qt_logging
[fef38e8]16
[83eb5208]17import sas.qtgui.Utilities.LocalConfig as LocalConfig
18import sas.qtgui.Utilities.GuiUtils as GuiUtils
19
[fef38e8]20import sas.qtgui.Utilities.ObjectLibrary as ObjectLibrary
[3b3b40b]21from sas.qtgui.Utilities.TabbedModelEditor import TabbedModelEditor
22from sas.qtgui.Utilities.PluginManager import PluginManager
[d4dac80]23from sas.qtgui.Utilities.GridPanel import BatchOutputPanel
24
[57be490]25from sas.qtgui.Utilities.ReportDialog import ReportDialog
[83eb5208]26from sas.qtgui.MainWindow.UI.AcknowledgementsUI import Ui_Acknowledgements
27from sas.qtgui.MainWindow.AboutBox import AboutBox
28from sas.qtgui.MainWindow.WelcomePanel import WelcomePanel
[3d18691]29from sas.qtgui.MainWindow.CategoryManager import CategoryManager
[fef38e8]30
[dc5ef15]31from sas.qtgui.MainWindow.DataManager import DataManager
[83eb5208]32
33from sas.qtgui.Calculators.SldPanel import SldPanel
34from sas.qtgui.Calculators.DensityPanel import DensityPanel
35from sas.qtgui.Calculators.KiessigPanel import KiessigPanel
36from sas.qtgui.Calculators.SlitSizeCalculator import SlitSizeCalculator
[28a09b0]37from sas.qtgui.Calculators.GenericScatteringCalculator import GenericScatteringCalculator
[01cda57]38from sas.qtgui.Calculators.ResolutionCalculatorPanel import ResolutionCalculatorPanel
[d5c5d3d]39from sas.qtgui.Calculators.DataOperationUtilityPanel import DataOperationUtilityPanel
[f721030]40
41# Perspectives
[83eb5208]42import sas.qtgui.Perspectives as Perspectives
[6c8fb2c]43from sas.qtgui.Perspectives.Fitting.FittingPerspective import FittingWindow
[d4881f6a]44from sas.qtgui.MainWindow.DataExplorer import DataExplorerWindow, DEFAULT_PERSPECTIVE
[f51ed67]45
[01ef3f7]46from sas.qtgui.Utilities.AddMultEditor import AddMultEditor
47
[f0a8f74]48logger = logging.getLogger(__name__)
49
[4992ff2]50class Acknowledgements(QDialog, Ui_Acknowledgements):
[f51ed67]51    def __init__(self, parent=None):
[4992ff2]52        QDialog.__init__(self, parent)
[f51ed67]53        self.setupUi(self)
[f721030]54
55class GuiManager(object):
56    """
57    Main SasView window functionality
58    """
[6fd4e36]59    def __init__(self, parent=None):
[f721030]60        """
[257bd57]61        Initialize the manager as a child of MainWindow.
[f721030]62        """
[6fd4e36]63        self._workspace = parent
[f721030]64        self._parent = parent
65
[d6b8a1d]66        # Decide on a locale
67        QLocale.setDefault(QLocale('en_US'))
68
[f721030]69        # Add signal callbacks
70        self.addCallbacks()
71
[c889a3e]72        # Assure model categories are available
73        self.addCategories()
74
[f721030]75        # Create the data manager
[1042dba]76        # TODO: pull out all required methods from DataManager and reimplement
77        self._data_manager = DataManager()
[f721030]78
79        # Create action triggers
80        self.addTriggers()
81
[d4881f6a]82        # Currently displayed perspective
[5236449]83        self._current_perspective = None
84
[d4881f6a]85        # Populate the main window with stuff
[0cd8612]86        self.addWidgets()
[f721030]87
[0cd8612]88        # Fork off logging messages to the Log Window
[e4335ae]89        handler = setup_qt_logging()
90        handler.messageWritten.connect(self.appendLog)
[8cb6cd6]91
[0cd8612]92        # Log the start of the session
93        logging.info(" --- SasView session started ---")
94        # Log the python version
95        logging.info("Python: %s" % sys.version)
[9e426c1]96
[e540cd2]97        # Set up the status bar
98        self.statusBarSetup()
[f721030]99
[9e426c1]100        # Current tutorial location
[b0c5e8c]101        self._tutorialLocation = os.path.abspath(os.path.join(GuiUtils.HELP_DIRECTORY_LOCATION,
[9e426c1]102                                              "_downloads",
[31c5b58]103                                              "Tutorial.pdf"))
[8353d90]104
[0cd8612]105    def addWidgets(self):
106        """
107        Populate the main window with widgets
108
109        TODO: overwrite close() on Log and DR widgets so they can be hidden/shown
110        on request
111        """
112        # Add FileDialog widget as docked
[630155bd]113        self.filesWidget = DataExplorerWindow(self._parent, self, manager=self._data_manager)
[2a432e7]114        ObjectLibrary.addObject('DataExplorer', self.filesWidget)
[0cd8612]115
[4992ff2]116        self.dockedFilesWidget = QDockWidget("Data Explorer", self._workspace)
[7969b9c]117        self.dockedFilesWidget.setFloating(False)
[0cd8612]118        self.dockedFilesWidget.setWidget(self.filesWidget)
[83d6249]119
[0cd8612]120        # Disable maximize/minimize and close buttons
[4992ff2]121        self.dockedFilesWidget.setFeatures(QDockWidget.NoDockWidgetFeatures)
122
[7969b9c]123        #self._workspace.workspace.addDockWidget(Qt.LeftDockWidgetArea, self.dockedFilesWidget)
124        self._workspace.addDockWidget(Qt.LeftDockWidgetArea, self.dockedFilesWidget)
[f84d793]125        self._workspace.resizeDocks([self.dockedFilesWidget], [305], Qt.Horizontal)
[0cd8612]126
127        # Add the console window as another docked widget
[4992ff2]128        self.logDockWidget = QDockWidget("Log Explorer", self._workspace)
[0cd8612]129        self.logDockWidget.setObjectName("LogDockWidget")
[4992ff2]130
131        self.listWidget = QTextBrowser()
[0cd8612]132        self.logDockWidget.setWidget(self.listWidget)
[7969b9c]133        self._workspace.addDockWidget(Qt.BottomDockWidgetArea, self.logDockWidget)
[0cd8612]134
135        # Add other, minor widgets
136        self.ackWidget = Acknowledgements()
137        self.aboutWidget = AboutBox()
[3d18691]138        self.categoryManagerWidget = CategoryManager(self._parent, manager=self)
[8353d90]139        self.welcomePanel = WelcomePanel()
[d4dac80]140        self.grid_window = None
[a0ed202]141        self._workspace.toolBar.setVisible(LocalConfig.TOOLBAR_SHOW)
142        self._workspace.actionHide_Toolbar.setText("Show Toolbar")
[0cd8612]143
[1d85b5e]144        # Add calculators - floating for usability
145        self.SLDCalculator = SldPanel(self)
146        self.DVCalculator = DensityPanel(self)
[a8ec5b1]147        self.KIESSIGCalculator = KiessigPanel(self)
[abc5e70]148        self.SlitSizeCalculator = SlitSizeCalculator(self)
[28a09b0]149        self.GENSASCalculator = GenericScatteringCalculator(self)
[01cda57]150        self.ResolutionCalculator = ResolutionCalculatorPanel(self)
[d5c5d3d]151        self.DataOperation = DataOperationUtilityPanel(self)
[83d6249]152
[c889a3e]153    def addCategories(self):
154        """
155        Make sure categories.json exists and if not compile it and install in ~/.sasview
156        """
157        try:
158            from sas.sascalc.fit.models import ModelManager
159            from sas.qtgui.Utilities.CategoryInstaller import CategoryInstaller
160            model_list = ModelManager().cat_model_list()
161            CategoryInstaller.check_install(model_list=model_list)
162        except Exception:
[f0a8f74]163            import traceback
[c889a3e]164            logger.error("%s: could not load SasView models")
165            logger.error(traceback.format_exc())
166
[e540cd2]167    def statusBarSetup(self):
168        """
169        Define the status bar.
170        | <message label> .... | Progress Bar |
171
172        Progress bar invisible until explicitly shown
173        """
[4992ff2]174        self.progress = QProgressBar()
[e540cd2]175        self._workspace.statusbar.setSizeGripEnabled(False)
176
[4992ff2]177        self.statusLabel = QLabel()
[e540cd2]178        self.statusLabel.setText("Welcome to SasView")
[8cb6cd6]179        self._workspace.statusbar.addPermanentWidget(self.statusLabel, 1)
[e540cd2]180        self._workspace.statusbar.addPermanentWidget(self.progress, stretch=0)
[8cb6cd6]181        self.progress.setRange(0, 100)
[e540cd2]182        self.progress.setValue(0)
183        self.progress.setTextVisible(True)
184        self.progress.setVisible(False)
185
[9d266d2]186    def fileWasRead(self, data):
[f721030]187        """
[f82ab8c]188        Callback for fileDataReceivedSignal
[f721030]189        """
190        pass
[481ff26]191
[e90988c]192    def showHelp(self, url):
193        """
194        Open a local url in the default browser
195        """
196        location = GuiUtils.HELP_DIRECTORY_LOCATION + url
[92c714f]197        #WP: Added to handle OSX bundle docs
198        if os.path.isdir(location) == False:
199            sas_path = os.path.abspath(os.path.dirname(sys.argv[0]))
200            location = sas_path+"/"+location
[e90988c]201        try:
202            webbrowser.open('file://' + os.path.realpath(location))
203        except webbrowser.Error as ex:
204            logging.warning("Cannot display help. %s" % ex)
205
[8cb6cd6]206    def workspace(self):
207        """
208        Accessor for the main window workspace
209        """
210        return self._workspace.workspace
211
[83d6249]212    def perspectiveChanged(self, perspective_name):
213        """
214        Respond to change of the perspective signal
215        """
216        # Close the previous perspective
[9e54199]217        self.clearPerspectiveMenubarOptions(self._current_perspective)
[83d6249]218        if self._current_perspective:
[b1e36a3]219            self._current_perspective.setClosable()
[7c487846]220            #self._workspace.workspace.removeSubWindow(self._current_perspective)
[83d6249]221            self._current_perspective.close()
[7c487846]222            self._workspace.workspace.removeSubWindow(self._current_perspective)
[83d6249]223        # Default perspective
[811bec1]224        self._current_perspective = Perspectives.PERSPECTIVES[str(perspective_name)](parent=self)
[9c391946]225
[8ac3551]226        self.setupPerspectiveMenubarOptions(self._current_perspective)
227
[d1955d67]228        subwindow = self._workspace.workspace.addSubWindow(self._current_perspective)
[4992ff2]229
[9c391946]230        # Resize to the workspace height
[fbfc488]231        workspace_height = self._workspace.workspace.sizeHint().height()
232        perspective_size = self._current_perspective.sizeHint()
233        perspective_width = perspective_size.width()
234        self._current_perspective.resize(perspective_width, workspace_height-10)
[d1955d67]235        # Resize the mdi area to match the widget within
236        subwindow.resize(subwindow.minimumSizeHint())
[7969b9c]237
[83d6249]238        self._current_perspective.show()
239
[f721030]240    def updatePerspective(self, data):
241        """
[71361f0]242        Update perspective with data sent.
[f721030]243        """
244        assert isinstance(data, list)
245        if self._current_perspective is not None:
[b3e8629]246            self._current_perspective.setData(list(data.values()))
[f721030]247        else:
248            msg = "No perspective is currently active."
249            logging.info(msg)
[481ff26]250
[f721030]251    def communicator(self):
[257bd57]252        """ Accessor for the communicator """
[f721030]253        return self.communicate
254
255    def perspective(self):
[257bd57]256        """ Accessor for the perspective """
[f721030]257        return self._current_perspective
258
[e540cd2]259    def updateProgressBar(self, value):
260        """
261        Update progress bar with the required value (0-100)
262        """
[8cb6cd6]263        assert -1 <= value <= 100
[e540cd2]264        if value == -1:
265            self.progress.setVisible(False)
266            return
267        if not self.progress.isVisible():
268            self.progress.setTextVisible(True)
269            self.progress.setVisible(True)
270
271        self.progress.setValue(value)
272
[f721030]273    def updateStatusBar(self, text):
274        """
[71361f0]275        Set the status bar text
[f721030]276        """
[e540cd2]277        self.statusLabel.setText(text)
[f721030]278
[e4335ae]279    def appendLog(self, msg):
280        """Appends a message to the list widget in the Log Explorer. Use this
281        instead of listWidget.insertPlainText() to facilitate auto-scrolling"""
282        self.listWidget.append(msg.strip())
283
[1042dba]284    def createGuiData(self, item, p_file=None):
285        """
286        Access the Data1D -> plottable Data1D conversion
287        """
288        return self._data_manager.create_gui_data(item, p_file)
[f721030]289
290    def setData(self, data):
291        """
292        Sends data to current perspective
293        """
294        if self._current_perspective is not None:
[b3e8629]295            self._current_perspective.setData(list(data.values()))
[f721030]296        else:
297            msg = "Guiframe does not have a current perspective"
298            logging.info(msg)
299
[d4dac80]300    def findItemFromFilename(self, filename):
301        """
302        Queries the data explorer for the index corresponding to the filename within
303        """
304        return self.filesWidget.itemFromFilename(filename)
305
[9e426c1]306    def quitApplication(self):
307        """
308        Close the reactor and exit nicely.
309        """
310        # Display confirmation messagebox
311        quit_msg = "Are you sure you want to exit the application?"
[4992ff2]312        reply = QMessageBox.question(
[481ff26]313            self._parent,
[7451b88]314            'Information',
[481ff26]315            quit_msg,
[4992ff2]316            QMessageBox.Yes,
317            QMessageBox.No)
[9e426c1]318
319        # Exit if yes
[4992ff2]320        if reply == QMessageBox.Yes:
[7451b88]321            reactor.callFromThread(reactor.stop)
322            return True
323
324        return False
[9e426c1]325
326    def checkUpdate(self):
327        """
328        Check with the deployment server whether a new version
329        of the application is available.
330        A thread is started for the connecting with the server. The thread calls
331        a call-back method when the current version number has been obtained.
332        """
333        version_info = {"version": "0.0.0"}
[dc5ef15]334        c = ConnectionProxy(LocalConfig.__update_URL__, LocalConfig.UPDATE_TIMEOUT)
[9e426c1]335        response = c.connect()
[71361f0]336        if response is None:
337            return
338        try:
339            content = response.read().strip()
340            logging.info("Connected to www.sasview.org. Latest version: %s"
341                            % (content))
342            version_info = json.loads(content)
343            self.processVersion(version_info)
[b3e8629]344        except ValueError as ex:
[71361f0]345            logging.info("Failed to connect to www.sasview.org:", ex)
[481ff26]346
[f82ab8c]347    def processVersion(self, version_info):
[9e426c1]348        """
349        Call-back method for the process of checking for updates.
350        This methods is called by a VersionThread object once the current
351        version number has been obtained. If the check is being done in the
352        background, the user will not be notified unless there's an update.
353
354        :param version: version string
355        """
356        try:
357            version = version_info["version"]
358            if version == "0.0.0":
359                msg = "Could not connect to the application server."
360                msg += " Please try again later."
361                self.communicate.statusBarUpdateSignal.emit(msg)
362
[cee5c78]363            elif version.__gt__(LocalConfig.__version__):
[9e426c1]364                msg = "Version %s is available! " % str(version)
[f82ab8c]365                if "download_url" in version_info:
366                    webbrowser.open(version_info["download_url"])
[9e426c1]367                else:
[f82ab8c]368                    webbrowser.open(LocalConfig.__download_page__)
[9e426c1]369                self.communicate.statusBarUpdateSignal.emit(msg)
370            else:
371                msg = "You have the latest version"
372                msg += " of %s" % str(LocalConfig.__appname__)
373                self.communicate.statusBarUpdateSignal.emit(msg)
374        except:
375            msg = "guiframe: could not get latest application"
[b3e8629]376            msg += " version number\n  %s" % sys.exc_info()[1]
[9e426c1]377            logging.error(msg)
[f82ab8c]378            msg = "Could not connect to the application server."
379            msg += " Please try again later."
380            self.communicate.statusBarUpdateSignal.emit(msg)
[9e426c1]381
[8353d90]382    def showWelcomeMessage(self):
383        """ Show the Welcome panel """
384        self._workspace.workspace.addSubWindow(self.welcomePanel)
385        self.welcomePanel.show()
386
[f721030]387    def addCallbacks(self):
388        """
[9e426c1]389        Method defining all signal connections for the gui manager
[f721030]390        """
[0cd8612]391        self.communicate = GuiUtils.Communicate()
[9d266d2]392        self.communicate.fileDataReceivedSignal.connect(self.fileWasRead)
[f721030]393        self.communicate.statusBarUpdateSignal.connect(self.updateStatusBar)
394        self.communicate.updatePerspectiveWithDataSignal.connect(self.updatePerspective)
[e540cd2]395        self.communicate.progressBarUpdateSignal.connect(self.updateProgressBar)
[83d6249]396        self.communicate.perspectiveChangedSignal.connect(self.perspectiveChanged)
[cbcdd2c]397        self.communicate.updateTheoryFromPerspectiveSignal.connect(self.updateTheoryFromPerspective)
[fd7ef36]398        self.communicate.deleteIntermediateTheoryPlotsSignal.connect(self.deleteIntermediateTheoryPlotsByModelID)
[d48cc19]399        self.communicate.plotRequestedSignal.connect(self.showPlot)
[3b3b40b]400        self.communicate.plotFromFilenameSignal.connect(self.showPlotFromFilename)
[d5c5d3d]401        self.communicate.updateModelFromDataOperationPanelSignal.connect(self.updateModelFromDataOperationPanel)
[f721030]402
403    def addTriggers(self):
404        """
405        Trigger definitions for all menu/toolbar actions.
406        """
407        # File
408        self._workspace.actionLoadData.triggered.connect(self.actionLoadData)
409        self._workspace.actionLoad_Data_Folder.triggered.connect(self.actionLoad_Data_Folder)
410        self._workspace.actionOpen_Project.triggered.connect(self.actionOpen_Project)
411        self._workspace.actionOpen_Analysis.triggered.connect(self.actionOpen_Analysis)
412        self._workspace.actionSave.triggered.connect(self.actionSave)
413        self._workspace.actionSave_Analysis.triggered.connect(self.actionSave_Analysis)
414        self._workspace.actionQuit.triggered.connect(self.actionQuit)
415        # Edit
416        self._workspace.actionUndo.triggered.connect(self.actionUndo)
417        self._workspace.actionRedo.triggered.connect(self.actionRedo)
418        self._workspace.actionCopy.triggered.connect(self.actionCopy)
419        self._workspace.actionPaste.triggered.connect(self.actionPaste)
420        self._workspace.actionReport.triggered.connect(self.actionReport)
421        self._workspace.actionReset.triggered.connect(self.actionReset)
422        self._workspace.actionExcel.triggered.connect(self.actionExcel)
423        self._workspace.actionLatex.triggered.connect(self.actionLatex)
424
425        # View
426        self._workspace.actionShow_Grid_Window.triggered.connect(self.actionShow_Grid_Window)
427        self._workspace.actionHide_Toolbar.triggered.connect(self.actionHide_Toolbar)
428        self._workspace.actionStartup_Settings.triggered.connect(self.actionStartup_Settings)
[3d18691]429        self._workspace.actionCategory_Manager.triggered.connect(self.actionCategory_Manager)
[f721030]430        # Tools
431        self._workspace.actionData_Operation.triggered.connect(self.actionData_Operation)
432        self._workspace.actionSLD_Calculator.triggered.connect(self.actionSLD_Calculator)
433        self._workspace.actionDensity_Volume_Calculator.triggered.connect(self.actionDensity_Volume_Calculator)
[363fbfa]434        self._workspace.actionKeissig_Calculator.triggered.connect(self.actionKiessig_Calculator)
435        #self._workspace.actionKIESSING_Calculator.triggered.connect(self.actionKIESSING_Calculator)
[f721030]436        self._workspace.actionSlit_Size_Calculator.triggered.connect(self.actionSlit_Size_Calculator)
437        self._workspace.actionSAS_Resolution_Estimator.triggered.connect(self.actionSAS_Resolution_Estimator)
438        self._workspace.actionGeneric_Scattering_Calculator.triggered.connect(self.actionGeneric_Scattering_Calculator)
439        self._workspace.actionPython_Shell_Editor.triggered.connect(self.actionPython_Shell_Editor)
440        self._workspace.actionImage_Viewer.triggered.connect(self.actionImage_Viewer)
[aa1db44]441        self._workspace.actionOrientation_Viewer.triggered.connect(self.actionOrientation_Viewer)
[6b50296]442        self._workspace.actionFreeze_Theory.triggered.connect(self.actionFreeze_Theory)
[f721030]443        # Fitting
444        self._workspace.actionNew_Fit_Page.triggered.connect(self.actionNew_Fit_Page)
445        self._workspace.actionConstrained_Fit.triggered.connect(self.actionConstrained_Fit)
446        self._workspace.actionCombine_Batch_Fit.triggered.connect(self.actionCombine_Batch_Fit)
447        self._workspace.actionFit_Options.triggered.connect(self.actionFit_Options)
[06ce180]448        self._workspace.actionGPU_Options.triggered.connect(self.actionGPU_Options)
[f721030]449        self._workspace.actionFit_Results.triggered.connect(self.actionFit_Results)
[3b3b40b]450        self._workspace.actionAdd_Custom_Model.triggered.connect(self.actionAdd_Custom_Model)
[f721030]451        self._workspace.actionEdit_Custom_Model.triggered.connect(self.actionEdit_Custom_Model)
[3b3b40b]452        self._workspace.actionManage_Custom_Models.triggered.connect(self.actionManage_Custom_Models)
[01ef3f7]453        self._workspace.actionAddMult_Models.triggered.connect(self.actionAddMult_Models)
[f721030]454        # Window
455        self._workspace.actionCascade.triggered.connect(self.actionCascade)
[e540cd2]456        self._workspace.actionTile.triggered.connect(self.actionTile)
[f721030]457        self._workspace.actionArrange_Icons.triggered.connect(self.actionArrange_Icons)
458        self._workspace.actionNext.triggered.connect(self.actionNext)
459        self._workspace.actionPrevious.triggered.connect(self.actionPrevious)
460        # Analysis
461        self._workspace.actionFitting.triggered.connect(self.actionFitting)
462        self._workspace.actionInversion.triggered.connect(self.actionInversion)
463        self._workspace.actionInvariant.triggered.connect(self.actionInvariant)
[8ac3551]464        self._workspace.actionCorfunc.triggered.connect(self.actionCorfunc)
[f721030]465        # Help
466        self._workspace.actionDocumentation.triggered.connect(self.actionDocumentation)
467        self._workspace.actionTutorial.triggered.connect(self.actionTutorial)
468        self._workspace.actionAcknowledge.triggered.connect(self.actionAcknowledge)
469        self._workspace.actionAbout.triggered.connect(self.actionAbout)
470        self._workspace.actionCheck_for_update.triggered.connect(self.actionCheck_for_update)
471
[d4dac80]472        self.communicate.sendDataToGridSignal.connect(self.showBatchOutput)
473
[f721030]474    #============ FILE =================
475    def actionLoadData(self):
476        """
[9e426c1]477        Menu File/Load Data File(s)
[f721030]478        """
[5032ea68]479        self.filesWidget.loadFile()
[f721030]480
481    def actionLoad_Data_Folder(self):
482        """
[9e426c1]483        Menu File/Load Data Folder
[f721030]484        """
[5032ea68]485        self.filesWidget.loadFolder()
[f721030]486
487    def actionOpen_Project(self):
488        """
[630155bd]489        Menu Open Project
[f721030]490        """
[630155bd]491        self.filesWidget.loadProject()
[f721030]492
493    def actionOpen_Analysis(self):
494        """
495        """
496        print("actionOpen_Analysis TRIGGERED")
497        pass
498
499    def actionSave(self):
500        """
[630155bd]501        Menu Save Project
[f721030]502        """
[630155bd]503        self.filesWidget.saveProject()
[f721030]504
505    def actionSave_Analysis(self):
506        """
[57be490]507        Menu File/Save Analysis
[f721030]508        """
[57be490]509        self.communicate.saveAnalysisSignal.emit()
[f721030]510
511    def actionQuit(self):
512        """
[1042dba]513        Close the reactor, exit the application.
[f721030]514        """
[9e426c1]515        self.quitApplication()
[f721030]516
517    #============ EDIT =================
518    def actionUndo(self):
519        """
520        """
521        print("actionUndo TRIGGERED")
522        pass
523
524    def actionRedo(self):
525        """
526        """
527        print("actionRedo TRIGGERED")
528        pass
529
530    def actionCopy(self):
531        """
[8e2cd79]532        Send a signal to the fitting perspective so parameters
533        can be saved to the clipboard
[f721030]534        """
[8e2cd79]535        self.communicate.copyFitParamsSignal.emit("")
[0eff615]536        self._workspace.actionPaste.setEnabled(True)
[f721030]537        pass
538
539    def actionPaste(self):
540        """
[8e2cd79]541        Send a signal to the fitting perspective so parameters
542        from the clipboard can be used to modify the fit state
[f721030]543        """
[8e2cd79]544        self.communicate.pasteFitParamsSignal.emit()
[f721030]545
546    def actionReport(self):
547        """
[57be490]548        Show the Fit Report dialog.
[f721030]549        """
[57be490]550        report_list = None
551        if getattr(self._current_perspective, "currentTab"):
552            try:
553                report_list = self._current_perspective.currentTab.getReport()
554            except Exception as ex:
555                logging.error("Report generation failed with: " + str(ex))
556
557        if report_list is not None:
558            self.report_dialog = ReportDialog(parent=self, report_list=report_list)
559            self.report_dialog.show()
[f721030]560
561    def actionReset(self):
562        """
563        """
[0cd8612]564        logging.warning(" *** actionOpen_Analysis logging *******")
565        print("actionReset print TRIGGERED")
566        sys.stderr.write("STDERR - TRIGGERED")
[f721030]567        pass
568
569    def actionExcel(self):
570        """
[8e2cd79]571        Send a signal to the fitting perspective so parameters
572        can be saved to the clipboard
[f721030]573        """
[8e2cd79]574        self.communicate.copyFitParamsSignal.emit("Excel")
[f721030]575
576    def actionLatex(self):
577        """
[8e2cd79]578        Send a signal to the fitting perspective so parameters
579        can be saved to the clipboard
[f721030]580        """
[8e2cd79]581        self.communicate.copyFitParamsSignal.emit("Latex")
[f721030]582
583    #============ VIEW =================
584    def actionShow_Grid_Window(self):
585        """
586        """
[d4dac80]587        self.showBatchOutput(None)
588
589    def showBatchOutput(self, output_data):
590        """
591        Display/redisplay the batch fit viewer
592        """
593        if self.grid_window is None:
594            self.grid_window = BatchOutputPanel(parent=self, output_data=output_data)
595            subwindow = self._workspace.workspace.addSubWindow(self.grid_window)
596
597            #self.grid_window = BatchOutputPanel(parent=self, output_data=output_data)
598            self.grid_window.show()
599            return
600        if output_data:
601            self.grid_window.addFitResults(output_data)
602        self.grid_window.show()
603        if self.grid_window.windowState() == Qt.WindowMinimized:
604            self.grid_window.setWindowState(Qt.WindowActive)
[f721030]605
606    def actionHide_Toolbar(self):
607        """
[e540cd2]608        Toggle toolbar vsibility
[f721030]609        """
[e540cd2]610        if self._workspace.toolBar.isVisible():
611            self._workspace.actionHide_Toolbar.setText("Show Toolbar")
612            self._workspace.toolBar.setVisible(False)
613        else:
614            self._workspace.actionHide_Toolbar.setText("Hide Toolbar")
615            self._workspace.toolBar.setVisible(True)
[f721030]616        pass
617
618    def actionStartup_Settings(self):
619        """
620        """
621        print("actionStartup_Settings TRIGGERED")
622        pass
623
[3d18691]624    def actionCategory_Manager(self):
[f721030]625        """
626        """
[3d18691]627        self.categoryManagerWidget.show()
[f721030]628
629    #============ TOOLS =================
630    def actionData_Operation(self):
631        """
632        """
[f0bb711]633        self.communicate.sendDataToPanelSignal.emit(self._data_manager.get_all_data())
[d5c5d3d]634
635        self.DataOperation.show()
[f721030]636
637    def actionSLD_Calculator(self):
638        """
639        """
[1d85b5e]640        self.SLDCalculator.show()
[f721030]641
642    def actionDensity_Volume_Calculator(self):
643        """
644        """
[1d85b5e]645        self.DVCalculator.show()
[f721030]646
[363fbfa]647    def actionKiessig_Calculator(self):
648        """
649        """
650        self.KIESSIGCalculator.show()
651
[f721030]652    def actionSlit_Size_Calculator(self):
653        """
654        """
[a8ec5b1]655        self.SlitSizeCalculator.show()
[f721030]656
657    def actionSAS_Resolution_Estimator(self):
658        """
659        """
[fa05c6c1]660        try:
661            self.ResolutionCalculator.show()
662        except Exception as ex:
663            logging.error(str(ex))
664            return
[f721030]665
666    def actionGeneric_Scattering_Calculator(self):
667        """
668        """
[fa05c6c1]669        try:
670            self.GENSASCalculator.show()
671        except Exception as ex:
672            logging.error(str(ex))
673            return
[f721030]674
675    def actionPython_Shell_Editor(self):
676        """
[1af348e]677        Display the Jupyter console as a docked widget.
[f721030]678        """
[fef38e8]679        # Import moved here for startup performance reasons
680        from sas.qtgui.Utilities.IPythonWidget import IPythonWidget
[1af348e]681        terminal = IPythonWidget()
682
683        # Add the console window as another docked widget
[4992ff2]684        self.ipDockWidget = QDockWidget("IPython", self._workspace)
[1af348e]685        self.ipDockWidget.setObjectName("IPythonDockWidget")
686        self.ipDockWidget.setWidget(terminal)
[fbfc488]687        self._workspace.addDockWidget(Qt.RightDockWidgetArea, self.ipDockWidget)
[f721030]688
[6b50296]689    def actionFreeze_Theory(self):
690        """
691        Convert a child index with data into a separate top level dataset
692        """
693        self.filesWidget.freezeCheckedData()
694
[aa1db44]695    def actionOrientation_Viewer(self):
696        """
697        Make sasmodels orientation & jitter viewer available
698        """
699        from sasmodels.jitter import run as orientation_run
700        try:
701            orientation_run()
702        except Exception as ex:
703            logging.error(str(ex))
704
[f721030]705    def actionImage_Viewer(self):
706        """
707        """
708        print("actionImage_Viewer TRIGGERED")
709        pass
710
711    #============ FITTING =================
712    def actionNew_Fit_Page(self):
713        """
[60af928]714        Add a new, empty Fit page in the fitting perspective.
[f721030]715        """
[60af928]716        # Make sure the perspective is correct
717        per = self.perspective()
718        if not isinstance(per, FittingWindow):
719            return
720        per.addFit(None)
[f721030]721
722    def actionConstrained_Fit(self):
723        """
[676f137]724        Add a new Constrained and Simult. Fit page in the fitting perspective.
[f721030]725        """
[676f137]726        per = self.perspective()
727        if not isinstance(per, FittingWindow):
728            return
729        per.addConstraintTab()
[f721030]730
731    def actionCombine_Batch_Fit(self):
732        """
733        """
734        print("actionCombine_Batch_Fit TRIGGERED")
735        pass
736
737    def actionFit_Options(self):
738        """
739        """
[2d0e0c1]740        if getattr(self._current_perspective, "fit_options_widget"):
741            self._current_perspective.fit_options_widget.show()
[f721030]742        pass
743
[06ce180]744    def actionGPU_Options(self):
745        """
[9863343]746        Load the OpenCL selection dialog if the fitting perspective is active
[06ce180]747        """
[9863343]748        if hasattr(self._current_perspective, "gpu_options_widget"):
[06ce180]749            self._current_perspective.gpu_options_widget.show()
750        pass
751
[f721030]752    def actionFit_Results(self):
753        """
754        """
755        print("actionFit_Results TRIGGERED")
756        pass
757
[3b3b40b]758    def actionAdd_Custom_Model(self):
759        """
760        """
761        self.model_editor = TabbedModelEditor(self)
762        self.model_editor.show()
763
[f721030]764    def actionEdit_Custom_Model(self):
765        """
766        """
[3b3b40b]767        self.model_editor = TabbedModelEditor(self, edit_only=True)
768        self.model_editor.show()
769
770    def actionManage_Custom_Models(self):
771        """
772        """
773        self.model_manager = PluginManager(self)
774        self.model_manager.show()
[f721030]775
[01ef3f7]776    def actionAddMult_Models(self):
777        """
778        """
[3b8cc00]779        # Add Simple Add/Multiply Editor
[01ef3f7]780        self.add_mult_editor = AddMultEditor(self)
781        self.add_mult_editor.show()
782
[f721030]783    #============ ANALYSIS =================
784    def actionFitting(self):
785        """
[9e54199]786        Change to the Fitting perspective
[f721030]787        """
[9e54199]788        self.perspectiveChanged("Fitting")
[8ac3551]789        # Notify other widgets
790        self.filesWidget.onAnalysisUpdate("Fitting")
[f721030]791
792    def actionInversion(self):
793        """
[9e54199]794        Change to the Inversion perspective
[f721030]795        """
[d4881f6a]796        self.perspectiveChanged("Inversion")
[8ac3551]797        self.filesWidget.onAnalysisUpdate("Inversion")
[f721030]798
799    def actionInvariant(self):
800        """
[9e54199]801        Change to the Invariant perspective
[f721030]802        """
[9e54199]803        self.perspectiveChanged("Invariant")
[8ac3551]804        self.filesWidget.onAnalysisUpdate("Invariant")
805
806    def actionCorfunc(self):
807        """
808        Change to the Corfunc perspective
809        """
810        self.perspectiveChanged("Corfunc")
811        self.filesWidget.onAnalysisUpdate("Corfunc")
[f721030]812
813    #============ WINDOW =================
814    def actionCascade(self):
815        """
[e540cd2]816        Arranges all the child windows in a cascade pattern.
[f721030]817        """
[2b39fea]818        self._workspace.workspace.cascadeSubWindows()
[f721030]819
[e540cd2]820    def actionTile(self):
[f721030]821        """
[e540cd2]822        Tile workspace windows
[f721030]823        """
[2b39fea]824        self._workspace.workspace.tileSubWindows()
[f721030]825
826    def actionArrange_Icons(self):
827        """
[e540cd2]828        Arranges all iconified windows at the bottom of the workspace
[f721030]829        """
[e540cd2]830        self._workspace.workspace.arrangeIcons()
[f721030]831
832    def actionNext(self):
833        """
[e540cd2]834        Gives the input focus to the next window in the list of child windows.
[f721030]835        """
[2b39fea]836        self._workspace.workspace.activateNextSubWindow()
[f721030]837
838    def actionPrevious(self):
839        """
[e540cd2]840        Gives the input focus to the previous window in the list of child windows.
[f721030]841        """
[2b39fea]842        self._workspace.workspace.activatePreviousSubWindow()
[f721030]843
844    #============ HELP =================
845    def actionDocumentation(self):
846        """
[9e426c1]847        Display the documentation
848
849        TODO: use QNetworkAccessManager to assure _helpLocation is valid
[f721030]850        """
[fe76fba]851        helpfile = "/index.html"
[aed0532]852        self.showHelp(helpfile)
[f721030]853
854    def actionTutorial(self):
855        """
[9e426c1]856        Open the tutorial PDF file with default PDF renderer
[f721030]857        """
[9e426c1]858        # Not terribly safe here. Shell injection warning.
859        # isfile() helps but this probably needs a better solution.
860        if os.path.isfile(self._tutorialLocation):
861            result = subprocess.Popen([self._tutorialLocation], shell=True)
[f721030]862
863    def actionAcknowledge(self):
864        """
[9e426c1]865        Open the Acknowledgements widget
[f721030]866        """
[9e426c1]867        self.ackWidget.show()
[f721030]868
869    def actionAbout(self):
870        """
[9e426c1]871        Open the About box
[f721030]872        """
[f82ab8c]873        # Update the about box with current version and stuff
874
875        # TODO: proper sizing
876        self.aboutWidget.show()
[f721030]877
878    def actionCheck_for_update(self):
879        """
[9e426c1]880        Menu Help/Check for Update
[f721030]881        """
[9e426c1]882        self.checkUpdate()
883
[cbcdd2c]884    def updateTheoryFromPerspective(self, index):
885        """
886        Catch the theory update signal from a perspective
887        Send the request to the DataExplorer for updating the theory model.
888        """
889        self.filesWidget.updateTheoryFromPerspective(index)
890
[fd7ef36]891    def deleteIntermediateTheoryPlotsByModelID(self, model_id):
892        """
893        Catch the signal to delete items in the Theory item model which correspond to a model ID.
894        Send the request to the DataExplorer for updating the theory model.
895        """
896        self.filesWidget.deleteIntermediateTheoryPlotsByModelID(model_id)
897
[d5c5d3d]898    def updateModelFromDataOperationPanel(self, new_item, new_datalist_item):
899        """
900        :param new_item: item to be added to list of loaded files
901        :param new_datalist_item:
902        """
[4992ff2]903        if not isinstance(new_item, QStandardItem) or \
[d5c5d3d]904                not isinstance(new_datalist_item, dict):
905            msg = "Wrong data type returned from calculations."
[b3e8629]906            raise AttributeError(msg)
[d5c5d3d]907
908        self.filesWidget.model.appendRow(new_item)
909        self._data_manager.add_data(new_datalist_item)
910
[3b3b40b]911    def showPlotFromFilename(self, filename):
912        """
913        Pass the show plot request to the data explorer
914        """
915        if hasattr(self, "filesWidget"):
916            self.filesWidget.displayFile(filename=filename, is_data=True)
917
[d48cc19]918    def showPlot(self, plot):
919        """
920        Pass the show plot request to the data explorer
921        """
922        if hasattr(self, "filesWidget"):
923            self.filesWidget.displayData(plot)
[9e54199]924
925    def uncheckAllMenuItems(self, menuObject):
926        """
927        Uncheck all options in a given menu
928        """
929        menuObjects = menuObject.actions()
930
931        for menuItem in menuObjects:
932            menuItem.setChecked(False)
933
934    def checkAnalysisOption(self, analysisMenuOption):
935        """
936        Unchecks all the items in the analysis menu and checks the item passed
937        """
938        self.uncheckAllMenuItems(self._workspace.menuAnalysis)
939        analysisMenuOption.setChecked(True)
940
941    def clearPerspectiveMenubarOptions(self, perspective):
942        """
943        When closing a perspective, clears the menu bar
944        """
945        for menuItem in self._workspace.menuAnalysis.actions():
946            menuItem.setChecked(False)
947
948        if isinstance(self._current_perspective, Perspectives.PERSPECTIVES["Fitting"]):
949            self._workspace.menubar.removeAction(self._workspace.menuFitting.menuAction())
950
951    def setupPerspectiveMenubarOptions(self, perspective):
952        """
953        When setting a perspective, sets up the menu bar
954        """
955        if isinstance(perspective, Perspectives.PERSPECTIVES["Fitting"]):
956            self.checkAnalysisOption(self._workspace.actionFitting)
957            # Put the fitting menu back in
958            # This is a bit involved but it is needed to preserve the menu ordering
959            self._workspace.menubar.removeAction(self._workspace.menuWindow.menuAction())
960            self._workspace.menubar.removeAction(self._workspace.menuHelp.menuAction())
961            self._workspace.menubar.addAction(self._workspace.menuFitting.menuAction())
962            self._workspace.menubar.addAction(self._workspace.menuWindow.menuAction())
963            self._workspace.menubar.addAction(self._workspace.menuHelp.menuAction())
[0eff615]964
[9e54199]965        elif isinstance(perspective, Perspectives.PERSPECTIVES["Invariant"]):
966            self.checkAnalysisOption(self._workspace.actionInvariant)
[8ac3551]967        elif isinstance(perspective, Perspectives.PERSPECTIVES["Inversion"]):
968            self.checkAnalysisOption(self._workspace.actionInversion)
969        elif isinstance(perspective, Perspectives.PERSPECTIVES["Corfunc"]):
970            self.checkAnalysisOption(self._workspace.actionCorfunc)
Note: See TracBrowser for help on using the repository browser.