-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLTCTI_Window.py
More file actions
executable file
·403 lines (326 loc) · 16.7 KB
/
LTCTI_Window.py
File metadata and controls
executable file
·403 lines (326 loc) · 16.7 KB
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
#!/usr/bin/python
################################################################################
#
# Class LTCTI - CLass of attributes and functions that acquires associated
# parameters, makes necessary calculations and creates an entry
# for the Non-Load Event Tracker
#
################################################################################
import gtk
import os
class LTCTI:
# The Constructor
def __init__(self):
"""
This is the constructor for the LTCTI Window manager. Not a whole
lot happens here. We define the LTCTI RTS file names and the
default current folder that Contains the Tracking Files to be
written to.
NonLoadTrackedEventsHeader.txt is the official for-score file
TEST_NonLoadTrackedEvents.txt is a play pen file used for testing and What-if
runs
"""
# Widgets
self.DATE_entry = gtk.Entry(max=0)
self.start_date = ""
self.stop_date = ""
self.start_time = 0.0
self.stop_time = 0.0
self.default_current_folder = "/data/acis/LoadReviews/"
self.number_of_chips = 6
self.LTCTI_RTS_4 = '1_4_CTI'
self.LTCTI_RTS_5 = '1_5_CTI'
self.LTCTI_RTS_6 = '1_CTI06'
self.LTCTI_selected = self.LTCTI_RTS_6 # Default to 6 chips
self.LTCTI_duration = '000:01:00:00' # Default to one hour
self.cap_number = None
self.RE_base_command = '/proj/sot/ska/bin/python /data/acis/LoadReviews/script/NONLOADEVENTTRACKER/RecordNonLoadEvent.py LTCTI --source NLET '
#-----------------------------------------------------------------------
#
# LTCTIcallback - call back function when TEST, CANCEL or SCORE buttons
# are pressed
#
#-----------------------------------------------------------------------
def LTCTIcallback(self, widget, string):
"""
LTCTIcallback is the callback that is called when the user pushes either
the SCORE, CANCEL or TEST pushbottons at the bottom of the screen.
If CANCEL was pushed the callback exits immediately with no effects.
If either TEST or SCORE buttons were pushed, then the user-supplied data
is obtained from the GUI and a call is made to RecordNonLoadEvent.py which
writes an event entry in the specified Tracking File. If SCORE was
pressed then the event is written to the official NLT file:
NonLoadTrackedEventsHeader.txt
If TEST was selected then the user is prompted to select a destination
file via a File Chooser pop-up. An extra switch (-t) and the file path
is appended to the NLET command being built.
When all data has been collected the NLET command is complete. That
command issues a call to RecordNonLoadEvent.py which records the event
in the appropriate file.
When the SCORE, CANCEL or TEST button has been clicked, the LTCTI pop-up
is destroyed.
"""
# CAP execution start time
self.start_date = self.DATE_entry.get_text()
# CAP number
self.cap_number = self.CAP_Number_entry.get_text()
# Duration of the CAP if it ran to completion
self.LTCTI_duration = self.LTCTI_Duration_entry.get_text()
# Now get whatever the user put in the comment field if anything
user_comments_buffer = self.UserComment_entry.get_buffer()
tstart = user_comments_buffer.get_start_iter()
tend = user_comments_buffer.get_end_iter()
user_comment = user_comments_buffer.get_text(tstart, tend)
# CANCEL was pressed so do nothing and destroy the window destroy the window
if (string != "CANCEL"):
self.BuildLTCTIWindow.destroy()
# Either SCORE or TEST was pressed so process accordingly
# Set up the output file depending upon whether this is for score
# or just a test run
if (string == "SCORE"):
NLET_cmd = self.RE_base_command
else:
# STRING == TEST so this is for TEST PURPOSES and a test
# file will be written to a user-selected file
# Pop up a file chooser for the user so that they can select the file
# to write to
# Here are the file filters used with the filechoosers
TEST_NLET_file_filter=gtk.FileFilter()
TEST_NLET_file_filter.set_name(".txt files")
TEST_NLET_file_filter.add_pattern("*.txt")
all_filter=gtk.FileFilter()
all_filter.set_name("All files")
all_filter.add_pattern("*")
# Create the dialog but do not show it yet
self.TEST_NLET_FILESelectordialog = gtk.FileChooserDialog(title="Select the TXT File",
action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
# Capture the name of the file selected
# Set the default folder
self.TEST_NLET_FILESelectordialog.set_current_folder(self.default_current_folder)
self.TEST_NLET_FILESelectordialog.add_filter(TEST_NLET_file_filter)
self.TEST_NLET_FILESelectordialog.add_filter(all_filter)
# Run the dialog and get the response
response = self.TEST_NLET_FILESelectordialog.run()
if response == gtk.RESPONSE_OK:
# User specified a file; capture it's name
self.TEST_NLET_file_filespec = self.TEST_NLET_FILESelectordialog.get_filename()
elif response == gtk.RESPONSE_CANCEL:
print 'Cancel Clicked'
# Done with the file chooser - get rid of it
self.TEST_NLET_FILESelectordialog.destroy()
NLET_cmd = self.RE_base_command+" -t "+self.TEST_NLET_file_filespec
# Now form the rest of the RecordNonLoadEvent.py command using the
# data extracted from the GUI page
if (string == "SCORE") or (string == "TEST"):
# --------------- DATE ------------------------------------------
if self.start_date == "":
print "NO START TIME SPECIFIED!!!"
else:
# Concatenate the
NLET_cmd += " --event_time "+self.start_date+" "
# --------------- CAP NUMBER -----------------------------------
# Next append the CAP number. NOTE that it is a string at
# point and concatenate it to the command
NLET_cmd += " --cap_num "+self.cap_number+" "
# --------------- NUMBER OF CHIPS -------------------------------
# Determine which chip count radio button was selected and
# set the self.LTCTI_selected variable to the appropriate
# RTS file name
if self.radio_button_6.get_active():
self.LTCTI_selected = self.LTCTI_RTS_6
elif self.radio_button_5.get_active():
self.LTCTI_selected = self.LTCTI_RTS_5
else:
self.LTCTI_selected = self.LTCTI_RTS_4
# Now append the switch and the selected RTS file name to the RecordNonLoadEvent arg list
NLET_cmd += " --RTS_file "+self.LTCTI_selected+" "
# Now tack on the LTCTI duration
# Put the number of hours in the RTS FOT Request format of:
# DDD:HH:MM:SS
# Convert the hours to seconds
secs = float(self.LTCTI_duration)*3600.
# Obtain the minutes and seconds divmod
m,s = divmod(secs, 60)
# Now obtain the hours and minutes divmod
h, m = divmod(m, 60)
# And finally days and hours
days, h = divmod(h, 24)
# Now form the string in FOT Request format
duration = str(int(days)).zfill(3)+':'+str(int(h)).zfill(2)+":%02d:%02d" % ( m, s)
# And then tack it on to the end of the NLET command
NLET_cmd += " --LTCTI_duration "+duration+" "
# -------------- COMMENT -----------------------------------------
# Now append the comment the user made for this event
if user_comment == "":
print "USER SUPPLIED NO COMMENT"
user_comment = "No Comment"
NLET_cmd += '--desc "'+user_comment+'" '
# Now that you have the command line built - execute it
os.system(NLET_cmd)
# Done with the window so destroy it
self.BuildLTCTIWindow.destroy()
return False
def Pop_UP_LTCTI_Window(self):
"""
This method builds the LTCTI popup when the user has selected that
option from the Main Menu. Data that is necessary for an entry in
the NLET system is supplied by the user after the pop-up appears.
"""
# 1111 - Create the Basic window
self.BuildLTCTIWindow = gtk.Window(gtk.WINDOW_TOPLEVEL)
# set the title and size of the window.
self.BuildLTCTIWindow.set_title("Long Term CTI Run")
self.BuildLTCTIWindow.set_size_request(1000,700)
self.BuildLTCTIWindow.set_border_width(10)
# 2222 VBOX Create Vertical box to hold the toolbar and the plot
# The first row will hold the toolbar
# The second row item will contain the plotting area
self.LTCTI_VBox = gtk.VBox(False, 20)
# 3333 - Create a TABLE for textual entries and buttons
self.TextEntry_Table = gtk.Table(15,15, True)
start_row = 0
start_col = 0
# ------------------------------- DATE --------------------------------------
# 4444 - LABEL - DATE
row_len = 1
col_len = 5
self.DATE_label = gtk.Label("CAP Execution Date (2018:071:17:32:00): ")
self.TextEntry_Table.attach(self.DATE_label,
start_col, start_col + col_len,
start_row, start_row + row_len)
start_col += col_len
row_len = 1
col_len = 5
# 4444a - TEXT ENTRY - DATE
# self.DATE_entry = gtk.Entry(max=0)
self.DATE_entry.set_text("")
self.TextEntry_Table.attach(self.DATE_entry,
start_col, start_col + col_len,
start_row, start_row + row_len)
# -------------------------- CAP Number --------------------------------------
# 5555b - LABEL - CAP number
start_row += row_len
start_col = 1
row_len = 1
col_len = 2
self.CAPNumber_label = gtk.Label("CAP Number: ")
self.TextEntry_Table.attach(self.CAPNumber_label,
start_col, start_col + col_len,
start_row, start_row + row_len)
start_col += col_len
row_len = 1
col_len = 1
# 5555b - TEXT ENTRY - CAP Number Text Entry Field
self.CAP_Number_entry = gtk.Entry(max=0)
self.CAP_Number_entry.set_text("")
self.TextEntry_Table.attach(self.CAP_Number_entry,
start_col, start_col + col_len,
start_row, start_row + row_len)
# -------------------- NUMBER OF CHIPS -------------------------
# 5555c - LABEL -
start_row += row_len
start_col = 0
row_len = 1
col_len = 3
self.CLDFileName_label = gtk.Label("Select the number of chips: ")
self.TextEntry_Table.attach(self.CLDFileName_label,
start_col, start_col + col_len,
start_row, start_row + row_len)
start_col += col_len
row_len = 1
col_len = 2
# 5555c - RADIO BUTTON 6 CHIPS -
self.radio_button_6 = gtk.RadioButton(group=None, label='6 chips')
self.radio_button_6.set_active(True)
self.TextEntry_Table.attach(self.radio_button_6,
start_col, start_col + col_len,
start_row, start_row + row_len)
start_col += col_len
row_len = 1
col_len = 2
# 5555c - RADIO BUTTON 5 CHIPS -
self.radio_button_5 = gtk.RadioButton(group=self.radio_button_6, label='5 chips')
self.radio_button_5.set_active(False)
self.TextEntry_Table.attach(self.radio_button_5,
start_col, start_col + col_len,
start_row, start_row + row_len)
start_col += col_len
row_len = 1
col_len = 2
# 5555c - RADIO BUTTON 4 CHIPS -
self.radio_button_4 = gtk.RadioButton(group=self.radio_button_6, label='4 chips')
self.radio_button_4.set_active(False)
self.TextEntry_Table.attach(self.radio_button_4,
start_col, start_col + col_len,
start_row, start_row + row_len)
# 5555c - LTCTI CAP DURATION
start_row += row_len+1
start_col = 0
row_len = 1
col_len = 4
self.RTS_duration_label = gtk.Label("LTCTI Duration (WHOLE HOURS): ")
self.TextEntry_Table.attach(self.RTS_duration_label,
start_col, start_col + col_len,
start_row, start_row + row_len)
start_col =+ col_len
row_len = 1
col_len = 1
# 5555d - TEXT ENTRY - LTCTI DURATION
self.LTCTI_Duration_entry = gtk.Entry(max=0)
self.LTCTI_Duration_entry.set_text("")
self.TextEntry_Table.attach(self.LTCTI_Duration_entry,
start_col, start_col + col_len,
start_row, start_row + row_len)
# -------------------- USER COMMENT -------------------------
# 4444d - LABEL - User Comment Label
start_row += row_len+1
start_col = 0
row_len = 1
col_len = 3
self.CLDFileName_label = gtk.Label("User Comment: ")
self.TextEntry_Table.attach(self.CLDFileName_label,
start_col, start_col + col_len,
start_row, start_row + row_len)
start_col =+ col_len
row_len = 4
col_len = 9
# 4444d - TEXT ENTRY - User Comment Text Entry field
self.UserComment_entry = gtk.TextView()
self.TextEntry_Table.attach(self.UserComment_entry,
start_col, start_col+col_len,
start_row, start_row+1)
# -------------------- SCORE BUTTON -------------------------
start_row = 14
start_col = 0
# 4444c - BUTTON For Real SCORE button
self.SCOREbutton = gtk.Button("SCORE")
self.SCOREbutton.connect("clicked", self.LTCTIcallback, "SCORE")
self.TextEntry_Table.attach(self.SCOREbutton,
start_col, start_col + 2,
start_row, start_row + 1)
# -------------------- CANCEL BUTTON -------------------------
start_row = 14
start_col = 11
# 4444c - BUTTON CANCEL button
self.CANCELbutton = gtk.Button("CANCEL")
self.CANCELbutton.connect("clicked", self.LTCTIcallback, "CANCEL")
self.TextEntry_Table.attach(self.CANCELbutton,
start_col, start_col + 2,
start_row, start_row + 1)
# -------------------- TEST BUTTON -------------------------
start_row = 14
start_col = 13
# 4444c - BUTTON TEST button
self.TESTbutton = gtk.Button("TEST")
self.TESTbutton.connect("clicked", self.LTCTIcallback, "TEST")
self.TextEntry_Table.attach(self.TESTbutton,
start_col, start_col + 1,
start_row, start_row + 1)
# 2222 - Add the table to the VBOX
self.LTCTI_VBox.pack_start(self.TextEntry_Table)
# Add the VBox to the window box
self.BuildLTCTIWindow.add(self.LTCTI_VBox)
# 1111 - Done creating the BuildEVENTTRACKER Window. Show it.
self.BuildLTCTIWindow.show_all()