1 | import sys |
---|
2 | |
---|
3 | from PyQt4 import QtCore |
---|
4 | from PyQt4 import QtGui |
---|
5 | from PyQt4 import QtWebKit |
---|
6 | |
---|
7 | from twisted.internet import reactor |
---|
8 | |
---|
9 | # General SAS imports |
---|
10 | from sas.sasgui.guiframe.data_manager import DataManager |
---|
11 | import LocalConfig |
---|
12 | from GuiUtils import * |
---|
13 | |
---|
14 | # Perspectives |
---|
15 | from Perspectives.Invariant.InvariantPerspective import InvariantWindow |
---|
16 | from DataExplorer import DataExplorerWindow |
---|
17 | from WelcomePanel import WelcomePanel |
---|
18 | |
---|
19 | class GuiManager(object): |
---|
20 | """ |
---|
21 | Main SasView window functionality |
---|
22 | """ |
---|
23 | def __init__(self, mainWindow=None, reactor=None, parent=None): |
---|
24 | """ |
---|
25 | |
---|
26 | """ |
---|
27 | self._workspace = mainWindow |
---|
28 | self._parent = parent |
---|
29 | |
---|
30 | # Reactor passed from above |
---|
31 | self.setReactor(reactor) |
---|
32 | |
---|
33 | # Add signal callbacks |
---|
34 | self.addCallbacks() |
---|
35 | |
---|
36 | # Create the data manager |
---|
37 | # TODO: pull out all required methods from DataManager and reimplement |
---|
38 | self._data_manager = DataManager() |
---|
39 | |
---|
40 | # Create action triggers |
---|
41 | self.addTriggers() |
---|
42 | |
---|
43 | # Populate menus with dynamic data |
---|
44 | # |
---|
45 | # Analysis/Perspectives - potentially |
---|
46 | # Window/current windows |
---|
47 | # |
---|
48 | |
---|
49 | # Widgets |
---|
50 | # |
---|
51 | # Add FileDialog widget as docked |
---|
52 | self.filesWidget = DataExplorerWindow(parent, self) |
---|
53 | #flags = (QtCore.Qt.Window | QtCore.Qt.WindowTitleHint | QtCore.Qt.CustomizeWindowHint) |
---|
54 | |
---|
55 | self.dockedFilesWidget = QtGui.QDockWidget("File explorer", self._workspace) |
---|
56 | self.dockedFilesWidget.setWidget(self.filesWidget) |
---|
57 | self._workspace.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.dockedFilesWidget) |
---|
58 | # Disable the close button (?) |
---|
59 | # Show the Welcome panel |
---|
60 | self.welcomePanel = WelcomePanel() |
---|
61 | self._workspace.workspace.addWindow(self.welcomePanel) |
---|
62 | |
---|
63 | # Current help file |
---|
64 | self._helpView = QtWebKit.QWebView() |
---|
65 | self._helpLocation = "html/index.html" |
---|
66 | |
---|
67 | #========================================================== |
---|
68 | # TEMP PROTOTYPE |
---|
69 | # Add InvariantWindow to the workspace. |
---|
70 | self.invariantWidget = InvariantWindow(self) |
---|
71 | self._workspace.workspace.addWindow(self.invariantWidget) |
---|
72 | |
---|
73 | # Default perspective |
---|
74 | self._current_perspective = self.invariantWidget |
---|
75 | |
---|
76 | def fileRead(self, data): |
---|
77 | """ |
---|
78 | """ |
---|
79 | print("FILE %s "%data) |
---|
80 | pass |
---|
81 | |
---|
82 | def updatePerspective(self, data): |
---|
83 | """ |
---|
84 | """ |
---|
85 | assert isinstance(data, list) |
---|
86 | if self._current_perspective is not None: |
---|
87 | self._current_perspective.setData(data.values()) |
---|
88 | else: |
---|
89 | msg = "No perspective is currently active." |
---|
90 | logging.info(msg) |
---|
91 | |
---|
92 | |
---|
93 | def communicator(self): |
---|
94 | """ |
---|
95 | """ |
---|
96 | return self.communicate |
---|
97 | |
---|
98 | def reactor(self): |
---|
99 | """ |
---|
100 | """ |
---|
101 | return self._reactor |
---|
102 | |
---|
103 | def setReactor(self, reactor): |
---|
104 | """ |
---|
105 | """ |
---|
106 | self._reactor = reactor |
---|
107 | |
---|
108 | def perspective(self): |
---|
109 | """ |
---|
110 | """ |
---|
111 | return self._current_perspective |
---|
112 | |
---|
113 | def updateStatusBar(self, text): |
---|
114 | """ |
---|
115 | """ |
---|
116 | self._workspace.statusbar.showMessage(text) |
---|
117 | |
---|
118 | def createGuiData(self, item, p_file=None): |
---|
119 | """ |
---|
120 | Access the Data1D -> plottable Data1D conversion |
---|
121 | """ |
---|
122 | return self._data_manager.create_gui_data(item, p_file) |
---|
123 | |
---|
124 | def addData(self, data_list): |
---|
125 | """ |
---|
126 | receive a dictionary of data from loader |
---|
127 | store them its data manager if possible |
---|
128 | send to data the current active perspective if the data panel |
---|
129 | is not active. |
---|
130 | :param data_list: dictionary of data's ID and value Data |
---|
131 | """ |
---|
132 | #Store data into manager |
---|
133 | #self._data_manager.add_data(data_list) |
---|
134 | |
---|
135 | # set data in the data panel |
---|
136 | #if self._data_panel is not None: |
---|
137 | # data_state = self._data_manager.get_data_state(data_list.keys()) |
---|
138 | # self._data_panel.load_data_list(data_state) |
---|
139 | |
---|
140 | #if the data panel is shown wait for the user to press a button |
---|
141 | #to send data to the current perspective. if the panel is not |
---|
142 | #show automatically send the data to the current perspective |
---|
143 | #style = self.__gui_style & GUIFRAME.MANAGER_ON |
---|
144 | #if style == GUIFRAME.MANAGER_ON: |
---|
145 | # #wait for button press from the data panel to set_data |
---|
146 | # if self._data_panel is not None: |
---|
147 | # self._data_panel.frame.Show(True) |
---|
148 | #else: |
---|
149 | #automatically send that to the current perspective |
---|
150 | #self.setData(data_id=data_list.keys()) |
---|
151 | pass |
---|
152 | |
---|
153 | def setData(self, data): |
---|
154 | """ |
---|
155 | Sends data to current perspective |
---|
156 | """ |
---|
157 | if self._current_perspective is not None: |
---|
158 | self._current_perspective.setData(data.values()) |
---|
159 | else: |
---|
160 | msg = "Guiframe does not have a current perspective" |
---|
161 | logging.info(msg) |
---|
162 | |
---|
163 | def addCallbacks(self): |
---|
164 | """ |
---|
165 | """ |
---|
166 | self.communicate = Communicate() |
---|
167 | self.communicate.fileDataReceivedSignal.connect(self.fileRead) |
---|
168 | self.communicate.statusBarUpdateSignal.connect(self.updateStatusBar) |
---|
169 | self.communicate.updatePerspectiveWithDataSignal.connect(self.updatePerspective) |
---|
170 | |
---|
171 | def addTriggers(self): |
---|
172 | """ |
---|
173 | Trigger definitions for all menu/toolbar actions. |
---|
174 | """ |
---|
175 | # File |
---|
176 | self._workspace.actionLoadData.triggered.connect(self.actionLoadData) |
---|
177 | self._workspace.actionLoad_Data_Folder.triggered.connect(self.actionLoad_Data_Folder) |
---|
178 | self._workspace.actionOpen_Project.triggered.connect(self.actionOpen_Project) |
---|
179 | self._workspace.actionOpen_Analysis.triggered.connect(self.actionOpen_Analysis) |
---|
180 | self._workspace.actionSave.triggered.connect(self.actionSave) |
---|
181 | self._workspace.actionSave_Analysis.triggered.connect(self.actionSave_Analysis) |
---|
182 | self._workspace.actionQuit.triggered.connect(self.actionQuit) |
---|
183 | # Edit |
---|
184 | self._workspace.actionUndo.triggered.connect(self.actionUndo) |
---|
185 | self._workspace.actionRedo.triggered.connect(self.actionRedo) |
---|
186 | self._workspace.actionCopy.triggered.connect(self.actionCopy) |
---|
187 | self._workspace.actionPaste.triggered.connect(self.actionPaste) |
---|
188 | self._workspace.actionReport.triggered.connect(self.actionReport) |
---|
189 | self._workspace.actionReset.triggered.connect(self.actionReset) |
---|
190 | self._workspace.actionExcel.triggered.connect(self.actionExcel) |
---|
191 | self._workspace.actionLatex.triggered.connect(self.actionLatex) |
---|
192 | |
---|
193 | # View |
---|
194 | self._workspace.actionShow_Grid_Window.triggered.connect(self.actionShow_Grid_Window) |
---|
195 | self._workspace.actionHide_Toolbar.triggered.connect(self.actionHide_Toolbar) |
---|
196 | self._workspace.actionStartup_Settings.triggered.connect(self.actionStartup_Settings) |
---|
197 | self._workspace.actionCategry_Manager.triggered.connect(self.actionCategry_Manager) |
---|
198 | # Tools |
---|
199 | self._workspace.actionData_Operation.triggered.connect(self.actionData_Operation) |
---|
200 | self._workspace.actionSLD_Calculator.triggered.connect(self.actionSLD_Calculator) |
---|
201 | self._workspace.actionDensity_Volume_Calculator.triggered.connect(self.actionDensity_Volume_Calculator) |
---|
202 | self._workspace.actionSlit_Size_Calculator.triggered.connect(self.actionSlit_Size_Calculator) |
---|
203 | self._workspace.actionSAS_Resolution_Estimator.triggered.connect(self.actionSAS_Resolution_Estimator) |
---|
204 | self._workspace.actionGeneric_Scattering_Calculator.triggered.connect(self.actionGeneric_Scattering_Calculator) |
---|
205 | self._workspace.actionPython_Shell_Editor.triggered.connect(self.actionPython_Shell_Editor) |
---|
206 | self._workspace.actionImage_Viewer.triggered.connect(self.actionImage_Viewer) |
---|
207 | # Fitting |
---|
208 | self._workspace.actionNew_Fit_Page.triggered.connect(self.actionNew_Fit_Page) |
---|
209 | self._workspace.actionConstrained_Fit.triggered.connect(self.actionConstrained_Fit) |
---|
210 | self._workspace.actionCombine_Batch_Fit.triggered.connect(self.actionCombine_Batch_Fit) |
---|
211 | self._workspace.actionFit_Options.triggered.connect(self.actionFit_Options) |
---|
212 | self._workspace.actionFit_Results.triggered.connect(self.actionFit_Results) |
---|
213 | self._workspace.actionChain_Fitting.triggered.connect(self.actionChain_Fitting) |
---|
214 | self._workspace.actionEdit_Custom_Model.triggered.connect(self.actionEdit_Custom_Model) |
---|
215 | # Window |
---|
216 | self._workspace.actionCascade.triggered.connect(self.actionCascade) |
---|
217 | self._workspace.actionTile_Horizontally.triggered.connect(self.actionTile_Horizontally) |
---|
218 | self._workspace.actionTile_Vertically.triggered.connect(self.actionTile_Vertically) |
---|
219 | self._workspace.actionArrange_Icons.triggered.connect(self.actionArrange_Icons) |
---|
220 | self._workspace.actionNext.triggered.connect(self.actionNext) |
---|
221 | self._workspace.actionPrevious.triggered.connect(self.actionPrevious) |
---|
222 | # Analysis |
---|
223 | self._workspace.actionFitting.triggered.connect(self.actionFitting) |
---|
224 | self._workspace.actionInversion.triggered.connect(self.actionInversion) |
---|
225 | self._workspace.actionInvariant.triggered.connect(self.actionInvariant) |
---|
226 | # Help |
---|
227 | self._workspace.actionDocumentation.triggered.connect(self.actionDocumentation) |
---|
228 | self._workspace.actionTutorial.triggered.connect(self.actionTutorial) |
---|
229 | self._workspace.actionAcknowledge.triggered.connect(self.actionAcknowledge) |
---|
230 | self._workspace.actionAbout.triggered.connect(self.actionAbout) |
---|
231 | self._workspace.actionCheck_for_update.triggered.connect(self.actionCheck_for_update) |
---|
232 | |
---|
233 | #============ FILE ================= |
---|
234 | def actionLoadData(self): |
---|
235 | """ |
---|
236 | Load file from Data Explorer |
---|
237 | """ |
---|
238 | self.filesWidget.loadFile() |
---|
239 | |
---|
240 | def actionLoad_Data_Folder(self): |
---|
241 | """ |
---|
242 | """ |
---|
243 | self.filesWidget.loadFolder() |
---|
244 | |
---|
245 | def actionOpen_Project(self): |
---|
246 | """ |
---|
247 | """ |
---|
248 | print("actionOpen_Project TRIGGERED") |
---|
249 | pass |
---|
250 | |
---|
251 | def actionOpen_Analysis(self): |
---|
252 | """ |
---|
253 | """ |
---|
254 | print("actionOpen_Analysis TRIGGERED") |
---|
255 | pass |
---|
256 | |
---|
257 | def actionSave(self): |
---|
258 | """ |
---|
259 | """ |
---|
260 | print("actionSave TRIGGERED") |
---|
261 | pass |
---|
262 | |
---|
263 | def actionSave_Analysis(self): |
---|
264 | """ |
---|
265 | """ |
---|
266 | print("actionSave_Analysis TRIGGERED") |
---|
267 | |
---|
268 | pass |
---|
269 | |
---|
270 | def actionQuit(self): |
---|
271 | """ |
---|
272 | Close the reactor, exit the application. |
---|
273 | """ |
---|
274 | # display messagebox |
---|
275 | quit_msg = "Are you sure you want to exit the application?" |
---|
276 | reply = QtGui.QMessageBox.question(self._parent, 'Warning', quit_msg, |
---|
277 | QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) |
---|
278 | |
---|
279 | if reply == QtGui.QMessageBox.No: |
---|
280 | return |
---|
281 | |
---|
282 | # exit if yes |
---|
283 | reactor.callFromThread(reactor.stop) |
---|
284 | sys.exit() |
---|
285 | |
---|
286 | #============ EDIT ================= |
---|
287 | def actionUndo(self): |
---|
288 | """ |
---|
289 | """ |
---|
290 | print("actionUndo TRIGGERED") |
---|
291 | pass |
---|
292 | |
---|
293 | def actionRedo(self): |
---|
294 | """ |
---|
295 | """ |
---|
296 | print("actionRedo TRIGGERED") |
---|
297 | pass |
---|
298 | |
---|
299 | def actionCopy(self): |
---|
300 | """ |
---|
301 | """ |
---|
302 | print("actionCopy TRIGGERED") |
---|
303 | pass |
---|
304 | |
---|
305 | def actionPaste(self): |
---|
306 | """ |
---|
307 | """ |
---|
308 | print("actionPaste TRIGGERED") |
---|
309 | pass |
---|
310 | |
---|
311 | def actionReport(self): |
---|
312 | """ |
---|
313 | """ |
---|
314 | print("actionReport TRIGGERED") |
---|
315 | pass |
---|
316 | |
---|
317 | def actionReset(self): |
---|
318 | """ |
---|
319 | """ |
---|
320 | print("actionReset TRIGGERED") |
---|
321 | pass |
---|
322 | |
---|
323 | def actionExcel(self): |
---|
324 | """ |
---|
325 | """ |
---|
326 | print("actionExcel TRIGGERED") |
---|
327 | pass |
---|
328 | |
---|
329 | def actionLatex(self): |
---|
330 | """ |
---|
331 | """ |
---|
332 | print("actionLatex TRIGGERED") |
---|
333 | pass |
---|
334 | |
---|
335 | #============ VIEW ================= |
---|
336 | def actionShow_Grid_Window(self): |
---|
337 | """ |
---|
338 | """ |
---|
339 | print("actionShow_Grid_Window TRIGGERED") |
---|
340 | pass |
---|
341 | |
---|
342 | def actionHide_Toolbar(self): |
---|
343 | """ |
---|
344 | """ |
---|
345 | print("actionHide_Toolbar TRIGGERED") |
---|
346 | pass |
---|
347 | |
---|
348 | def actionStartup_Settings(self): |
---|
349 | """ |
---|
350 | """ |
---|
351 | print("actionStartup_Settings TRIGGERED") |
---|
352 | pass |
---|
353 | |
---|
354 | def actionCategry_Manager(self): |
---|
355 | """ |
---|
356 | """ |
---|
357 | print("actionCategry_Manager TRIGGERED") |
---|
358 | pass |
---|
359 | |
---|
360 | #============ TOOLS ================= |
---|
361 | def actionData_Operation(self): |
---|
362 | """ |
---|
363 | """ |
---|
364 | print("actionData_Operation TRIGGERED") |
---|
365 | pass |
---|
366 | |
---|
367 | def actionSLD_Calculator(self): |
---|
368 | """ |
---|
369 | """ |
---|
370 | print("actionSLD_Calculator TRIGGERED") |
---|
371 | pass |
---|
372 | |
---|
373 | def actionDensity_Volume_Calculator(self): |
---|
374 | """ |
---|
375 | """ |
---|
376 | print("actionDensity_Volume_Calculator TRIGGERED") |
---|
377 | pass |
---|
378 | |
---|
379 | def actionSlit_Size_Calculator(self): |
---|
380 | """ |
---|
381 | """ |
---|
382 | print("actionSlit_Size_Calculator TRIGGERED") |
---|
383 | pass |
---|
384 | |
---|
385 | def actionSAS_Resolution_Estimator(self): |
---|
386 | """ |
---|
387 | """ |
---|
388 | print("actionSAS_Resolution_Estimator TRIGGERED") |
---|
389 | pass |
---|
390 | |
---|
391 | def actionGeneric_Scattering_Calculator(self): |
---|
392 | """ |
---|
393 | """ |
---|
394 | print("actionGeneric_Scattering_Calculator TRIGGERED") |
---|
395 | pass |
---|
396 | |
---|
397 | def actionPython_Shell_Editor(self): |
---|
398 | """ |
---|
399 | """ |
---|
400 | print("actionPython_Shell_Editor TRIGGERED") |
---|
401 | pass |
---|
402 | |
---|
403 | def actionImage_Viewer(self): |
---|
404 | """ |
---|
405 | """ |
---|
406 | print("actionImage_Viewer TRIGGERED") |
---|
407 | pass |
---|
408 | |
---|
409 | #============ FITTING ================= |
---|
410 | def actionNew_Fit_Page(self): |
---|
411 | """ |
---|
412 | """ |
---|
413 | print("actionNew_Fit_Page TRIGGERED") |
---|
414 | pass |
---|
415 | |
---|
416 | def actionConstrained_Fit(self): |
---|
417 | """ |
---|
418 | """ |
---|
419 | print("actionConstrained_Fit TRIGGERED") |
---|
420 | pass |
---|
421 | |
---|
422 | def actionCombine_Batch_Fit(self): |
---|
423 | """ |
---|
424 | """ |
---|
425 | print("actionCombine_Batch_Fit TRIGGERED") |
---|
426 | pass |
---|
427 | |
---|
428 | def actionFit_Options(self): |
---|
429 | """ |
---|
430 | """ |
---|
431 | print("actionFit_Options TRIGGERED") |
---|
432 | pass |
---|
433 | |
---|
434 | def actionFit_Results(self): |
---|
435 | """ |
---|
436 | """ |
---|
437 | print("actionFit_Results TRIGGERED") |
---|
438 | pass |
---|
439 | |
---|
440 | def actionChain_Fitting(self): |
---|
441 | """ |
---|
442 | """ |
---|
443 | print("actionChain_Fitting TRIGGERED") |
---|
444 | pass |
---|
445 | |
---|
446 | def actionEdit_Custom_Model(self): |
---|
447 | """ |
---|
448 | """ |
---|
449 | print("actionEdit_Custom_Model TRIGGERED") |
---|
450 | pass |
---|
451 | |
---|
452 | #============ ANALYSIS ================= |
---|
453 | def actionFitting(self): |
---|
454 | """ |
---|
455 | """ |
---|
456 | print("actionFitting TRIGGERED") |
---|
457 | pass |
---|
458 | |
---|
459 | def actionInversion(self): |
---|
460 | """ |
---|
461 | """ |
---|
462 | print("actionInversion TRIGGERED") |
---|
463 | pass |
---|
464 | |
---|
465 | def actionInvariant(self): |
---|
466 | """ |
---|
467 | """ |
---|
468 | print("actionInvariant TRIGGERED") |
---|
469 | pass |
---|
470 | |
---|
471 | #============ WINDOW ================= |
---|
472 | def actionCascade(self): |
---|
473 | """ |
---|
474 | """ |
---|
475 | print("actionCascade TRIGGERED") |
---|
476 | pass |
---|
477 | |
---|
478 | def actionTile_Horizontally(self): |
---|
479 | """ |
---|
480 | """ |
---|
481 | print("actionTile_Horizontally TRIGGERED") |
---|
482 | pass |
---|
483 | |
---|
484 | def actionTile_Vertically(self): |
---|
485 | """ |
---|
486 | """ |
---|
487 | print("actionTile_Vertically TRIGGERED") |
---|
488 | pass |
---|
489 | |
---|
490 | def actionArrange_Icons(self): |
---|
491 | """ |
---|
492 | """ |
---|
493 | print("actionArrange_Icons TRIGGERED") |
---|
494 | pass |
---|
495 | |
---|
496 | def actionNext(self): |
---|
497 | """ |
---|
498 | """ |
---|
499 | print("actionNext TRIGGERED") |
---|
500 | pass |
---|
501 | |
---|
502 | def actionPrevious(self): |
---|
503 | """ |
---|
504 | """ |
---|
505 | print("actionPrevious TRIGGERED") |
---|
506 | pass |
---|
507 | |
---|
508 | #============ HELP ================= |
---|
509 | def actionDocumentation(self): |
---|
510 | """ |
---|
511 | """ |
---|
512 | self._helpView.load(QtCore.QUrl(self._helpLocation)) |
---|
513 | self._helpView.show() |
---|
514 | |
---|
515 | def actionTutorial(self): |
---|
516 | """ |
---|
517 | """ |
---|
518 | print("actionTutorial TRIGGERED") |
---|
519 | pass |
---|
520 | |
---|
521 | def actionAcknowledge(self): |
---|
522 | """ |
---|
523 | """ |
---|
524 | print("actionAcknowledge TRIGGERED") |
---|
525 | pass |
---|
526 | |
---|
527 | def actionAbout(self): |
---|
528 | """ |
---|
529 | """ |
---|
530 | print("actionAbout TRIGGERED") |
---|
531 | pass |
---|
532 | |
---|
533 | def actionCheck_for_update(self): |
---|
534 | """ |
---|
535 | """ |
---|
536 | print("actionCheck_for_update TRIGGERED") |
---|
537 | pass |
---|
538 | |
---|