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

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 305114c was 768387e0, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Added Data Explorer visibility toggle for more flexibility. SASVIEW-998

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