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