-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbeamline_setup.py
executable file
·144 lines (122 loc) · 5.45 KB
/
beamline_setup.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
#!/bin/env python3
# QT5 imports
from PyQt5 import QtWidgets, QtCore
# App imports
from base import APP_GUI, APP_Base
from base import login
class BL_MainWindow(APP_GUI, APP_Base):
def __init__(self, window, staffdetails, configuration_file):
"""
Beamline Setup Main Class
This the the main class that can be edited by the different beamlines and synchrotrons to overide upstream methods
"""
if configuration_file == "default":
config = "default"
else:
config = configuration_file
# APP_Base loads configuration and sets up logging
APP_Base.__init__(self, yaml_file=config)
# APP_GUI prepars QT5 GUI and populates list of available objects. Needs to know information about modules (from APP_base)
# So that that is knows what modules to load
APP_GUI.__init__(self, window)
# Auth
self.staffdetails = staffdetails
self.username = staffdetails["username"]
self.password = staffdetails["password"]
self.log.info(
f'Hello {self.staffdetails["first_name"]}, good to see you. Good luck with the setup'
)
self.log.info(
f"Ready to start BeamlineSetup quality control and checklist for {self.ID}"
)
self.add_update_widget_to_module_instances()
def delete_redis_update_UI(self):
self.delete_redis_key()
self.update_all_widgets()
def update_widget(self, task, status=2, value="current"):
"""
Widget types suppported. If you add more please fix me:
- DateEdit (DE)
- CheckBox (CB)
- Close APP (CLOSE)
- Do nothing (UNK)
the widgets are defined in the __init_ function for each module in the modules directory
e.g
ui.update_widget('InitialChecks',status=2) - CB full ticked
ui.update_widget('InitialChecks',status=1) - CB half ticked
ui.update_widget('InitialChecks',status=0) - CB unticked
"""
widget_type = self.MD[task].widget2update
if widget_type == "UNK":
self.log.debug(
"This module is configured not to update any widget. All done"
)
elif widget_type == "DE" or widget_type == "CB" or widget_type == "CLOSE":
self._update_widget_(task, status, widget_type)
if status == 0:
# Overwrite last run date stamp in redis
self.log.debug(
f"Overwriting datastamp for {task} of widget {widget_type}"
)
self.set(
f"{task}_{widget_type}_lastrun",
QtCore.QDateTime.fromSecsSinceEpoch(1553504400),
)
else:
self.log.debug(f"don't know this widget yet {widget_type} please extend me")
def add_update_widget_to_module_instances(self):
# THis will allow the different beamline setup modules to update the CB by accessing this function if they require.
for modu in self.MD:
self.MD[modu].update_widget = self.update_widget
self.log.debug(
f"setting module {modu} new function update_widget to {self.update_widget} #####"
)
self.MD[modu].password = self.password
self.MD[modu].username = self.username
def update_all_widgets(self):
for widget_type in ["DE", "CB"]:
# getattr will convert to self.DE or self.CB
for obj in getattr(self, widget_type):
lastrun = self.get(f"{obj}_{widget_type}_lastrun")
if not lastrun:
self.log.debug(
"redis hash key for storing time for last run is empty. Creating a new one"
)
self.set(
f"{obj}_{widget_type}_lastrun",
QtCore.QDateTime.fromSecsSinceEpoch(1553504400),
) # default to EPOC for when DGA started working at Diamond :$
lastrun = self.get(f"{obj}_{widget_type}_lastrun")
self.log.debug(
f"{obj}: Going to update {obj} for widget {widget_type} with new time"
)
# CB and DE Widgets have a criteria for how long before they need to be updated (see config yaml file)
if widget_type == "CB" or widget_type == "DE":
status = self.check_criteria4CBs(obj, widget_type, lastrun)
else:
status = -1
self._update_widget_(obj, status, widget_type, lastrun)
if __name__ == "__main__":
import sys
import os
username = os.environ.get("USER")
app = QtWidgets.QApplication(sys.argv)
auth = login.Login(username)
if auth.exec_() == QtWidgets.QDialog.Accepted:
MainWindow = QtWidgets.QFrame()
# ui = BL_MainWindow(MainWindow,auth.staffdetails,'default')
# print(auth.staffdetails)
ui = BL_MainWindow(MainWindow, auth.staffdetails, "configure_blsetup.yaml")
ui.username = auth.textName.text()
# ui.password = auth.textPass.text()
# print(ui.username)
# ui.setupUi(MainWindow)
# ui.prepare()
ui.MainWindow.show()
sys.exit(app.exec_())
# ui.log.info('Launchers with arguments')
# ui.log.info(f'{sys.argv}')
# from pprint import pprint
# pprint(ui.get_all())
# import code
# code.interact(local = locals())