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