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

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since fa762f4 was fa762f4, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 13 months ago

Fixed lifecycle/visibility of the Grid Viewer SASVIEW-1122

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