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