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