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