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

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 03e04a4 was 060413c, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

More CR and merge fixes.

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