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