forked from susanasanchez/GUIPSY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guipsy.pyw
executable file
·2367 lines (1954 loc) · 101 KB
/
guipsy.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
import gipsy
from gipsy import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
#Common imports
import sys
import functools
import os
import pickle
import webbrowser
#Import modules needed
from browser.workspaceBrowser import *
from gipsyClasses.view_gipsySet import *
from gipsyClasses.gipsySet import *
from gipsyClasses.gipsyTask import *
from gipsyClasses.view_tasks import *
from session.session import *
from workflow.workflow import *
from dialog.historyDlg import *
from dialog.tableHeadersDlg import *
from dialog.plotTableWindow import *
from dialog.aboutDlg import *
from table.view_table import *
from images.view_image import *
from help.view_help import *
from help.view_helpFile import *
from launch.view_cola import *
from launch.view_pyfile import *
from text.view_text import *
from new_exceptions import *
import resources_rc
#Import general things
import general
from general import *
class document(object):
"""
This class represents the different kind of document that GUIpsy can open: set, table, cola, text, python script, image.
The class document has two attributes:
docname: It is the whole path of the document
type: it is the type of the document. The possible types are:
- SET: Document is a set
- COLA: Document is a cola file
- COLTEMP: Document is a cola template
- TEXT: Document is a text file
- PYFILE: Document is a python script
- PYTEMP: Document is a python template
- IMAGE: Document is a image file(jpg, gif and other image format)
- HELP: Document is a gipsy task help page
- TABLE: Document is a ascii table
- SETTABLE: Document is a table embedded in a gipsy SET
- VOTABLE: Document is a table with VO format
- SESSION: Document is a session
"""
def __init__(self, docname, type):
self.docname = docname
self.type = type
def getDocname(self):
return self.docname
def getType(self):
return self.type
def setDocname(self, newDoc):
self.docname=newDoc
class MainWindow(QMainWindow):
"""
This class is the main window of the application. This inherits from QMainWindow class, so it has its own layout.
It is composed by this widget:
- self.browser: It is the widget of the left part.
- self.workspaceBrowser: It is the tab which is showed in the self.browser widget. It inherits from workspaceBrowser class and it contains the session tree file structure.
- self.info: It is the widget of the right part.
- self.info_task: it is the tab which is showed in the self.info widget.It inherits from view_help class and it contains the list of gipsy task, and show some info about this task.
- self.documents: It is the central tabbed widget, which show all the documents opened in the application
This class also contains these next attributes:
- self.allDocuments: A list of object of the class Document. It keeps a list of all the documents opened.
- self.allWidgets: A dictionary which store the widget of the different document opened. Each kind of document has its own widget to be showed, e.g. the widget for the tables contains a view to show the tabular data. The keys of ths dictionary is the whole path of the document showed in this widget.
- self.recentDocuments: A list of the documents paths recently opened
- self.recentTypes: A list of the types stored in self.recentDocuments
- self.session: The current session opened. If no session was opened, a default session will be stored in this attribute.
"""
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
#CREATE APPLICATION DIRECTORY
try:
os.mkdir(GUIPSYDIR)
except OSError: #The dir already exists
pass
#COUNTER
self.cnt=counter()
#OPERATIONAL ATRIBUTES
#list of all opened documents
self.allDocuments=[]
#list of all inside set tables
#self.allSetTables=[]
#List of all widget in opened
self.allWidgets={}
#list of recent opened files (max=10)
self.recentDocuments=[]
#Variable to keep the session information
c=self.cnt()
self.session=session(c)
self.LASTPATH=os.getcwd()
#UI ATRIBUTES
#browser area
browserDockWidget = QDockWidget( self)
browserDockWidget.setObjectName("browserDockWidget")
browserDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea)
self.browser = QTabWidget()
browserDockWidget.setWidget(self.browser)
self.addDockWidget(Qt.LeftDockWidgetArea, browserDockWidget)
#info area
infoDockWidget = QDockWidget( self)
infoDockWidget.setObjectName("infoDockWidget")
infoDockWidget.setAllowedAreas(Qt.RightDockWidgetArea)
self.info=QTabWidget()
infoDockWidget.setWidget(self.info)
self.addDockWidget(Qt.RightDockWidgetArea, infoDockWidget)
# info area for task help
self.infoTask=view_help()
self.info.addTab(self.infoTask, "Tasks")
# documents area and workflow area
self.documents = QTabWidget()
self.documents.setTabsClosable(True)
self.workflow = workflow()
self.workArea=QSplitter(Qt.Vertical)
self.workArea.addWidget(self.documents)
self.workArea.addWidget(self.workflow)
self.setCentralWidget(self.workArea)
#Adding workspaceBrowser
self.workspaceBrowser=workspaceBrowser()
self.browser.addTab(self.workspaceBrowser,"Workspace Browser")
#SAMP CONNECTION
self.hub = sampy.SAMPHubServer()
self.hub.start(False)
# Create a client
try:
self.sampClient = sampy.SAMPIntegratedClient(metadata = {"samp.name":"GUIpsy client", "samp.description.text":"GUIpsy, advanced GUI for Gipsy - a highly interactive software for the reduction of astronomical data", "cli1.version":"0.01"})
except sampy.SAMPHubError, e:
QMessageBox.warning(self, "SAMP connection Failed", unicode(e))
else:
# Connect them
self.sampClient.connect()
#If it is received a notification with the messages coord.pointAt, a SIGNAL will be emitted to transmit the coordinates.
self.sampClient.bindReceiveNotification("coord.pointAt.sky",self.emit_sampcoord)
#If it is recieved a LoadFits, a function to load the fits will be executed
self.sampClient.bindReceiveNotification("image.load.fits", self.emit_imageloadfits)
self.sampClient.bindReceiveNotification("table.load.votable", self.emit_loadvotable)
#Creating icons
self.iconDict={}
self.icon_filenew=QIcon()
self.icon_filenew.addPixmap(QPixmap(":/filenew.png"), QIcon.Normal, QIcon.Off)
self.iconDict["FILENEW"]=self.icon_filenew
self.icon_fileopen=QIcon()
self.icon_fileopen.addPixmap(QPixmap(":/fileopen.png"), QIcon.Normal, QIcon.Off)
self.iconDict["FILEOPEN"]=self.icon_fileopen
self.icon_tabclose=QIcon()
self.icon_tabclose.addPixmap(QPixmap(":/tab-close.png"), QIcon.Normal, QIcon.Off)
self.iconDict["TABCLOSE"]=self.icon_tabclose
self.icon_quit=QIcon()
self.icon_quit.addPixmap(QPixmap(":/filequit.png"), QIcon.Normal, QIcon.Off)
self.iconDict["QUIT"]=self.icon_quit
self.icon_session=QIcon()
self.icon_session.addPixmap(QPixmap(":/session.png"), QIcon.Normal, QIcon.Off)
self.iconDict["SESSION"]=self.icon_session
self.icon_sessionclose=QIcon()
self.icon_sessionclose.addPixmap(QPixmap(":/session-close.png"), QIcon.Normal, QIcon.Off)
self.iconDict["SESSIONCLOSE"]=self.icon_sessionclose
self.icon_set=QIcon()
self.icon_set.addPixmap(QPixmap(":/cube.png"), QIcon.Normal, QIcon.Off)
self.iconDict["SET"]=self.icon_set
self.icon_table=QIcon()
self.icon_table.addPixmap(QPixmap(":/table.png"), QIcon.Normal, QIcon.Off)
self.iconDict["TABLE"]=self.icon_table
self.iconDict["SETTABLE"]=self.icon_table
self.iconDict["VOTABLE"]=self.icon_table
self.icon_image=QIcon()
self.icon_image.addPixmap(QPixmap(":/image.png"), QIcon.Normal, QIcon.Off)
self.iconDict["IMAGE"]=self.icon_image
self.icon_help=QIcon()
self.icon_help.addPixmap(QPixmap(":/help.png"), QIcon.Normal, QIcon.Off)
self.iconDict["HELP"]=self.icon_help
self.icon_cola=QIcon()
self.icon_cola.addPixmap(QPixmap(":/cola.png"), QIcon.Normal, QIcon.Off)
self.iconDict["COLA"]=self.icon_cola
self.iconDict["COLATEMP"]=self.icon_cola
self.icon_text=QIcon()
self.icon_text.addPixmap(QPixmap(":/text.png"), QIcon.Normal, QIcon.Off)
self.iconDict["TEXT"]=self.icon_text
self.icon_pyfile=QIcon()
self.icon_pyfile.addPixmap(QPixmap(":/python.png"), QIcon.Normal, QIcon.Off)
self.iconDict["PYFILE"]=self.icon_pyfile
self.iconDict["PYTEMP"]=self.icon_pyfile
self.icon_task=QIcon()
self.icon_task.addPixmap(QPixmap(":/icon_gui.png"), QIcon.Normal, QIcon.Off)
self.iconDict["task"]=self.icon_task
self.icon_taskgid=QIcon()
self.icon_taskgid.addPixmap(QPixmap(":/loading.png"), QIcon.Normal, QIcon.Off)
self.iconDict["taskgid"]=self.icon_taskgid
#Adding status area
self.sizeLabel = QLabel()
self.sizeLabel.setFrameStyle(QFrame.StyledPanel|QFrame.Sunken)
status = self.statusBar()
status.setSizeGripEnabled(False)
status.addPermanentWidget(self.sizeLabel)
status.showMessage("Ready", 5000)
#FILE MENU
newColaActions=[]
newColaGroup=QActionGroup(self)
emptyCola_action = QAction("Empty cola file", self)
emptyCola_action.setToolTip(menuTips['empty_cola_file'])
emptyCola_action.setStatusTip(menuTips['empty_cola_file'])
curried = functools.partial(self.fileNewCola, templateName=None)
self.connect(emptyCola_action, SIGNAL("triggered()"), curried)
newColaActions.append(emptyCola_action)
colTemplateDir=QDir(DIRCOLATEMPLATE)
colTemplateList = colTemplateDir.entryInfoList()
for colTemplate in colTemplateList:
template_action = QAction(colTemplate.fileName(), self)
curried = functools.partial(self.fileOpenTemplate, type="COLATEMP", templateName=colTemplate.fileName(), templatePath=colTemplate.filePath())
self.connect(template_action, SIGNAL("triggered()"), curried)
newColaActions.append(template_action)
newColaActions.append(None)
newPyfileActions=[]
newPyfileGroup=QActionGroup(self)
emptyPyfile_action = QAction("Empty python file", self)
emptyPyfile_action.setToolTip(menuTips['empty_python_file'])
emptyCola_action.setStatusTip(menuTips['empty_python_file'])
curried = functools.partial(self.fileNewPyfile, templateName=None)
self.connect(emptyPyfile_action, SIGNAL("triggered()"), curried)
newPyfileActions.append(emptyPyfile_action)
pyTemplateDir=QDir(DIRPYTHONTEMPLATE)
pyTemplateList = pyTemplateDir.entryInfoList()
for pyTemplate in pyTemplateList:
template_action = QAction(pyTemplate.fileName(), self)
curried = functools.partial(self.fileOpenTemplate, type="PYTEMP", templateName=pyTemplate.fileName(), templatePath=pyTemplate.filePath())
self.connect(template_action, SIGNAL("triggered()"), curried)
newPyfileActions.append(template_action)
newPyfileActions.append(None)
fileMenu = self.menuBar().addMenu("&File")
newTextAction = self.createAction("Te&xt File", self.fileNewText,tip=menuTips['new_text_file'])
newSessionAction = self.createAction("&Session", self.fileNewSession,tip=menuTips['new_session'])
openGroup = QActionGroup(self)
curried = functools.partial(self.fileOpenDocument,"SET")
openSetAction = self.createAction("S&et", curried, tip=menuTips['open_set'])
curried = functools.partial(self.fileOpenDocument,"TABLE")
openTableAction = self.createAction("&Table", curried,tip=menuTips['open_table'])
curried = functools.partial(self.fileOpenDocument,"IMAGE")
openImageAction = self.createAction("&Image File", curried,tip=menuTips['open_image'])
curried = functools.partial(self.fileOpenDocument,"COLA")
openColaAction = self.createAction("&Cola file", curried,tip=menuTips['open_cola'])
curried = functools.partial(self.fileOpenDocument,"TEXT")
openTextAction = self.createAction("Te&xt file", curried,tip=menuTips['open_text'])
curried = functools.partial(self.fileOpenDocument,"PYFILE")
openPyfileAction = self.createAction("&Python file", curried,tip=menuTips['open_pyfile'])
openSessionAction = self.createAction("&Session file", self.fileOpenSession,tip=menuTips['open_session'])
curried = functools.partial(self.interfaceTask,view_rfits)
openFitsAction=self.createAction("&Fits file",curried, tip=menuTips['open_fits'])
#openFitsAction = self.createAction("&Fits file", self.fileOpenFits,tip=menuTips['open_fits'])
self.openActions=(openColaAction,openFitsAction,openImageAction, openPyfileAction, openSessionAction, openSetAction, openTableAction, openTextAction)
fileSaveSessionAction = self.createAction("Save Session", self.saveSession,
tip=menuTips['save_session'])
fileSaveAction = self.createAction("&Save", self.save,
QKeySequence.Save, tip=menuTips['save'])
fileSaveAsAction = self.createAction("Save &As...",
self.saveAs, tip=menuTips['save_as'])
fileSaveAsVOTAction = self.createAction("Save as VOtable...",
self.saveAsVotable, tip=menuTips['save_as_vot'])
fileSaveAsASCIITAction = self.createAction("Save as ASCII table...",
self.saveAsASCIItable, tip=menuTips['save_as_ascii'])
curried = functools.partial(self.interfaceTask,view_wfits)
fileSaveSetAsAction = self.createAction("Save as fits",
curried, tip=menuTips['save_as_fits'])
fileCloseAction = self.createAction("&Close Tab", self.closeTab,
tip=menuTips['close'], icon=self.iconDict["TABCLOSE"])
fileCloseSessionAction = self.createAction("Close Session", self.closeSession,
tip=menuTips['close_session'], icon=self.iconDict["SESSIONCLOSE"])
fileCloseAllAction = self.createAction("Close All", self.closeAll,
tip=menuTips['close_all'])
fileQuitAction = self.createAction("&Quit", self.close,
"Ctrl+Q", tip=menuTips['quit'], icon=self.iconDict["QUIT"])
self.fileMenuActions = ( fileCloseAction, fileCloseSessionAction, fileCloseAllAction, None,
fileSaveSessionAction, fileSaveAction, fileSaveAsAction, fileSaveAsVOTAction, fileSaveAsASCIITAction, fileSaveSetAsAction, None, fileQuitAction)
newMenu = fileMenu.addMenu(self.iconDict["FILENEW"],"&New")
colaMenu = newMenu.addMenu("&Cola")
pyfileMenu=newMenu.addMenu("&Python")
openMenu= fileMenu.addMenu(self.iconDict["FILEOPEN"],"&Open")
openRecentMenu=fileMenu.addMenu("Open &Recent")
openRecentMenu.setEnabled(True)
self.openRecentFiles = openRecentMenu.addMenu("Files")
self.openRecentSessions = openRecentMenu.addMenu("Sessions")
newMenu.addAction(newTextAction)
newMenu.addAction(newSessionAction)
self.addActions(colaMenu, newColaActions)
self.addActions(pyfileMenu, newPyfileActions)
self.addActions(openMenu, self.openActions)
self.addActions(fileMenu,(
fileCloseAction, fileCloseSessionAction, fileCloseAllAction, None,
fileSaveSessionAction, fileSaveAction, fileSaveAsAction, fileSaveAsVOTAction, fileSaveAsASCIITAction, fileSaveSetAsAction, None, fileQuitAction))
self.fileMenuActions[0].setEnabled(False)
self.fileMenuActions[2].setEnabled(False)
self.fileMenuActions[5].setEnabled(False)
self.fileMenuActions[6].setEnabled(False)
self.fileMenuActions[7].setEnabled(False)
self.fileMenuActions[8].setEnabled(False)
self.fileMenuActions[9].setEnabled(False)
#SET EDITION MENU
# The menu item of the task without dialog, will open the corresponding help file
#Needed to know the file help of the tasks
p=os.environ.get("gip_tsk")
editMenu = self.menuBar().addMenu("&Set Edition")
curried = functools.partial(self.interfaceTask,view_combin)
Combin=self.createAction("Combin",curried, tip=menuTips['Combin'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_clip, "clip")
Clip=self.createAction("Clip",curried, tip=menuTips['Clip'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_copy)
Copy=self.createAction("Copy",curried, tip=menuTips['Copy'], icon=self.icon_task)
# viewDlg=view_decim(self)
# curried = functools.partial(self.interfaceTask,viewDlg)
curried = functools.partial(self.interfaceTask,view_decim, "decim")
Decim=self.createAction("Decim",curried, tip=menuTips['Decim'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_diminish, "diminish")
Diminish=self.createAction("Diminish",curried, tip=menuTips['Diminish'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_editset, "editset")
EditSet=self.createAction("EditSet",curried, tip=menuTips['EditSet'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_extend, "extend")
Extend=self.createAction("Extend",curried, tip=menuTips['Extend'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_insert, "insert")
Insert=self.createAction("Insert",curried, tip=menuTips['Insert'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_meanSum, "mean")
Mean=self.createAction("Mean",curried, icon=self.icon_task, tip=menuTips['Mean'])
curried = functools.partial(self.interfaceTask,view_minbox, "minbox")
MinBox=self.createAction("MinBox",curried, icon=self.icon_task, tip=menuTips['MinBox'])
curried = functools.partial(self.interfaceTask,view_regrid)
Regrid=self.createAction("Regrid",curried, icon=self.icon_task, tip=menuTips['Regrid'])
curried = functools.partial(self.interfaceTask,view_snapper, "snapper")
Snapper=self.createAction("Snapper",curried, icon=self.icon_task, tip=menuTips['Snapper'])
curried = functools.partial(self.interfaceTask,view_transform, "transform")
Transform=self.createAction("Transform",curried, tip=menuTips['Transform'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_transpose, "transpose")
Transpose=self.createAction("Transpose",curried, tip=menuTips['Transpose'],icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_velsmo, "velsmo")
Velsmo=self.createAction("Velsmo",curried, tip=menuTips['Velsmo'], icon=self.icon_task)
Pyblot=self.createTaskAction("PyBlot", "pyblot", shortcut=None, icon=self.icon_taskgid, tip=menuTips['PyBlot'])
curried = functools.partial(self.fileOpenDocument,"HELP", p+"/condit"+".dc1")
conDit=self.createAction("ConDit",slot=curried, tip=menuTips['ConDit'], icon=self.icon_help)
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/conrem"+".dc1")
conRem=self.createAction("ConRem",slot=curried, tip=menuTips['ConRem'], icon=self.icon_help)
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/findgauss"+".dc1")
findGauss=self.createAction("findGauss",slot=curried, tip=menuTips['FindGauss'], icon=self.icon_help)
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/mfilter"+".dc1")
MFilter=self.createAction("MFilter",slot=curried, tip=menuTips['MFilter'], icon=self.icon_help)
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/patch"+".dc1")
Patch=self.createAction("Patch",slot=curried, tip=menuTips['Patch'], icon=self.icon_help)
self.addActions (editMenu, ( Clip, Combin, Copy, Decim, Diminish, EditSet, Extend, Insert,
Mean, MinBox, Regrid, Snapper, Transform, Transpose, Velsmo, None, Pyblot,
None, conDit, conRem, findGauss, MFilter, Patch))
#DISPLAY MENU
displayMenu = self.menuBar().addMenu("&Display")
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/maps"+".dc1")
Maps=self.createAction("Maps", enable=False, slot=curried, tip=menuTips['Maps'], icon=self.icon_help)
SkyCalq=self.createTaskAction("SkyCalq", "skycalq", shortcut=None, icon=self.icon_taskgid, tip=menuTips['SkyCalq'])
Sliceview=self.createTaskAction("Sliceview", "sliceview", shortcut=None, icon=self.icon_taskgid, tip=menuTips['Sliceview'])
Inspector=self.createTaskAction("Inspector", "inspector", shortcut=None, icon=self.icon_taskgid, tip=menuTips['Inspector'])
Render=self.createTaskAction("Render", "render", shortcut=None, icon=self.icon_taskgid, tip=menuTips['Render'])
VTKVolume=self.createTaskAction("VTKVolume", "vtkvolume", shortcut=None, icon=self.icon_taskgid, tip=menuTips['VTKVolume'])
Visions=self.createTaskAction("Visions", "visions", shortcut=None, icon=self.icon_taskgid, tip=menuTips['Visions'])
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/allskyplot"+".dc1")
AllSkyPlot=self.createAction("AllSkyPlot", slot=curried, tip=menuTips['AllSkyPlot'], icon=self.icon_help)
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/cplot"+".dc1")
CPlot=self.createAction("CPlot", slot=curried, tip=menuTips['CPlot'], icon=self.icon_help)
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/reproj"+".dc1")
Reproj=self.createAction("Reproj", slot=curried, tip=menuTips['Reproj'], icon=self.icon_help)
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/fitsreproj"+".dc1")
ReprojFits=self.createAction("Fitsreproj", slot=curried, tip=menuTips['ReprojFits'], icon=self.icon_help)
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/wcsflux"+".dc1")
WCSFlux=self.createAction("WCSFlux", slot=curried, tip=menuTips['WCSFlux'], icon=self.icon_help)
self.addActions(displayMenu, (Maps, SkyCalq, None,
Sliceview, Inspector, Render, VTKVolume, Visions, None,
AllSkyPlot, CPlot, Reproj, ReprojFits, WCSFlux))
#ANALYSIS MENU
taskMenu = self.menuBar().addMenu("&Analysis")
curried = functools.partial(self.interfaceTask,view_ellint, "ellint")
EllInt=self.createAction("EllInt", curried, tip=menuTips['EllInt'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_galmod, "galmod")
GalMod=self.createAction("GalMod", curried, tip=menuTips['GalMod'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_moments, "moments")
Moments=self.createAction("Moments", curried, tip=menuTips['Moments'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_potential, "potential")
Potential=self.createAction("Potential", curried, tip=menuTips['Potential'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_pplot, "pplot")
PPlot=self.createAction("PPlot", curried, tip=menuTips['PPlot'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_profil, "profil")
Profil=self.createAction("Profil", curried, tip=menuTips['Profil'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_reswri, "reswri")
ResWri=self.createAction("ResWri", curried, tip=menuTips['ResWri'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_rotcur, "rotcur")
RotCur=self.createAction("RotCur", curried, tip=menuTips['RotCur'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_shuffle, "shuffle")
Shuffle=self.createAction("Shuffle", curried, tip=menuTips['Shuffle'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_slice, "slice")
Slice=self.createAction("Slice", curried, tip=menuTips['Slice'], icon=self.icon_task)
curried = functools.partial(self.interfaceTask,view_velfi, "velfi")
VelFi=self.createAction("VelFi", curried, tip=menuTips['VelFi'], icon=self.icon_task)
Inspector=self.createTaskAction("Inspector", "inspector", shortcut=None, icon=self.icon_taskgid, tip=menuTips['Inspector'])
RotMas=self.createTaskAction("RotMas", "rotmas", shortcut=None, icon=self.icon_taskgid, tip=menuTips['RotMas'])
XGauFit=self.createTaskAction("XGauFit", "xgaufit", shortcut=None, icon=self.icon_taskgid,tip=menuTips['XGauFit'])
XGauProf=self.createTaskAction("XGauProf", "xgauprof", shortcut=None, icon=self.icon_taskgid, tip=menuTips['XGauProf'])
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/gausscube"+".dc1")
GaussCube=self.createAction("GaussCube",slot=curried, tip=menuTips['GaussCube'], icon=self.icon_help)
curried = functools.partial(self.fileOpenDocument,"HELP",p+"/rotmod"+".dc1")
RotMod=self.createAction("RotMod",slot=curried, tip=menuTips['RotMod'], icon=self.icon_help)
self.addActions(taskMenu,(EllInt, GalMod, Moments, Potential, PPlot, Profil, ResWri, RotCur,
Shuffle, Slice, VelFi, None,Inspector, RotMas, XGauFit, XGauProf, None,
GaussCube, RotMod ))
self.taskMenuActions={ "clip":Clip, "combin":Combin, "copy":Copy, "decim":Decim, "diminish":Diminish, "editset":EditSet, "extend":Extend, "insert":Insert,
"mean":Mean, "minbox":MinBox, "regrid":Regrid, "snapper":Snapper, "transform":Transform, "transpose":Transpose, "velsmo":Velsmo,
"pyblot":Pyblot, "condit":conDit, "conrem":conRem, "findgauss":findGauss, "mfilter":MFilter, "patch":Patch, "maps":Maps, "skycalq":SkyCalq,
"sliceview":Sliceview, "inspector":Inspector, "render":Render, "vtkvolume":VTKVolume, "allskyplot":AllSkyPlot, "cplot":CPlot,
"reproj":Reproj, "reprojfits":ReprojFits, "WCSFlux":WCSFlux, "ellint":EllInt, "galmod":GalMod, "moments":Moments,
"potential":Potential, "pplot":PPlot, "profil":Profil, "reswri":ResWri, "rotcur":RotCur, "shuffle":Shuffle, "slice":Slice, "velfi":VelFi,
"inspector":Inspector, "rotmas":RotMas, "xgaufit":XGauFit, "xgauprof":XGauProf, "gausscube":GaussCube, "rotmod":RotMod}
#VO MENU
voMenu = self.menuBar().addMenu("&Virtual Observatory")
curried=functools.partial(self.VOToolsTask, VOTOOLS["TOPCAT"])
topcatAction=self.createAction("TOPCAT", curried, enable=True, tip=menuTips['TOPCAT'])
curried=functools.partial(self.VOToolsTask, VOTOOLS["ALADIN"])
aladinAction=self.createAction("ALADIN", curried,enable=True, tip=menuTips['ALADIN'])
curried=functools.partial(self.VOToolsTask, VOTOOLS["VOSPEC"])
vospecAction=self.createAction("VOSPEC", curried, enable=True, tip=menuTips['VOSPEC'])
# vosearchAction=self.createAction("VO search", self.voTemplate, enable=False, tip=menuTips['VOSearch'])
# senttoAction=self.createAction("Sent to ...", self.voTemplate, enable=False, tip=menuTips['Send_to'])
self.addActions(voMenu,(topcatAction,aladinAction, vospecAction))
#HELP MENU
helpMenu = self.menuBar().addMenu("&Help")
handbook=self.createAction("Handbook", self.showAboutDlg, enable=False, tip=menuTips['Handbook'])
about=self.createAction("About", self.showAboutDlg, enable=True, tip=menuTips['About'])
self.addActions(helpMenu, (handbook, about))
#CONNECTING SLOTS
self.connect(self.documents, SIGNAL("currentChanged(int)"), self.documentsChanged)
self.connect(self.workspaceBrowser, SIGNAL("itemSelected"), self.documentsSelected)
self.connect(self.workspaceBrowser, SIGNAL("itemDoubleClicked"), self.documentsDoubleClicked)
self.connect(self.workspaceBrowser, SIGNAL("contextMenu"), self.showContextMenu)
self.connect(self.documents, SIGNAL("tabCloseRequested(int)"), self.closeTab)
self.connect(self.infoTask, SIGNAL("openHelpFile"), lambda file: self.fileOpenDocument("HELP", file))
self.connect(self.workflow,SIGNAL("updateWorkflow"), lambda: self.session.updateWorkflowText(self.workflow.getWorkflowText()))
self.connect(self, SIGNAL("imageloadfits"), self.openFitsFromSamp)
self.connect(self, SIGNAL("loadvotable"), self.openVotableFromSamp)
#SETTINGS + WINDOW APPERANCE
settings = QSettings()
size = settings.value("MainWindow/Size",
QVariant(QSize(600, 500))).toSize()
self.resize(size)
position = settings.value("MainWindow/Position",
QVariant(QPoint(0, 0))).toPoint()
self.move(position)
self.restoreState(settings.value("MainWindow/State").toByteArray());
self.workArea.restoreState(settings.value("splitterSizes").toByteArray())
self.setWindowTitle("GUIpsy")
self.recentDocuments=settings.value("recentDocuments").toStringList()
self.recentTypes=settings.value("recentTypes").toStringList()
self.updateOpenRecentMenu()
#ACTION FUNCTIONS
def createAction(self, text, slot=None, shortcut=None, icon=None,
tip=None, checkable=False, enable=True,signal="triggered()"):
action = QAction(text, self)
if icon is not None:
action.setIcon(icon)
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
if slot is not None:
self.connect(action, SIGNAL(signal), slot)
if checkable:
action.setCheckable(True)
if not enable:
action.setEnabled(False)
return action
def createTaskAction(self, text, taskname, shortcut=None, icon=None, tip=None):
action = QAction(text, self)
if icon is not None:
action.setIcon(icon)
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
curried = functools.partial(self.sendTask, taskname=taskname)
self.connect(action, SIGNAL("triggered()"), curried)
return action
def addActions(self, target, actions):
for action in actions:
if action is None:
target.addSeparator()
else:
target.addAction(action)
#CLOSE EVENT
def closeEvent(self, event):
self.closeAll()
if(self.okToContinue()):
self.session.close()
settings = QSettings()
settings.setValue("MainWindow/Size", QVariant(self.size()))
settings.setValue("MainWindow/Position",QVariant(self.pos()))
settings.setValue("MainWindow/State", self.saveState())
settings.setValue("splitterSizes", self.workArea.saveState())
settings.setValue("recentDocuments", self.recentDocuments)
settings.setValue("recentTypes", self.recentTypes)
else:
event.ignore()
#Closing the HUB and the client.
try:
self.sampClient.disconnect()
except sampy.SAMPClientError, e:
pass
self.hub.stop()
#SLOTS
def documentsChanged(self, index):
#fileCloseAction, fileCloseSessionAction, fileCloseAllAction, None, fileSaveSessionAction, fileSaveAction, fileSaveAsAction, fileSaveAsVOTAction, fileSaveAsASCIITAction, fileSaveSetAsAction, None, fileQuitAction
self.fileMenuActions[5].setEnabled(False) #Option save
self.fileMenuActions[6].setEnabled(False) #Option save as
self.fileMenuActions[7].setEnabled(False) #Option save as votable
self.fileMenuActions[8].setEnabled(False) #Option save as ascii table
self.fileMenuActions[9].setEnabled(False) #Option save as fits
self.fileMenuActions[0].setEnabled(False) #Option close
self.fileMenuActions[2].setEnabled(False) #Option close all
if(index>-1):
self.workspaceBrowser.selectFile(self.allDocuments[index].getDocname())
type=self.allDocuments[index].getType()
self.fileMenuActions[5].setEnabled(True) #Option save
self.fileMenuActions[6].setEnabled(True) #Option save as
self.fileMenuActions[0].setEnabled(True) #Option close
self.fileMenuActions[2].setEnabled(True) #Option close all
if (type== "SET") :
self.fileMenuActions[5].setEnabled(False)
self.fileMenuActions[6].setEnabled(False)
self.fileMenuActions[9].setEnabled(True) #Option save as fits
elif (type=="COLA" or type=="PYFILE"):
if (self.allWidgets[self.allDocuments[index].getDocname()].isTemplate() or self.allWidgets[self.allDocuments[index].getDocname()].isNew()):
self.fileMenuActions[5].setEnabled(False)
elif(type=="TEXT" ):
if(self.allWidgets[self.allDocuments[index].getDocname()].isNew()):
self.fileMenuActions[5].setEnabled(False)
elif(type=="IMAGE"):
self.fileMenuActions[5].setEnabled(False)
elif (type=="HELP"):
self.fileMenuActions[5].setEnabled(False)
self.fileMenuActions[6].setEnabled(False)
elif (type=="SETTABLE"):
self.fileMenuActions[5].setEnabled(False) #Option save
self.fileMenuActions[6].setEnabled(False) #Option save as
self.fileMenuActions[7].setEnabled(True) #Option save as votable
elif(type=="TABLE"):
self.fileMenuActions[7].setEnabled(True) #Option save as votable
elif (type=="VOTABLE"):
self.fileMenuActions[5].setEnabled(False)
self.fileMenuActions[6].setEnabled(False)
self.fileMenuActions[8].setEnabled(True) #Option save as ascii table
elif (type=="SESSION"):
self.fileMenuActions[6].setEnabled(False)
elif (type=="PYTEMP") or (type=="COLATEMP"):
self.fileMenuActions[5].setEnabled(False) #Option save
def documentsSelected(self, filename):
for index, doc in enumerate(self.allDocuments):
if doc.getDocname() == filename:
self.documents.setCurrentWidget(self.documents.widget(index))
return
def documentsDoubleClicked(self, fName, type, shortname):
methods={
"SET":self.openSet,
"TABLE": self.openTable,
"VOTABLE":self.openTable,
"SETTABLE":self.openSetTable,
"IMAGE":self.openImage,
"PYFILE":self.openPyfile,
"TEXT":self.openText,
"COLA":self.openCola,
"HELP":self.openHelp
}
if type=="COLATEMP" or type=="PYTEMP":
self.fileOpenTemplate(unicode(type), shortname, fName)
else:
fName=unicode(fName)
type=unicode(type)
shortname=unicode(shortname)
#If it is already open, it will be focused
indexOpen=self.isDocumentOpen(fName)
if indexOpen>=0:
self.documents.setCurrentWidget(self.allWidgets[fName])
else:
try:
output=methods[type](fName)
except IOError as e:
QMessageBox.warning(self, "Open File Failed", unicode(e))
return
except imageException as e:
QMessageBox.warning(self, "Open Image Failed", QString(e.msj))
return
except gipsyException as g:
QMessageBox.warning(self, "Open SET Failed", QString(g.msj))
return
except tableException as t:
QMessageBox.warning(self, "Format TABLE Failed", QString(unicode(t.msj)))
return
if type=="TABLE": #In this case the method opentable return the type TABLE or VOTABLE
if output=="": #The user has cancelled the operation
return
type=output
shortname=os.path.basename(fName)
#Maybe is a SETTABLE
shortname=shortname.split('*')
if len(shortname)==4:
shortname=shortname[2]
else:
shortname=shortname[0]
self.showDocument(fName, shortname, type )
if type=="SET":
#Adding the log to the wokflow
self.workflow.appendWorkflowText(output)
#Adding the set without parents to the session
self.session.setToSession(fName)
elif type !="SETTABLE":
#Adding the file to the session
self.session.docToSession(fName, type)
#Adding the file to recent opened
self.addRecentDocuments(fName, type)
#FILE NEW
def fileNewText(self):
c=self.cnt()
fName="Untitled"+unicode(c)
self.openText(fName)
#Adding the file to the session and to the workspaceBrowser
shortname=os.path.basename(fName)
#Adding the item to the workspacearea
self.workspaceBrowser.addFile("TEXT", fName , shortname)
#Adding the doc to the tab
self.showDocument(fName, shortname, "TEXT" )
def fileNewPyfile(self, templateName=None):
if(templateName != None):
fName=templateName
#Check if the script is opened yet
for index, doc in enumerate(self.allDocuments):
if doc.getDocname() == fName:
self.workspaceBrowser.selectFile(fName)
self.documents.setCurrentWidget(self.documents.widget(index))
return
else:
c=self.cnt()
fName="Untitled"+unicode(c)+".py"
while ( os.path.isfile(fName) and c < 100):
c=self.cnt()
fName="Untitled"+unicode(c)+".py"
self.openPyfile(fName,templateName)
#Adding the file to the session and to the workspaceBrowser
shortname=os.path.basename(fName)
#Adding the item to the workspacearea
self.workspaceBrowser.addFile("PYFILE", fName , shortname)
#Adding the doc to the tab
self.showDocument(fName, shortname, "PYFILE" )
def fileNewCola(self, templateName=None):
if(templateName != None):
fName=templateName
#Check if the template is opened yet
for index, doc in enumerate(self.allDocuments):
if doc.getDocname() == fName:
self.workspaceBrowser.selectFile(fName)
self.documents.setCurrentWidget(self.documents.widget(index))
return
else:
c=self.cnt()
fName="Untitled"+unicode(c)+".col"
while ( os.path.isfile(fName) and c < 100):
c=self.cnt()
fName="Untitled"+unicode(c)+".col"
self.openCola(fName,templateName )
#Adding the file to the session and to the workspaceBrowser
shortname=os.path.basename(fName)
#Adding the item to the workspacearea
self.workspaceBrowser.addFile("COLA", fName , shortname)
#Adding the doc to the tab
self.showDocument(fName, shortname, "COLA" )
def fileNewSession(self):
self.closeAll()
if(self.okToContinue()):
self.session.close()
c=self.cnt()
self.session=session(c)
self.workspaceBrowser.updateSessionTitle("Untitled Session")
self.workspaceBrowser.clearTree()
self.workflow.clearWorkflow()
def fileOpenSession(self, filename=None):
if filename!=None:
fName=filename
else:
dir = os.path.dirname(".")
fName = unicode(QFileDialog.getOpenFileName(self, "Session open ", dir,FORMATS["SESSION"]))
if (fName==""):
return
fName=unicode(fName)
#Check if there is a unsaved session
if (self.closeSession()):
try:
self.session.loadSession(fName)
except IOError as e:
QMessageBox.warning(self, "Open SESSION Failed", QString(unicode(e)))
return
except KeyError as k:
QMessageBox.warning(self, "Open SESSION Failed", "Format unrecognised\n"+QString(unicode(k)))
return
except sessionException as k:
QMessageBox.warning(self, "Open SESSION Failed",QString(unicode(k)))
return
#Show log in workflow
self.workflow.setWorkflowText(self.session.getWorkflowText())
#Put session name as title on workspacearea
self.workspaceBrowser.updateSessionTitle(os.path.basename(fName))
#Adding the file to recent opened
self.addRecentDocuments(fName, "SESSION")
#Topological sorted list of set
list=self.session.orderedListOfSet()
for child, father in list:
if father =="":
try:
log=self.setToWorkspace(child)
except gipsyException as g:
QMessageBox.warning(self, "Open SET Failed", QString(g.msj))
else:
try:
log=self.setToWorkspace(child, parent_name=father)
except gipsyException as g:
QMessageBox.warning(self, "Open SET Failed", QString(g.msj))
for type, list in self.session.docFiles.iteritems():
for fName in list:
shortname=os.path.basename(fName)
if os.path.exists(fName):
self.workspaceBrowser.addFile(type, fName , shortname)
else:
self.workspaceBrowser.addFile(type, fName , shortname, exist=False)
def fileOpenTemplate(self, type, templateName, templatePath):
methods={
"PYTEMP":self.openPyfile,
"COLATEMP":self.openCola
}
openIndex=self.isDocumentOpen(templatePath)
if openIndex>=0:
#The document is open
self.workspaceBrowser.selectFile(templatePath)
self.documents.setCurrentWidget(self.documents.widget(openIndex))
else:
try:
output=methods[type](fName=templatePath, templatePath=templatePath)
except IOError as e:
QMessageBox.warning(self, "Open Template Failed", unicode(e))
return
#Adding the item to the workspacearea
if not self.workspaceBrowser.hasFile(templatePath):
self.workspaceBrowser.addFile(type, templatePath, templateName)
#Adding the doc to the tab
self.showDocument(unicode(templatePath), unicode(templateName), type )
def fileOpenDocument(self, type, helpfile=None, filename=None):
methods={
"SET":self.openSet,
"TABLE": self.openTable,
"VOTABLE":self.openTable,
"IMAGE":self.openImage,
"PYFILE":self.openPyfile,
"TEXT":self.openText,
"COLA":self.openCola,
"HELP":self.openHelp
}
if helpfile !=None:
fName=helpfile
elif filename !=None:
fName=filename
else:
#dir = os.path.dirname(".")
dir=self.LASTPATH
fName = unicode(QFileDialog.getOpenFileName(self, "Choose %s File"%type, dir,FORMATS[type]))
if (fName==""):
return
fName=unicode(fName)
self.LASTPATH=os.path.dirname(fName)
if type=="SET":
(name,ext)=os.path.splitext(fName)
fName=name
# if len(fName)>79:
# QMessageBox.warning(self, "Setname too long", "Some GIPSY task as MNMX and WFITS do not support setname longer than 80, so please, select a setname with shorter path")
# return
openIndex=self.isDocumentOpen(fName)
if openIndex>=0:
#The document is open
self.workspaceBrowser.selectFile(fName)
self.documents.setCurrentWidget(self.documents.widget(openIndex))
else:
#The document is not open and it is not in the session
try: