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