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