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