mainly in src/gui.py
This commit is contained in:
176
src/gui.py
176
src/gui.py
@@ -43,6 +43,8 @@ class AppGui(QWidget):
|
||||
self.parent = parent
|
||||
self.cafe = self.parent.cafe
|
||||
self.cyca = self.parent.cyca
|
||||
|
||||
self.send_to_log_window = self.parent.send_to_log_window
|
||||
self.gui_frame = self.parent.gui_frame
|
||||
self.gui_header = self.parent.gui_header
|
||||
self.font_gui = self.parent.gui_frame.font_gui
|
||||
@@ -71,14 +73,21 @@ class AppGui(QWidget):
|
||||
|
||||
self.I_min = 1.0
|
||||
|
||||
sec_state_list = ['SEC-IP2:STATE','SEC-IW2:STATE','SEC-PK1:STATE','SEC-PK2:STATE',
|
||||
'SEC-SINQ:STATE','SEC-UCN:STATE']
|
||||
#sec_state_list = ['SEC-IP2:STATE','SEC-IW2:STATE','SEC-PK1:STATE',
|
||||
# 'SEC-PK2:STATE','SEC-SINQ:STATE','SEC-UCN:STATE']
|
||||
|
||||
sec_state_list = ['ZIP2-HUSH:STATE', 'ZIW2-HUSH:STATE',
|
||||
'ZPK1-HUSH:STATE', 'ZPK2-HUSH:STATE',
|
||||
'ZSINQ-HUSH:STATE', 'ZUCN-HUSH:STATE']
|
||||
|
||||
self.cafe.openPrepare()
|
||||
self.cafe.open(['HUSH:LASTPWR','HUSH:TOTPWR','HUSH:LASTSAVE','HUSH:TOTSAVE'])
|
||||
self.cafe.open(['ZHIPA-HUSH:LASTPWR','ZHIPA-HUSH:TOTPWR',
|
||||
'ZHIPA-HUSH:LASTSAVE', 'ZHIPA-HUSH:TOTSAVE'])
|
||||
self.cafe.open(sec_state_list)
|
||||
self.cafe.open("UCN:BEAMREQ:STATUS")
|
||||
self.cafe.openNowAndWait(0.1)
|
||||
|
||||
self.cafe.monitor("UCNQ:BEAMREQ:STATUS")
|
||||
|
||||
wgt = self.group_sector_qtabwidget()
|
||||
self.gui_frame.measurement_layout.addWidget(
|
||||
@@ -107,11 +116,44 @@ class AppGui(QWidget):
|
||||
pk1_line = ["IW2"]
|
||||
pk2_line = ["IW2"]
|
||||
|
||||
def enable_disable_end(sector, sector_line, value):
|
||||
self.sectorI_dict[sector] = value
|
||||
def enable_disable_ucn(sect, sector_line, value):
|
||||
self.sectorI_dict[sect] = value
|
||||
|
||||
beam_req_running = True
|
||||
beam_req_status = self.cafe.getCache("UCNQ:BEAMREQ:STATUS")
|
||||
#print(" beam_req_status", beam_req_status, flush=True)
|
||||
|
||||
if beam_req_status is not None:
|
||||
if beam_req_status == "stopped":
|
||||
beam_req_running = False
|
||||
|
||||
|
||||
for sector in sector_line:
|
||||
if self.sectorI_dict['UCN'] > self.I_min or self.sectorI_dict[
|
||||
'SINQ'] > self.I_min:
|
||||
beam_req_flag = True
|
||||
if sector == 'UCN':
|
||||
beam_req_flag = beam_req_running
|
||||
|
||||
#if self.sectorI_dict['UCN'] > self.I_min or self.sectorI_dict[
|
||||
# 'SINQ'] > self.I_min:
|
||||
if self.sectorI_dict[sector] > self.I_min or beam_req_flag:
|
||||
if self.table_sol_dict[
|
||||
sector].standby_value_button.isEnabled():
|
||||
self.table_sol_dict[
|
||||
sector].standby_value_button.setEnabled(False)
|
||||
|
||||
else:
|
||||
if not self.table_sol_dict[
|
||||
sector].standby_value_button.isEnabled():
|
||||
self.table_sol_dict[
|
||||
sector].standby_value_button.setEnabled(True)
|
||||
|
||||
|
||||
def enable_disable_end(sect, sector_line, value):
|
||||
self.sectorI_dict[sect] = value
|
||||
for sector in sector_line:
|
||||
#if self.sectorI_dict['UCN'] > self.I_min or self.sectorI_dict[
|
||||
# 'SINQ'] > self.I_min:
|
||||
if self.sectorI_dict[sector] > self.I_min:
|
||||
if self.table_sol_dict[
|
||||
sector].standby_value_button.isEnabled():
|
||||
self.table_sol_dict[
|
||||
@@ -121,9 +163,10 @@ class AppGui(QWidget):
|
||||
sector].standby_value_button.isEnabled():
|
||||
self.table_sol_dict[
|
||||
sector].standby_value_button.setEnabled(True)
|
||||
|
||||
|
||||
def enable_disable_pk(sector, sector_line, value):
|
||||
self.sectorI_dict[sector] = value
|
||||
def enable_disable_pk(sect, sector_line, value):
|
||||
self.sectorI_dict[sect] = value
|
||||
for sector in sector_line:
|
||||
if self.sectorI_dict['PK1'] > self.I_min or self.sectorI_dict[
|
||||
'PK2'] > self.I_min:
|
||||
@@ -136,10 +179,11 @@ class AppGui(QWidget):
|
||||
sector].standby_value_button.isEnabled():
|
||||
self.table_sol_dict[
|
||||
sector].standby_value_button.setEnabled(True)
|
||||
|
||||
|
||||
|
||||
def receive_ucn_update(value, status, alarm_severity):
|
||||
enable_disable_end('UCN', ucn_line, value)
|
||||
enable_disable_ucn('UCN', ucn_line, value)
|
||||
def receive_sinq_update(value, status, alarm_severity):
|
||||
enable_disable_end('SINQ', sinq_line, value)
|
||||
def receive_pk1_update(value, status, alarm_severity):
|
||||
@@ -160,8 +204,12 @@ class AppGui(QWidget):
|
||||
def receive_sec_state(handle, pv, pvdata):
|
||||
#print(pv)
|
||||
#pvdata.show()
|
||||
pvsplit = pv.split(":")
|
||||
secsplit = pvsplit[0].split("SEC-")
|
||||
#pvsplit = pv.split(":")
|
||||
#secsplit = pvsplit[0].split("SEC-")
|
||||
#sec = secsplit[1]
|
||||
#now ZIP2-HUSH
|
||||
pvsplit = pv.split("-")
|
||||
secsplit = pvsplit[0].split("Z")
|
||||
sec = secsplit[1]
|
||||
if pvdata.value[0] == 'ON':
|
||||
#print("sec-ON", secsplit[1], flush=True)
|
||||
@@ -245,16 +293,16 @@ class AppGui(QWidget):
|
||||
qtot.setFont(fnt)
|
||||
qgrid.addWidget(qtot, _row+1, 0, 1, 1)
|
||||
qgrid.addWidget(
|
||||
CAQLineEdit(self, pv_name="HUSH:LASTPWR", show_units=True),
|
||||
CAQLineEdit(self, pv_name="ZHIPA-HUSH:LASTPWR", show_units=True),
|
||||
_row+1, 1, 1, 1)
|
||||
qgrid.addWidget(
|
||||
CAQLineEdit(self, pv_name="HUSH:TOTPWR", show_units=True),
|
||||
CAQLineEdit(self, pv_name="ZHIPA-HUSH:TOTPWR", show_units=True),
|
||||
_row+1, 2, 1, 1)
|
||||
qgrid.addWidget(
|
||||
CAQLineEdit(self, pv_name="HUSH:LASTSAVE", show_units=False),
|
||||
CAQLineEdit(self, pv_name="ZHIPA-HUSH:LASTSAVE", show_units=False),
|
||||
_row+1, 3, 1, 1)
|
||||
qgrid.addWidget(
|
||||
CAQLineEdit(self, pv_name="HUSH:TOTSAVE", show_units=False),
|
||||
CAQLineEdit(self, pv_name="ZHIPA-HUSH:TOTSAVE", show_units=False),
|
||||
_row+1, 5, 1, 1)
|
||||
|
||||
qgrid.setContentsMargins(9, 20, 9, 9)
|
||||
@@ -277,7 +325,8 @@ class AppGui(QWidget):
|
||||
def sector_status(self, sector):
|
||||
'''Create each sector line for inclusion into group
|
||||
'''
|
||||
device = "SEC-" + sector
|
||||
#device = "SEC-" + sector
|
||||
device = "Z" + sector + "-HUSH"
|
||||
#Qlabel
|
||||
qsector = QLabel(sector+":")
|
||||
f = qsector.font()
|
||||
@@ -510,29 +559,87 @@ class AppGui(QWidget):
|
||||
sector = target.sector
|
||||
_table = self.table_sol_dict[sector]
|
||||
|
||||
def is_update_enabled():
|
||||
'''Check if update buttons are enabled
|
||||
if NOT, then do not allow inital values values to be updated"
|
||||
'''
|
||||
|
||||
if self.table_pwr_dict[sector].init_value_button.isEnabled() \
|
||||
and _table.init_value_button.isEnabled():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def write_to_restore_ucn():
|
||||
if sector != 'UCN':
|
||||
return
|
||||
restore_pvs = self.settings.data['RestoreUCN']['PV']
|
||||
default_values = self.settings.data['RestoreUCN']['value']
|
||||
#print(restore_pvs, default_values, flush=True)
|
||||
values_dict = self.table_sol_dict['UCN'].get_init_values()
|
||||
#print(values_dict, flush=True)
|
||||
values = []
|
||||
pvs = []
|
||||
for pv, val in zip(restore_pvs, default_values):
|
||||
pv_indict = pv[-4:] + ":SOL:2"
|
||||
try:
|
||||
_val = values_dict[pv_indict]
|
||||
if _val > 0.8 * val:
|
||||
pvs.append(pv)
|
||||
values.append(_val)
|
||||
except KeyError as ex:
|
||||
print("ex", ex)
|
||||
|
||||
|
||||
if pvs:
|
||||
status, status_list = self.cafe.setScalarList(pvs, values)
|
||||
if status != self.cyca.ICAFE_NORMAL:
|
||||
self.send_to_log_window(pv_list=pvs, status=status,
|
||||
status_list=status_list,
|
||||
operation='set', pymodule=_pymodule,
|
||||
line=_line())
|
||||
|
||||
|
||||
if sector == 'UCN':
|
||||
write_to_restore_ucn()
|
||||
|
||||
|
||||
QApplication.processEvents(QEventLoop.AllEvents, 1.0)
|
||||
|
||||
#Do NOT do updates if in standby mode!
|
||||
#Update button is disabled when in standby
|
||||
|
||||
|
||||
#disenable widgets to avoid circular behaviour since
|
||||
#updates of SOL also update PWR, and vice-versa
|
||||
self.table_pwr_dict[sector].init_value_button.setEnabled(False)
|
||||
_table.init_value_button.click()
|
||||
time.sleep(0.05)
|
||||
self.table_pwr_dict[sector].init_value_button.setEnabled(True)
|
||||
|
||||
_table.init_value_button.setEnabled(False)
|
||||
self.table_pwr_dict[sector].init_value_button.click()
|
||||
time.sleep(0.05)
|
||||
self.table_sol_dict[sector].init_value_button.setEnabled(True)
|
||||
|
||||
QApplication.processEvents(QEventLoop.AllEvents, 1.0)
|
||||
#Do not click if already on standby!!
|
||||
|
||||
|
||||
if is_update_enabled():
|
||||
self.table_pwr_dict[sector].init_value_button.setEnabled(False)
|
||||
_table.init_value_button.click()
|
||||
time.sleep(0.05)
|
||||
self.table_pwr_dict[sector].init_value_button.setEnabled(True)
|
||||
|
||||
_table.init_value_button.setEnabled(False)
|
||||
self.table_pwr_dict[sector].init_value_button.click()
|
||||
time.sleep(0.05)
|
||||
self.table_sol_dict[sector].init_value_button.setEnabled(True)
|
||||
|
||||
QApplication.processEvents(QEventLoop.AllEvents, 1.0)
|
||||
|
||||
|
||||
|
||||
if not self.input_parameters['simulation']:
|
||||
if sector == 'UCN':
|
||||
write_to_restore_ucn()
|
||||
status, status_list, pv_list = _table.set_standby_values()
|
||||
|
||||
if status != self.cyca.ICAFE_NORMAL:
|
||||
self.check_status_list(pv_list, status_list, _line())
|
||||
|
||||
pv = 'SEC-' + target.sector + ":STATE"
|
||||
#pv = 'SEC-' + target.sector + ":STATE"
|
||||
pv = 'Z' + target.sector + "-HUSH:STATE"
|
||||
stat = self.cafe.set(pv, 0)
|
||||
self.check_status(pv, stat, _line())
|
||||
|
||||
@@ -548,15 +655,17 @@ class AppGui(QWidget):
|
||||
if status != self.cyca.ICAFE_NORMAL:
|
||||
self.check_status_list(pv_list, status_list, _line())
|
||||
|
||||
pv = 'SEC-' + target.sector + ":STATE"
|
||||
#pv = 'SEC-' + target.sector + ":STATE"
|
||||
pv = 'Z' + target.sector + "-HUSH:STATE"
|
||||
stat = self.cafe.set(pv, 1)
|
||||
self.check_status(pv, stat, _line())
|
||||
|
||||
_table_pwr = self.table_pwr_dict[sector]
|
||||
row_pwr_dict = _table_pwr.get_init_values()
|
||||
sum_pwr = sum(list(row_pwr_dict.values()))
|
||||
pv_last_pwr = 'SEC-' + target.sector + ":LASTPWR"
|
||||
|
||||
#pv_last_pwr = 'SEC-' + target.sector + ":LASTPWR"
|
||||
pv_last_pwr = 'Z' + target.sector + "-HUSH:LASTPWR"
|
||||
|
||||
stat = self.cafe.set(pv_last_pwr, sum_pwr)
|
||||
self.check_status(pv_last_pwr, stat, _line())
|
||||
|
||||
@@ -706,7 +815,8 @@ class AppGui(QWidget):
|
||||
table_pwr.init_value_button.click()
|
||||
time.sleep(0.1)
|
||||
table_sol.init_value_button.setEnabled(True)
|
||||
pv = "SEC-" + table_pwr.init_value_button.sector + ":LASTPWR"
|
||||
#pv = "SEC-" + table_pwr.init_value_button.sector + ":LASTPWR"
|
||||
pv = "Z" + table_pwr.init_value_button.sector + "-HUSH:LASTPWR"
|
||||
_sum = sum(table_pwr.get_init_values().values())
|
||||
#print("SUM up all the values", pv, _sum, flush=True)
|
||||
stat = self.cafe.set(pv, _sum)
|
||||
|
||||
Reference in New Issue
Block a user