-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsessionGUI.py
executable file
·4754 lines (3918 loc) · 195 KB
/
sessionGUI.py
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 python3
import os
import re
import sys
import copy
import math
import ephem
import argparse
from io import StringIO
from datetime import datetime, timedelta
from xml.etree import ElementTree
import conflict
import lsl
from lsl import astro
from lsl.common.dp import fS
from lsl.common import stations
from lsl.astro import deg_to_dms, deg_to_hms, MJD_OFFSET, DJD_OFFSET
from lsl.reader.tbn import FILTER_CODES as TBNFilters
from lsl.reader.drx import FILTER_CODES as DRXFilters
from lsl.common import sdf, sdfADP, sdfNDP
from lsl.misc import parser as aph
import wx
import wx.html as html
from wx.lib.scrolledpanel import ScrolledPanel
from wx.lib.mixins.listctrl import TextEditMixin, CheckListCtrlMixin
import matplotlib
matplotlib.use('WXAgg')
matplotlib.interactive(True)
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg, FigureCanvasWxAgg
from matplotlib.figure import Figure
from matplotlib.ticker import NullFormatter, NullLocator
__version__ = "0.6"
__author__ = "Jayce Dowell"
ALLOW_TBW_TBN_SAME_SDF = True
# Deal with the different wxPython versions
if 'phoenix' in wx.PlatformInfo:
AppendMenuItem = lambda x, y: x.Append(y)
AppendMenuMenu = lambda *args, **kwds: args[0].Append(*args[1:], **kwds)
InsertListItem = lambda *args, **kwds: args[0].InsertItem(*args[1:], **kwds)
SetListItem = lambda *args, **kwds: args[0].SetItem(*args[1:], **kwds)
SetDimensions = lambda *args, **kwds: args[0].SetSize(*args[1:], **kwds)
## This one is a little trickier
def AppendToolItem(*args, **kwds):
args = args+(kwds['bmpDisabled'] if 'bmpDisabled' in kwds else wx.NullBitmap,)
return args[0].AddTool(*args[1:],
kind=kwds['kind'] if 'kind' in kwds else wx.ITEM_NORMAL,
clientData=kwds['clientData'] if 'clientData' in kwds else None,
shortHelp=kwds['shortHelp'] if 'shortHelp' in kwds else '',
longHelp=kwds['longHelp'] if 'longHelp' in kwds else '')
else:
AppendMenuItem = lambda x, y: x.AppendItem(y)
AppendMenuMenu = lambda *args, **kwds: args[0].AppendMenu(*args[1:], **kwds)
InsertListItem = lambda *args, **kwds: args[0].InsertStringItem(*args[1:], **kwds)
SetListItem = lambda *args, **kwds: args[0].SetStringItem(*args[1:], **kwds)
SetDimensions = lambda *args, **kwds: args[0].SetDimensions(*args[1:], **kwds)
AppendToolItem = lambda *args, **kwds: args[0].AddLabelTool(*args[1:], **kwds)
def pid_print(*args, **kwds):
print(f"[{os.getpid()}]", *args, **kwds)
class ChoiceMixIn(wx.Control):
def __init__(self, options={}):
self.options = options
self.choices = {}
self.dropdown = None
self.make_choices()
self.Bind(wx.EVT_CHOICE, self.CloseDropdown)
def make_choices(self):
try:
self.dropdown.Destroy()
except AttributeError:
pass
for col in self.options.keys():
choice = wx.Choice(self, -1, choices=self.options[col])
font = self.GetFont()
choice.SetFont(font)
choice.Hide()
try:
self.choices[col].Destroy()
except KeyError:
pass
self.choices[col] = choice
self.choices[col].Bind(wx.EVT_KILL_FOCUS, self.CloseDropdown)
self.dropdown = None
self.active_row = -1
self.active_col = -1
def OpenDropdown(self, col, row):
# give the derived class a chance to Allow/Veto this edit.
event = wx.ListEvent(wx.wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, self.GetId())
event.m_itemIndex = row
event.m_col = col
item = self.GetItem(row, col)
if 'phoenix' in wx.PlatformInfo:
event_item = event.Item
else:
event_item = event.m_item
event_item.SetId(item.GetId())
event_item.SetColumn(item.GetColumn())
event_item.SetData(item.GetData())
event_item.SetText(item.GetText())
ret = self.GetEventHandler().ProcessEvent(event)
if ret and not event.IsAllowed():
return # user code doesn't allow the edit.
x0 = self.col_locs[col]
x1 = self.col_locs[col+1] - x0
scrolloffset = self.GetScrollPos(wx.HORIZONTAL)
# scroll forward
if x0+x1-scrolloffset > self.GetSize()[0]:
if wx.Platform == "__WXMSW__":
# don't start scrolling unless we really need to
offset = x0+x1-self.GetSize()[0]-scrolloffset
# scroll a bit more than what is minimum required
# so we don't have to scroll everytime the user presses TAB
# which is very tireing to the eye
addoffset = self.GetSize()[0]/4
# but be careful at the end of the list
if addoffset + scrolloffset < self.GetSize()[0]:
offset += addoffset
self.ScrollList(offset, 0)
scrolloffset = self.GetScrollPos(wx.HORIZONTAL)
else:
# Since we can not programmatically scroll the ListCtrl
# close the editor so the user can scroll and open the editor
# again
self.dropdown.SetValue(self.GetItem(row, col).GetText())
self.active_row = row
self.active_col = col
self.CloseDropdown()
return
y0 = self.GetItemRect(row)[1]
try:
self.dropdown = self.choices[col]
except KeyError:
return
SetDimensions(self.dropdown, x0-scrolloffset,y0, x1,-1)
idx = self.dropdown.FindString(self.GetItem(row, col).GetText())
self.dropdown.SetSelection(idx)
self.dropdown.Show()
self.dropdown.Raise()
#self.dropdown.SetSelection(-1,-1)
self.dropdown.SetFocus()
self.active_row = row
self.active_col = col
def CloseDropdown(self, event=None):
if self.dropdown is None:
return
text = self.dropdown.GetString(self.dropdown.GetSelection())
self.dropdown.Hide()
self.SetFocus()
# Event can be vetoed. It doesn't has SetEditCanceled(), what would
# require passing extra argument to CloseMenu()
event = wx.ListEvent(wx.wxEVT_COMMAND_LIST_END_LABEL_EDIT, self.GetId())
if 'phoenix' in wx.PlatformInfo:
event.Index = self.active_row
event.Column = self.active_col
item = wx.ListItem(self.GetItem(self.active_row, self.active_col))
item.SetText(text)
event.SetItem(item)
else:
event.m_itemIndex = self.active_row
event.m_col = self.active_col
item = self.GetItem(self.active_row, self.active_col)
event.m_item.SetId(item.GetId())
event.m_item.SetColumn(item.GetColumn())
event.m_item.SetData(item.GetData())
event.m_item.SetText(text) #should be empty string if editor was canceled
ret = self.GetEventHandler().ProcessEvent(event)
if not ret or event.IsAllowed():
if self.IsVirtual():
# replace by whather you use to populate the virtual ListCtrl
# data source
self.SetVirtualData(self.active_row, self.active_col, text)
else:
SetListItem(self, self.active_row, self.active_col, text)
self.RefreshItem(self.active_row)
class ObservationListCtrl(wx.ListCtrl, TextEditMixin, ChoiceMixIn, CheckListCtrlMixin):
"""
Class that combines an editable list with check boxes.
"""
def __init__(self, parent, **kwargs):
try:
adp = kwargs['adp']
del kwargs['adp']
except KeyError:
adp = False
try:
ndp = kwargs['ndp']
del kwargs['ndp']
except KeyError:
ndp = False
wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT, **kwargs)
TextEditMixin.__init__(self)
if ndp:
ChoiceMixIn.__init__(self, {10:['1','2','3','4','5','6','7'], 11:['No','Yes']})
elif adp:
ChoiceMixIn.__init__(self, {10:['1','2','3','4','5','6','7'], 11:['No','Yes']})
else:
ChoiceMixIn.__init__(self, {10:['1','2','3','4','5','6','7'], 11:['No','Yes']})
CheckListCtrlMixin.__init__(self)
self.nSelected = 0
self.parent = parent
def setCheckDependant(self, index=None):
"""
Update various menu entried and toolbar actions depending on what is selected.
"""
if self.nSelected == 0:
# Edit menu - disabled
try:
self.parent.editmenu['cut'].Enable(False)
self.parent.editmenu['copy'].Enable(False)
except (KeyError, AttributeError):
pass
# Stepped observation edits - disabled
try:
self.parent.obsmenu['steppedEdit'].Enable(False)
self.parent.toolbar.EnableTool(ID_EDIT_STEPPED, False)
except (KeyError, AttributeError):
pass
# Remove and resolve - disabled
self.parent.obsmenu['remove'].Enable(False)
self.parent.toolbar.EnableTool(ID_REMOVE, False)
self.parent.obsmenu['resolve'].Enable(False)
elif self.nSelected == 1:
# Edit menu - enabled
try:
self.parent.editmenu['cut'].Enable(True)
self.parent.editmenu['copy'].Enable(True)
except (KeyError, AttributeError):
pass
# Stepped observation edits - enbled if there is an index and it is STEPPED,
# disabled otherwise
if index is not None:
if self.parent.project.sessions[0].observations[index].mode == 'STEPPED':
try:
self.parent.obsmenu['steppedEdit'].Enable(True)
self.parent.toolbar.EnableTool(ID_EDIT_STEPPED, True)
except (KeyError, AttributeError):
pass
else:
try:
self.parent.obsmenu['steppedEdit'].Enable(False)
self.parent.toolbar.EnableTool(ID_EDIT_STEPPED, False)
except (KeyError, AttributeError):
pass
else:
# Stepped observation edits - disabled
try:
self.parent.obsmenu['steppedEdit'].Enable(False)
self.parent.toolbar.EnableTool(ID_EDIT_STEPPED, False)
except (KeyError, AttributeError):
pass
# Remove and resolve - enabled
self.parent.obsmenu['remove'].Enable(True)
self.parent.toolbar.EnableTool(ID_REMOVE, True)
self.parent.obsmenu['resolve'].Enable(True)
else:
# Edit menu - enabled
try:
self.parent.editmenu['cut'].Enable(True)
self.parent.editmenu['copy'].Enable(True)
except (KeyError, AttributeError):
pass
# Stepped observation edits - disabled
try:
self.parent.obsmenu['steppedEdit'].Enable(False)
self.parent.toolbar.EnableTool(ID_EDIT_STEPPED, False)
except (KeyError, AttributeError):
pass
# Remove and resolve - enabled and disabled, respectively
self.parent.obsmenu['remove'].Enable(True)
self.parent.toolbar.EnableTool(ID_REMOVE, True)
self.parent.obsmenu['resolve'].Enable(False)
def CheckItem(self, index, check=True):
"""
Catch for wxPython 4.1 which has a wx.ListCtrl.CheckItem() method
that interferes with CheckListCtrlMixin.CheckItem().
"""
CheckListCtrlMixin.CheckItem(self, index, check=check)
def OnCheckItem(self, index, flag):
"""
Overwrite the default OnCheckItem function so that we can control the enabling
and disabling of the STEPPED step editor button/menu item.
"""
if flag:
self.nSelected += 1
else:
self.nSelected -= 1
self.setCheckDependant(index=index)
CheckListCtrlMixin.OnCheckItem(self, index, flag)
def OpenEditor(self, col, row):
"""
Overwrite the default OpenEditor function so that select columns
are not actually editable.
"""
if col in [0,]:
pass
elif col in self.options.keys():
ChoiceMixIn.OpenDropdown(self, col, row)
elif self.parent.project.sessions[0].observations[row].mode == 'TBW' and col in [5, 6, 7]:
pass
elif self.parent.project.sessions[0].observations[row].mode in ['TRK_SOL', 'TRK_JOV', 'TRK_LUN'] and col in [6, 7]:
pass
elif self.parent.project.sessions[0].observations[row].mode == 'STEPPED' and col in [5, 6, 7, 8, 9, 11]:
pass
else:
TextEditMixin.OpenEditor(self, col, row)
class SteppedListCtrl(wx.ListCtrl, TextEditMixin, ChoiceMixIn, CheckListCtrlMixin):
"""
Class that combines an editable list with check boxes.
"""
def __init__(self, parent, **kwargs):
wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT, **kwargs)
TextEditMixin.__init__(self)
ChoiceMixIn.__init__(self, {6:['No','Yes']})
CheckListCtrlMixin.__init__(self)
self.nSelected = 0
self.parent = parent
def setCheckDependant(self, index=None):
"""
Update various menu entried and toolbar actions depending on what is selected.
"""
if self.nSelected == 0:
# Edit menu - disabled
try:
self.parent.editmenu['cut'].Enable(False)
self.parent.editmenu['copy'].Enable(False)
except (KeyError, AttributeError):
pass
elif self.nSelected == 1:
# Edit menu - enabled
try:
self.parent.editmenu['cut'].Enable(True)
self.parent.editmenu['copy'].Enable(True)
except (KeyError, AttributeError):
pass
else:
# Edit menu - enabled
try:
self.parent.editmenu['cut'].Enable(True)
self.parent.editmenu['copy'].Enable(True)
except (KeyError, AttributeError):
pass
def CheckItem(self, index, check=True):
"""
Catch for wxPython 4.1 which has a wx.ListCtrl.CheckItem() method
that interferes with CheckListCtrlMixin.CheckItem().
"""
CheckListCtrlMixin.CheckItem(self, index, check=check)
def OnCheckItem(self, index, flag):
"""
Overwrite the default OnCheckItem function so that we can control the enabling
and disabling of the STEPPED step editor button/menu item.
"""
if flag:
self.nSelected += 1
else:
self.nSelected -= 1
self.setCheckDependant(index=index)
CheckListCtrlMixin.OnCheckItem(self, index, flag)
def OpenEditor(self, col, row):
"""
Overwrite the default OpenEditor class so that select columns
are not actually editable.
"""
if col in [0,]:
pass
elif col in self.options.keys():
ChoiceMixIn.OpenDropdown(self, col, row)
else:
TextEditMixin.OpenEditor(self, col, row)
class PlotPanel(wx.Panel):
"""
The PlotPanel has a Figure and a Canvas. OnSize events simply set a
flag, and the actual resizing of the figure is triggered by an Idle event.
From: http://www.scipy.org/Matplotlib_figure_in_a_wx_panel
"""
def __init__(self, parent, color=None, dpi=None, **kwargs):
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure
# initialize Panel
if 'id' not in kwargs.keys():
kwargs['id'] = wx.ID_ANY
if 'style' not in kwargs.keys():
kwargs['style'] = wx.NO_FULL_REPAINT_ON_RESIZE
wx.Panel.__init__(self, parent, **kwargs)
self.parent = parent
# initialize matplotlib stuff
self.figure = Figure(None, dpi)
self.canvas = FigureCanvasWxAgg(self, -1, self.figure)
self.SetColor(color)
self._SetSize()
self.draw()
self._resizeflag = False
self.Bind(wx.EVT_IDLE, self._onIdle)
self.Bind(wx.EVT_SIZE, self._onSize)
def SetColor( self, rgbtuple=None ):
"""
Set figure and canvas colours to be the same.
"""
if rgbtuple is None:
rgbtuple = wx.SystemSettings.GetColour( wx.SYS_COLOUR_BTNFACE ).Get()
clr = [c/255. for c in rgbtuple]
self.figure.set_facecolor(clr)
self.figure.set_edgecolor(clr)
self.canvas.SetBackgroundColour(wx.Colour(*rgbtuple))
def _onSize(self, event):
self._resizeflag = True
def _onIdle(self, evt):
if self._resizeflag:
self._resizeflag = False
self._SetSize()
def _SetSize(self):
pixels = tuple(self.parent.GetClientSize())
self.SetSize(pixels)
self.canvas.SetSize(pixels)
self.figure.set_size_inches(float( pixels[0] )/self.figure.get_dpi(), float( pixels[1] )/self.figure.get_dpi())
def draw(self):
pass # abstract, to be overridden by child classes
ID_NEW = 11
ID_OPEN = 12
ID_SAVE = 13
ID_SAVE_AS = 14
ID_LOGGER = 15
ID_QUIT = 16
ID_INFO = 21
ID_SCHEDULE = 22
ID_ADD_TBW = 23
ID_ADD_TBF = 24
ID_ADD_TBN = 25
ID_ADD_DRX_RADEC = 26
ID_ADD_DRX_SOLAR = 27
ID_ADD_DRX_JOVIAN = 28
ID_ADD_DRX_LUNAR = 29
ID_ADD_STEPPED_RADEC = 30
ID_ADD_STEPPED_AZALT = 31
ID_EDIT_STEPPED = 32
ID_REMOVE = 33
ID_VALIDATE = 40
ID_TIMESERIES = 41
ID_RESOLVE = 42
ID_ADVANCED = 43
ID_DATA_VOLUME = 51
ID_HELP = 61
ID_FILTER_INFO = 62
ID_ABOUT = 63
ID_LISTCTRL = 71
ID_CUT = 81
ID_COPY = 82
ID_PASTE_BEFORE = 83
ID_PASTE_AFTER = 84
ID_PASTE_END = 85
class SDFCreator(wx.Frame):
def __init__(self, parent, title, args):
wx.Frame.__init__(self, parent, title=title, size=(750,500))
self.station = stations.lwa1
self.sdf = sdf
self.adp = False
self.ndp = False
if args.lwasv:
self.station = stations.lwasv
self.sdf = sdfADP
self.adp = True
if args.lwana:
self.station = stations.lwana
self.sdf = sdfNDP
self.ndp = True
self.scriptPath = os.path.abspath(__file__)
self.scriptPath = os.path.split(self.scriptPath)[0]
self.dirname = ''
self.toolbar = None
self.statusbar = None
self.savemenu = None
self.editmenu = {}
self.obsmenu = {}
self.buffer = None
self.initSDF()
self.initUI()
self.initEvents()
self.Show()
self.sdf._DRSUCapacityTB = args.drsu_size
#self.logger = None
#self.onLogger(None)
if args.filename is not None:
self.filename = args.filename
self.parseFile(self.filename)
if self.mode == 'TBW' and not ALLOW_TBW_TBN_SAME_SDF:
self.finfo.Enable(False)
else:
self.finfo.Enable(True)
else:
self.filename = ''
self.setMenuButtons('None')
self.edited = False
self.setSaveButton()
def initSDF(self):
"""
Create an empty sdf.project instance to store all of the actual
observations.
"""
po = self.sdf.ProjectOffice()
observer = self.sdf.Observer('', 0, first='', last='')
project = self.sdf.Project(observer, '', '', project_office=po)
session = self.sdf.Session('session_name', 0, observations=[])
project.sessions = [session,]
self.project = project
self.mode = ''
self.project.sessions[0].tbwBits = 12
self.project.sessions[0].tbwSamples = 12000000
self.project.sessions[0].tbfSamples = 12000000
self.project.sessions[0].tbnGain = -1
self.project.sessions[0].drxGain = -1
def initUI(self):
"""
Start the user interface.
"""
menubar = wx.MenuBar()
fileMenu = wx.Menu()
editMenu = wx.Menu()
obsMenu = wx.Menu()
dataMenu = wx.Menu()
helpMenu = wx.Menu()
# File menu items
new = wx.MenuItem(fileMenu, ID_NEW, '&New')
AppendMenuItem(fileMenu, new)
open = wx.MenuItem(fileMenu, ID_OPEN, '&Open')
AppendMenuItem(fileMenu, open)
save = wx.MenuItem(fileMenu, ID_SAVE, '&Save')
AppendMenuItem(fileMenu, save)
saveas = wx.MenuItem(fileMenu, ID_SAVE_AS, 'S&ave As')
AppendMenuItem(fileMenu, saveas)
fileMenu.AppendSeparator()
#logger = wx.MenuItem(fileMenu, ID_LOGGER, '&Logger')
#AppendMenuItem(fileMenu, logger)
#fileMenu.AppendSeparator()
quit = wx.MenuItem(fileMenu, ID_QUIT, '&Quit')
AppendMenuItem(fileMenu, quit)
# Save the 'save' menu item
self.savemenu = save
# Edit menu items
cut = wx.MenuItem(editMenu, ID_CUT, 'C&ut Selected Observation')
AppendMenuItem(editMenu, cut)
cpy = wx.MenuItem(editMenu, ID_COPY, '&Copy Selected Observation')
AppendMenuItem(editMenu, cpy)
pstb = wx.MenuItem(editMenu, ID_PASTE_BEFORE, '&Paste Before Selected')
AppendMenuItem(editMenu, pstb)
psta = wx.MenuItem(editMenu, ID_PASTE_AFTER, '&Paste After Selected')
AppendMenuItem(editMenu, psta)
pste = wx.MenuItem(editMenu, ID_PASTE_END, '&Paste at End of List')
AppendMenuItem(editMenu, pste)
# Save menu items and disable all of them
self.editmenu['cut'] = cut
self.editmenu['copy'] = cpy
self.editmenu['pasteBefore'] = pstb
self.editmenu['pasteAfter'] = psta
self.editmenu['pasteEnd'] = pste
for k in self.editmenu.keys():
self.editmenu[k].Enable(False)
# Observer menu items
info = wx.MenuItem(obsMenu, ID_INFO, 'Observer/&Project Info.')
AppendMenuItem(obsMenu, info)
sch = wx.MenuItem(obsMenu, ID_SCHEDULE, 'Sc&heduling')
AppendMenuItem(obsMenu, sch)
obsMenu.AppendSeparator()
add = wx.Menu()
addTBW = wx.MenuItem(add, ID_ADD_TBW, 'TB&W')
AppendMenuItem(add, addTBW)
addTBF = wx.MenuItem(add, ID_ADD_TBF, 'TB&F')
AppendMenuItem(add, addTBF)
addTBN = wx.MenuItem(add, ID_ADD_TBN, 'TB&N')
AppendMenuItem(add, addTBN)
add.AppendSeparator()
addDRXR = wx.MenuItem(add, ID_ADD_DRX_RADEC, 'DRX - &RA/Dec')
AppendMenuItem(add, addDRXR)
addDRXS = wx.MenuItem(add, ID_ADD_DRX_SOLAR, 'DRX - &Solar')
AppendMenuItem(add, addDRXS)
addDRXJ = wx.MenuItem(add, ID_ADD_DRX_JOVIAN, 'DRX - &Jovian')
AppendMenuItem(add, addDRXJ)
addDRXL = wx.MenuItem(add, ID_ADD_DRX_LUNAR, 'DRX - &Lunar')
AppendMenuItem(add, addDRXL)
addSteppedRADec = wx.MenuItem(add, ID_ADD_STEPPED_RADEC, 'DRX - Ste&pped - RA/Dec')
AppendMenuItem(add, addSteppedRADec)
addSteppedAzAlt = wx.MenuItem(add, ID_ADD_STEPPED_AZALT, 'DRX - Ste&pped - Az/Alt')
AppendMenuItem(add, addSteppedAzAlt)
editStepped = wx.MenuItem(add, ID_EDIT_STEPPED, 'DRX - Edit Selected Stepped Obs.')
AppendMenuItem(add, editStepped)
AppendMenuMenu(obsMenu, -1, '&Add', add)
remove = wx.MenuItem(obsMenu, ID_REMOVE, '&Remove Selected')
AppendMenuItem(obsMenu, remove)
validate = wx.MenuItem(obsMenu, ID_VALIDATE, '&Validate All\tF5')
AppendMenuItem(obsMenu, validate)
obsMenu.AppendSeparator()
resolve = wx.MenuItem(obsMenu, ID_RESOLVE, 'Resolve Selected\tF3')
AppendMenuItem(obsMenu, resolve)
timeseries = wx.MenuItem(obsMenu, ID_TIMESERIES, 'Session at a &Glance')
AppendMenuItem(obsMenu, timeseries)
advanced = wx.MenuItem(obsMenu, ID_ADVANCED, 'Advanced &Settings')
AppendMenuItem(obsMenu, advanced)
# Save menu items
self.obsmenu['tbw'] = addTBW
self.obsmenu['tbf'] = addTBF
self.obsmenu['tbn'] = addTBN
self.obsmenu['drx-radec'] = addDRXR
self.obsmenu['drx-solar'] = addDRXS
self.obsmenu['drx-jovian'] = addDRXJ
self.obsmenu['drx-lunar'] = addDRXL
self.obsmenu['steppedRADec'] = addSteppedRADec
self.obsmenu['steppedAzAlt'] = addSteppedAzAlt
self.obsmenu['steppedEdit'] = editStepped
self.obsmenu['remove'] = remove
self.obsmenu['resolve'] = resolve
for k in ('remove', 'resolve'):
self.obsmenu[k].Enable(False)
# Data menu items
volume = wx.MenuItem(obsMenu, ID_DATA_VOLUME, '&Estimated Data Volume')
AppendMenuItem(dataMenu, volume)
# Help menu items
help = wx.MenuItem(helpMenu, ID_HELP, 'Session GUI Handbook\tF1')
AppendMenuItem(helpMenu, help)
self.finfo = wx.MenuItem(helpMenu, ID_FILTER_INFO, '&Filter Codes')
AppendMenuItem(helpMenu, self.finfo)
helpMenu.AppendSeparator()
about = wx.MenuItem(helpMenu, ID_ABOUT, '&About')
AppendMenuItem(helpMenu, about)
menubar.Append(fileMenu, '&File')
menubar.Append(editMenu, '&Edit')
menubar.Append(obsMenu, '&Observations')
menubar.Append(dataMenu, '&Data')
menubar.Append(helpMenu, '&Help')
self.SetMenuBar(menubar)
# Toolbar
self.toolbar = self.CreateToolBar()
AppendToolItem(self.toolbar, ID_NEW, '', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'new.png')), shortHelp='New',
longHelp='Clear the existing setup and start a new project/session')
AppendToolItem(self.toolbar, ID_OPEN, '', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'open.png')), shortHelp='Open',
longHelp='Open and load an existing SD file')
AppendToolItem(self.toolbar, ID_SAVE, '', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'save.png')), shortHelp='Save',
longHelp='Save the current setup')
AppendToolItem(self.toolbar, ID_SAVE_AS, '', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'save-as.png')), shortHelp='Save as',
longHelp='Save the current setup to a new SD file')
AppendToolItem(self.toolbar, ID_QUIT, '', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'exit.png')), shortHelp='Quit',
longHelp='Quit (without saving)')
self.toolbar.AddSeparator()
AppendToolItem(self.toolbar, ID_ADD_TBW, 'tbw', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'tbw.png')), shortHelp='Add TBW',
longHelp='Add a new all-sky TBW observation to the list')
AppendToolItem(self.toolbar, ID_ADD_TBF, 'tbf', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'tbf.png')), shortHelp='Add TBF',
longHelp='Add a new all-sky TBF observation to the list')
AppendToolItem(self.toolbar, ID_ADD_TBN, 'tbn', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'tbn.png')), shortHelp='Add TBN',
longHelp='Add a new all-sky TBN observation to the list')
AppendToolItem(self.toolbar, ID_ADD_DRX_RADEC, 'drx-radec', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'drx-radec.png')), shortHelp='Add DRX - RA/Dec',
longHelp='Add a new beam forming DRX observation that tracks the sky (ra/dec)')
AppendToolItem(self.toolbar, ID_ADD_DRX_SOLAR, 'drx-solar', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'drx-solar.png')), shortHelp='Add DRX - Solar',
longHelp='Add a new beam forming DRX observation that tracks the Sun')
AppendToolItem(self.toolbar, ID_ADD_DRX_JOVIAN, 'drx-jovian', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'drx-jovian.png')), shortHelp='Add DRX - Jovian',
longHelp='Add a new beam forming DRX observation that tracks Jupiter')
AppendToolItem(self.toolbar, ID_ADD_DRX_LUNAR, 'drx-lunar', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'drx-lunar.png')), shortHelp='Add DRX - Lunar',
longHelp='Add a new beam forming DRX observation that tracks the Moon')
AppendToolItem(self.toolbar, ID_ADD_STEPPED_RADEC, 'stepped', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'stepped-radec.png')), shortHelp='Add DRX - Stepped - RA/Dec',
longHelp='Add a new beam forming DRX observation with custom RA/Dec position and frequency stepping')
AppendToolItem(self.toolbar, ID_ADD_STEPPED_AZALT, 'stepped', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'stepped-azalt.png')), shortHelp='Add DRX - Stepped - Az/Alt',
longHelp='Add a new beam forming DRX observation with custom az/alt position and frequency stepping')
AppendToolItem(self.toolbar, ID_EDIT_STEPPED, 'step', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'stepped-edit.png')), shortHelp='Edit Selected Stepped Observation',
longHelp='Add and edit steps for the currently selected stepped observation')
AppendToolItem(self.toolbar, ID_REMOVE, '', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'remove.png')), shortHelp='Remove Selected',
longHelp='Remove the selected observations from the list')
AppendToolItem(self.toolbar, ID_VALIDATE, '', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'validate.png')), shortHelp='Validate Observations',
longHelp='Validate the current set of parameters and observations')
self.toolbar.AddSeparator()
AppendToolItem(self.toolbar, ID_HELP, '', wx.Bitmap(os.path.join(self.scriptPath, 'icons', 'help.png')), shortHelp='Help',
longHelp='Display a brief help message for this program')
self.toolbar.Realize()
# Disable "remove" in the toolbar
self.toolbar.EnableTool(ID_REMOVE, False)
# Status bar
self.statusbar = self.CreateStatusBar()
# Observation list
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.panel = ScrolledPanel(self, -1)
self.listControl = ObservationListCtrl(self.panel, id=ID_LISTCTRL, adp=self.adp, ndp=self.ndp)
self.listControl.parent = self
hbox.Add(self.listControl, 1, wx.EXPAND)
self.panel.SetSizer(hbox)
def initEvents(self):
"""
Set all of the various events in the main window.
"""
# File menu events
self.Bind(wx.EVT_MENU, self.onNew, id=ID_NEW)
self.Bind(wx.EVT_MENU, self.onLoad, id=ID_OPEN)
self.Bind(wx.EVT_MENU, self.onSave, id=ID_SAVE)
self.Bind(wx.EVT_MENU, self.onSaveAs, id=ID_SAVE_AS)
#self.Bind(wx.EVT_MENU, self.onLogger, id=ID_LOGGER)
self.Bind(wx.EVT_MENU, self.onQuit, id=ID_QUIT)
# Edit menu events
self.Bind(wx.EVT_MENU, self.onCut, id=ID_CUT)
self.Bind(wx.EVT_MENU, self.onCopy, id=ID_COPY)
self.Bind(wx.EVT_MENU, self.onPasteBefore, id=ID_PASTE_BEFORE)
self.Bind(wx.EVT_MENU, self.onPasteAfter, id=ID_PASTE_AFTER)
self.Bind(wx.EVT_MENU, self.onPasteEnd, id=ID_PASTE_END)
# Observer menu events
self.Bind(wx.EVT_MENU, self.onInfo, id=ID_INFO)
self.Bind(wx.EVT_MENU, self.onSchedule, id=ID_SCHEDULE)
self.Bind(wx.EVT_MENU, self.onAddTBW, id=ID_ADD_TBW)
self.Bind(wx.EVT_MENU, self.onAddTBF, id=ID_ADD_TBF)
self.Bind(wx.EVT_MENU, self.onAddTBN, id=ID_ADD_TBN)
self.Bind(wx.EVT_MENU, self.onAddDRXR, id=ID_ADD_DRX_RADEC)
self.Bind(wx.EVT_MENU, self.onAddDRXS, id=ID_ADD_DRX_SOLAR)
self.Bind(wx.EVT_MENU, self.onAddDRXJ, id=ID_ADD_DRX_JOVIAN)
self.Bind(wx.EVT_MENU, self.onAddDRXL, id=ID_ADD_DRX_LUNAR)
self.Bind(wx.EVT_MENU, self.onAddSteppedRADec, id=ID_ADD_STEPPED_RADEC)
self.Bind(wx.EVT_MENU, self.onAddSteppedAzAlt, id=ID_ADD_STEPPED_AZALT)
self.Bind(wx.EVT_MENU, self.onEditStepped, id=ID_EDIT_STEPPED)
self.Bind(wx.EVT_MENU, self.onRemove, id=ID_REMOVE)
self.Bind(wx.EVT_MENU, self.onValidate, id=ID_VALIDATE)
self.Bind(wx.EVT_MENU, self.onResolve, id=ID_RESOLVE)
self.Bind(wx.EVT_MENU, self.onTimeseries, id=ID_TIMESERIES)
self.Bind(wx.EVT_MENU, self.onAdvanced, id=ID_ADVANCED)
# Data menu events
self.Bind(wx.EVT_MENU, self.onVolume, id=ID_DATA_VOLUME)
# Help menu events
self.Bind(wx.EVT_MENU, self.onHelp, id=ID_HELP)
self.Bind(wx.EVT_MENU, self.onFilterInfo, id=ID_FILTER_INFO)
self.Bind(wx.EVT_MENU, self.onAbout, id=ID_ABOUT)
# Observation edits
self.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.onEdit, id=ID_LISTCTRL)
# Window manager close
self.Bind(wx.EVT_CLOSE, self.onQuit)
#def onLogger(self, event):
# """
# Create a new logger window, if needed
# """
#
# if self.logger is None:
# self.logger = wx.LogWindow(self, 'SDF Logger', True, False)
# elif not self.logger.Frame.IsShown():
# self.logger.Destroy()
# self.logger = wx.LogWindow(self, 'SDF Logger', True, False)
def onNew(self, event):
"""
Create a new SD session.
"""
if self.edited:
dialog = wx.MessageDialog(self, 'The current session defintion file has changes that have not been saved.\n\nStart a new session anyways?', 'Confirm New', style=wx.YES_NO|wx.NO_DEFAULT|wx.ICON_QUESTION)
if dialog.ShowModal() == wx.ID_YES:
pass
else:
return False
self.filename = ''
self.edited = True
self.badEdit = False
self.setSaveButton()
self.setMenuButtons('None')
self.listControl.DeleteAllItems()
self.listControl.DeleteAllColumns()
self.listControl.nSelected = 0
self.listControl.setCheckDependant()
self.initSDF()
ObserverInfo(self)
if self.mode == 'TBW' and not ALLOW_TBW_TBN_SAME_SDF:
self.finfo.Enable(False)
else:
self.finfo.Enable(True)
def onLoad(self, event):
"""
Load an existing SD file.
"""
if self.edited:
dialog = wx.MessageDialog(self, 'The current session defintion file has changes that have not been saved.\n\nOpen a new file anyways?', 'Confirm Open', style=wx.YES_NO|wx.NO_DEFAULT|wx.ICON_QUESTION)
if dialog.ShowModal() == wx.ID_YES:
pass
else:
return False
dialog = wx.FileDialog(self, "Select a SD File", self.dirname, '', 'SDF Files (*.sdf,*.txt)|*.sdf;*.txt|All Files|*', wx.FD_OPEN)
if dialog.ShowModal() == wx.ID_OK:
self.dirname = dialog.GetDirectory()
self.filename = dialog.GetPath()
self.parseFile(dialog.GetPath())
self.edited = False
self.setSaveButton()
dialog.Destroy()
if self.mode == 'TBW':
self.finfo.Enable(False)
else:
self.finfo.Enable(True)
def onSave(self, event):
"""
Save the current observation to a file.
"""
if self.filename == '':
self.onSaveAs(event)
else:
if not self.onValidate(1, confirmValid=False):
self.displayError('The session definition file could not be saved due to errors in the file. See the command standard output for details.', title='Save Failed')
else:
try:
with open(self.filename, 'w') as fh:
fh.write(self.project.render())
self.edited = False
self.setSaveButton()
except IOError as err:
self.displayError(f"Error saving to '{self.filename}'", details=err, title='Save Error')
def onSaveAs(self, event):
"""
Save the current observation to a new SD file.
"""
if not self.onValidate(1, confirmValid=False):
self.displayError('The session definition file could not be saved due to errors in the file. See the command standard output for details.', title='Save Failed')
else:
dialog = wx.FileDialog(self, "Select Output File", self.dirname, '', 'SDF Files (*.sdf,*.txt)|*.sdf;*.txt|All Files|*', wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
if dialog.ShowModal() == wx.ID_OK:
self.dirname = dialog.GetDirectory()
self.filename = dialog.GetPath()
try:
with open(self.filename, 'w') as fh:
fh.write(self.project.render())
self.edited = False
self.setSaveButton()
except IOError as err:
self.displayError(f"Error saving to '{self.filename}'", details=err, title='Save Error')
dialog.Destroy()
def onCopy(self, event):
"""
Copy the selected observation(s) to the buffer.
"""
self.buffer = []
for i in range(self.listControl.GetItemCount()):
if self.listControl.IsChecked(i):
self.buffer.append( copy.deepcopy(self.project.sessions[0].observations[i]) )
self.editmenu['pasteBefore'].Enable(True)
self.editmenu['pasteAfter'].Enable(True)
self.editmenu['pasteEnd'].Enable(True)
def onCut(self, event):
self.onCopy(event)
self.onRemove(event)
def onPasteBefore(self, event):
firstChecked = None
for i in range(self.listControl.GetItemCount()):
if self.listControl.IsChecked(i):
firstChecked = i