-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflat_gui.py
More file actions
138 lines (113 loc) · 5.4 KB
/
flat_gui.py
File metadata and controls
138 lines (113 loc) · 5.4 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
#!/usr/bin/env python3
import datetime
from PyQtX.QtCore import Qt
from PyQtX.QtGui import QFont, QTextCursor
from PyQtX import QtCore, QtGui
from PyQtX.QtWidgets import (QMainWindow, QApplication, QAbstractItemView, QWidget, QLabel, QCheckBox, QTextEdit,
QLineEdit, QDialog, QTabWidget, QPushButton, QFileDialog, QGridLayout, QHBoxLayout,
QVBoxLayout, QTableWidget, QTableWidgetItem, QSlider, QCompleter, QFileDialog, QFrame,
QComboBox, QProgressBar, QHeaderView)
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import numpy
from base_window import BaseWindow
class FlatWindow(BaseWindow):
def __init__(self, parent):
super(FlatWindow, self).__init__()
self.parent = parent
self.setWindowTitle('Flat Log')
self.set_initial_geometry(self.parent.obs_window_geometry[0] + 1940, self.parent.obs_window_geometry[1]+810, 900, 500)
self.mkUI()
self.text = {k:"" for k in self.parent.local_cfg["toi"]["telescopes"]}
def updateUI(self):
if self.parent.telescope:
self.tel_e.setText(self.parent.active_tel)
self.tel_e.setAlignment(Qt.AlignCenter)
font = QFont("Courier New",9)
font.setBold(True)
self.tel_e.setFont(font)
self.tel_e.setStyleSheet(f"background-color: {self.parent.nats_cfg[self.parent.active_tel]['color']};")
self.info_e.clear()
self.info_e.append("date UT filter (n/n_dit) exp h_sun ADU")
for r in self.parent.flat_log:
n_exp = "--"
exp_no = "--"
if "n_exp" in r.keys() and "exp_no" in r.keys():
n_exp = r["n_exp"]
exp_no = r["exp_no"]
txt = r["timestamp_utc"].split()[0] + " " + r["timestamp_utc"].split()[1].split(".")[0]
txt = txt + f' {r["filter"]:8} ({n_exp}/{exp_no}) {r["exp_time"]:.2f} {r["h_sun"]} {r["mean"]}'
self.info_e.append(txt)
self.info_e.moveCursor(QTextCursor.End)
self.info_e.repaint()
self.show()
self.raise_()
def update_flat_overwatch(self,data):
self.flat_table_t.clearContents()
self.flat_table_t.setRowCount(0)
font = QtGui.QFont()
font.setPointSize(10)
t0 = datetime.datetime.now(datetime.timezone.utc)
for i,f in enumerate(data.keys()):
if self.flat_table_t.rowCount() <= i: self.flat_table_t.insertRow(i)
txt = f
txt = QTableWidgetItem(txt)
txt.setFont(font)
#txt.setBackground(QtGui.QColor(233, 233, 233))
self.flat_table_t.setItem(i, 0, txt)
if data[f]["last_flats"]:
t_filter = datetime.datetime.fromisoformat(data[f]["last_flats"])
t_filter = t_filter.replace(tzinfo=datetime.timezone.utc)
dt = t0 - t_filter
days = dt.days
hours = dt.seconds / 3600.
if float(days) == 0:
txt = f'{float(hours):.0f} hours'
else:
txt = f'{days} days'
else:
txt = "--"
txt = QTableWidgetItem(txt)
txt.setFont(font)
#txt.setBackground(QtGui.QColor(233, 233, 233))
self.flat_table_t.setItem(i, 1, txt)
if data[f]["last_obs"]:
t_obs = datetime.datetime.fromisoformat(data[f]["last_obs"])
t_obs = t_obs.replace(tzinfo=datetime.timezone.utc)
dt = t0 - t_obs
days = dt.days
hours = dt.seconds / 3600.
if float(days) == 0:
txt = f'{float(hours):.0f} hours'
else:
txt = f'{days} days'
else:
txt = "--"
txt = QTableWidgetItem(txt)
txt.setFont(font)
#txt.setBackground(QtGui.QColor(233, 233, 233))
self.flat_table_t.setItem(i, 2, txt)
#self.flat_table_t.scrollToBottom()
self.flat_table_t.resizeColumnsToContents()
for col in range(2,self.flat_table_t.columnCount()):
self.flat_table_t.horizontalHeader().setSectionResizeMode(col,QHeaderView.Stretch)
self.flat_table_t.repaint()
def mkUI(self):
grid = QGridLayout()
self.flat_table_t = QTableWidget(0,3)
self.flat_table_t.setHorizontalHeaderLabels(["FILTER", "LAST FLAT", "LAST OBJECT"])
self.flat_table_t.setSelectionMode(QAbstractItemView.NoSelection)
self.flat_table_t.verticalHeader().hide()
self.flat_table_t.setEditTriggers(QTableWidget.NoEditTriggers)
self.flat_table_t.setStyleSheet("selection-background-color: white;")
self.flat_table_t.verticalHeader().setDefaultSectionSize(10)
grid.addWidget(self.flat_table_t, 1, 0)
self.tel_e = QLineEdit()
self.tel_e.setReadOnly(True)
grid.addWidget(self.tel_e, 0, 0,1,2)
self.info_e = QTextEdit()
self.info_e.setReadOnly(True)
self.info_e.setStyleSheet("background-color: rgb(235,235,235);")
grid.addWidget(self.info_e, 1, 1)
self.setLayout(grid)