Commit efa8632b authored by Claudio Scafuri's avatar Claudio Scafuri 💬
Browse files

imported from CVS release_15

parent 58bb7e60
CVS
*.pyc
core
.project
.pydevproject
.idea
#!/usr/bin/env python
# $Author: claudio $
#
# $Name: $
#
# $Log: FRTND_E.py,v $
# Revision 1.3 2017-02-13 09:30:51 claudio
# revision tag
#
#
import sys
from PyQt4 import QtCore, QtGui
#from ui_frntd_e import Ui_frntd_e
from active_frntd_e import active_frntd_e
app = QtGui.QApplication(sys.argv)
window = QtGui.QDialog()
#ui = Ui_frntd_e()
ui=active_frntd_e()
#ui.setupUi(window)
ui.setup(window)
window.show()
sys.exit(app.exec_())
#makefile for PyQt4 panel
ui_frntd_e.py::frntd_e.ui
pyuic4 frntd_e.ui >ui_frntd_e.py
\ No newline at end of file
# deirved class to which active beahvoirou is delegated
# the fatehr class is re-generated by the designer
# $Author: claudio $
#
# $Name: $
#
# $Log: active_frntd_e.py,v $
# Revision 1.5 2019-06-20 08:14:21 claudio
# #8957, #8947: add new stopper syrmep, tango controlled
#
# Revision 1.4 2017-02-13 09:30:51 claudio
# revision tag
#
#
from PyQt4 import QtCore, QtGui
from ui_frntd_e import *
import blfe
import tango
class Worker(QtCore.QThread):
def __init__(self, parent=None):
QtCore.QThread.__init__(self, parent)
self.BL = blfe.blfe()
self.exiting = False
self.mode = 'update'
# tango device for syrmep - geco device
self.syrmepstopper = 0
self.syrmepstopperindex = 0
self.stopper_value = -1 # 0: closed , 1:open, -1 : unknown
try:
self.syrmepstopper = tango.DeviceProxy('syrmep-control-01.blcs.elettra.trieste.it:20000/syrmep/beamline/geco')
except:
self.syrmepstopper = 0
def run(self):
if self.mode == 'update':
self.update()
if self.mode == 'execute':
self.execute()
def update(self):
self.BL.read()
self.emit(QtCore.SIGNAL("UpdateThread(PyQt_PyObject)"), self.BL)
# read tango status
try:
self.stopper_value = self.syrmepstopper.r_bs4_v
except:
self.stopper_value = -1
def execute(self):
errtable = self.BL.closeall()
#close tango controlloed syrme stopper
try:
self.syrmepstopper.r_bs4_v=0
except:
self.emit(QtCore.SIGNAL("ExecuteError(PyQt_PyObject,PyQt_PyObject)"), self.BL, 'geco/r_bs4_v failed')
if errtable is None:
self.emit(QtCore.SIGNAL("ExecuteThread(PyQt_PyObject)"), self.BL)
else:
self.emit(QtCore.SIGNAL("ExecuteError(PyQt_PyObject,PyQt_PyObject)"), self.BL, errtable)
class active_frntd_e(Ui_frntd_e, QtCore.QObject):
# ovverride setupUI: create graphics and active object, worker thread , then connects signals and start timer
def setup(self, father):
# create ancesstor graphic objetcs
ui = self.setupUi(father)
self.ui = ui
self.msgbox = None
# connect to slots of this class
self.connect(self.pushClose, QtCore.SIGNAL("clicked()"), self.slot_do_close)
self.connect(self.tableWidget, QtCore.SIGNAL("destroyed()"), self.slot_quit)
# create worker thread - does all the slow network activities
self.thread = Worker()
self.connect(self.thread, QtCore.SIGNAL("UpdateThread(PyQt_PyObject)"), self.slot_thread_update)
self.connect(self.thread, QtCore.SIGNAL("ExecuteThread(PyQt_PyObject)"), self.slot_thread_execute)
self.connect(self.thread, QtCore.SIGNAL("ExecuteError(PyQt_PyObject,PyQt_PyObject)"), self.slot_thread_execute_error)
self.connect(self.thread, QtCore.SIGNAL("ExecuteError(PyQt_PyObject,PyQt_PyObject)"), self.slot_thread_tango_error)
# get reference of BL object from thread
# since the class only reads form BL object non synch primitives are used
# N.B. python copyes object references
self.BL = self.thread.BL
# configure table widget and create color brushes
self.yellowbrush = QtGui.QBrush(QtGui.QColor("yellow"))
self.greenbrush = QtGui.QBrush(QtGui.QColor("green"))
self.redbrush = QtGui.QBrush(QtGui.QColor("red"))
self.graybrush = QtGui.QBrush(QtGui.QColor("gray"))
n = self.BL.nentries
self.tableWidget.setRowCount(n + 1)
row = 0
for entry in self.BL.bltable:
bname = entry[2]
objname = entry[0]
stname = entry[4]
col0 = QtGui.QTableWidgetItem(bname, 0)
col1 = QtGui.QTableWidgetItem(objname, 1)
col2 = QtGui.QTableWidgetItem(stname, 2)
col2.setBackground(self.graybrush)
self.tableWidget.setItem(row, 0, col0)
self.tableWidget.setItem(row, 1, col1)
self.tableWidget.setItem(row, 2, col2)
self.tableWidget.setRowHeight(row, 22)
row = row + 1
# add Tango managed entries - different
bname = 'Syrmep'
objname = 'geco/r_bs4_v'
stname = 'UNKNOWN'
col0 = QtGui.QTableWidgetItem(bname, 0)
col1 = QtGui.QTableWidgetItem(objname, 1)
col2 = QtGui.QTableWidgetItem(stname, 2)
col2.setBackground(self.graybrush)
self.tableWidget.setItem(row, 0, col0)
self.tableWidget.setItem(row, 1, col1)
self.tableWidget.setItem(row, 2, col2)
self.tableWidget.setRowHeight(row, 22)
self.thread.syrmepstopperindex = row
self.syrmepstopperindex = row
row = row + 1
palette = self.label.palette()
palette.setBrush(QtGui.QPalette.Window, self.graybrush)
self.label.setPalette(palette)
self.label.setAutoFillBackground(1)
self.label.setText('UNKNOWN')
# resize columns
self.tableWidget.setColumnWidth(0, 130)
self.tableWidget.setColumnWidth(1, 310)
# do first table update
self.update_table()
# start timer
self.timer = QtCore.QTimer(self)
self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.update_table)
self.timer.start(3000)
return ui
def update_table(self):
# configure and start thread
self.thread.mode = 'update'
self.thread.start()
def redraw_table(self, myBL):
# redraw informations
row = 0
for entry in myBL.bltable:
stname = entry[4]
item = self.tableWidget.item(row, 2)
item.setText(stname)
if stname == 'OPEN':
item.setBackground(self.redbrush)
if stname == 'CLOSED':
item.setBackground(self.greenbrush)
if stname == 'ERROR':
item.setBackground(self.yellowbrush)
if stname == 'UNKNOWN':
item.setBackground(self.graybrush)
# self.tableWidget.setItem(row,2,item)
row = row + 1
# check syrmep tango reading
idx = self.thread.syrmepstopperindex
item = self.tableWidget.item(idx, 2)
if self.thread.stopper_value == 1:
item.setBackground(self.redbrush)
item.setText('OPEN')
if self.thread.stopper_value == 0:
item.setBackground(self.greenbrush)
item.setText('CLOSED')
if self.thread.stopper_value == -1:
item.setBackground(self.graybrush)
item.setText('UNKNOWN')
palette = self.label.palette()
if (myBL.allclosed() == 1 and self.thread.stopper_value == 0):
palette.setBrush(QtGui.QPalette.Window, self.greenbrush)
self.label.setText('ALL CLOSED')
else:
palette.setBrush(QtGui.QPalette.Window, self.redbrush)
self.label.setText('OPEN/CLOSED')
self.label.setPalette(palette)
self.label.setAutoFillBackground(1)
def slot_do_close(self):
# first stop aqcusition thread
self.timer.stop()
self.thread.wait()
# start execution thread
self.thread.mode = 'execute'
self.thread.start()
# post dialog box since there is some time to wait
if self.msgbox is None:
self.msgbox = QtGui.QProgressDialog('Closing front-ends...', '', 0, 0)
self.msgbox.setLabelText('Closing front-ends...')
self.msgbox.setCancelButtonText('')
self.msgbox.setWindowTitle('BEAMLINE FRONT END')
self.msgbox.setModal(True)
# How do you remove a button in a dialog????
# butt=self.msgbox.button(QtGui.QMessageBox.Close)
# as a work-aroud, remove cancel functionality
QtCore.QObject.disconnect(self.msgbox, QtCore.SIGNAL('canceled()'), self.msgbox, QtCore.SLOT('cancel()'))
self.msgbox.show()
QtCore.SIGNAL
else:
self.msgbox.show()
def slot_thread_update(self, myBL):
# slot called when read is terminated
self.redraw_table(myBL)
def slot_thread_execute(self, myBL):
# called when execution thread is terminated normally
self.msgbox.close()
self.redraw_table(myBL)
self.timer.start(3000)
def slot_thread_execute_error(self, myBL, myerrtable):
# called when execution thread is terminated with error
self.msgbox.close()
self.redraw_table(myBL)
self.timer.start(3000)
# shuold improve formatting of beamline errors...
QtGui.QMessageBox.critical(self.ui, 'front-end close', repr(myerrtable))
def slot_thread_tango_error(self, myBL, msg):
# called when execution thread is terminated with error
self.msgbox.close()
self.redraw_table(myBL)
self.timer.start(3000)
# shuold improve formatting of beamline errors...
QtGui.QMessageBox.critical(self.ui, 'syrmep front-end close', msg)
def slot_quit(self):
self.timer.stop()
self.thread.wait()
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>frntd_e</class>
<widget class="QDialog" name="frntd_e">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>702</width>
<height>1021</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="windowTitle">
<string>BEAMLINE FRONT END</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout">
<item>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="text">
<string>ALL CLOSED</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>1</number>
</property>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushClose">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>CLOSE ALL</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="tableWidget">
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="autoScroll">
<bool>false</bool>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="tabKeyNavigation">
<bool>false</bool>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="textElideMode">
<enum>Qt::ElideNone</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="cornerButtonEnabled">
<bool>false</bool>
</property>
<column>
<property name="text">
<string>Beamline</string>
</property>
</column>
<column>
<property name="text">
<string>Point Name</string>
</property>
</column>
<column>
<property name="text">
<string>Status</string>
</property>
</column>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'frntd_e.ui'
#
# Created by: PyQt4 UI code generator 4.12.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_frntd_e(object):
def setupUi(self, frntd_e):
frntd_e.setObjectName(_fromUtf8("frntd_e"))
frntd_e.resize(702, 1021)
font = QtGui.QFont()
font.setPointSize(10)
frntd_e.setFont(font)
frntd_e.setSizeGripEnabled(True)
self.gridlayout = QtGui.QGridLayout(frntd_e)
self.gridlayout.setObjectName(_fromUtf8("gridlayout"))
self.hboxlayout = QtGui.QHBoxLayout()
self.hboxlayout.setObjectName(_fromUtf8("hboxlayout"))
self.vboxlayout = QtGui.QVBoxLayout()
self.vboxlayout.setObjectName(_fromUtf8("vboxlayout"))
self.label = QtGui.QLabel(frntd_e)
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setFrameShape(QtGui.QFrame.Panel)
self.label.setFrameShadow(QtGui.QFrame.Sunken)
self.label.setLineWidth(1)
self.label.setTextFormat(QtCore.Qt.PlainText)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
self.label.setObjectName(_fromUtf8("label"))
self.vboxlayout.addWidget(self.label)
self.pushClose = QtGui.QPushButton(frntd_e)
font = QtGui.QFont()
font.setPointSize(10)
self.pushClose.setFont(font)
self.pushClose.setObjectName(_fromUtf8("pushClose"))
self.vboxlayout.addWidget(self.pushClose)
spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.vboxlayout.addItem(spacerItem)
self.hboxlayout.addLayout(self.vboxlayout)
self.tableWidget = QtGui.QTableWidget(frntd_e)
font = QtGui.QFont()
font.setPointSize(9)
self.tableWidget.setFont(font)
self.tableWidget.setAutoFillBackground(True)
self.tableWidget.setLineWidth(1)
self.tableWidget.setAutoScroll(False)
self.tableWidget.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.tableWidget.setTabKeyNavigation(False)
self.tableWidget.setProperty("showDropIndicator", False)
self.tableWidget.setDragDropOverwriteMode(False)
self.tableWidget.setAlternatingRowColors(True)
self.tableWidget.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
self.tableWidget.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.tableWidget.setTextElideMode(QtCore.Qt.ElideNone)
self.tableWidget.setWordWrap(False)
self.tableWidget.setCornerButtonEnabled(False)
self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
self.tableWidget.setColumnCount(3)
self.tableWidget.setRowCount(0)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
self.hboxlayout.addWidget(self.tableWidget)
self.gridlayout.addLayout(self.hboxlayout, 0, 0, 1, 1)
self.retranslateUi(frntd_e)
QtCore.QMetaObject.connectSlotsByName(frntd_e)
def retranslateUi(self, frntd_e):
frntd_e.setWindowTitle(_translate("frntd_e", "BEAMLINE FRONT END", None))
self.label.setText(_translate("frntd_e", "ALL CLOSED", None))
self.pushClose.setText(_translate("frntd_e", "CLOSE ALL", None))
self.tableWidget.setSortingEnabled(False)
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("frntd_e", "Beamline", None))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("frntd_e", "Point Name", None))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("frntd_e", "Status", None))
Il servzio TCPS viene gestito da un certo numero di istanze differenti con port number assegnato in modo da ripartire il carico,
le uscite da bending - per ora - leggono tutte dalla stessa istanza.
Le porte vanno assegnate per corrispondere al range di bcs da 1.1 (11) A 11.2 (112)
011 TWIN mIC : 20011
012 FEL - Nanospectroscopy : 20012
022 SuperESCA - Escamicroscopy : 20022
032 VUV photoemission - Spectromicroscopy : 20032
042 Circularly Polarized : 20042
052 X-ray diffraction - SAXS : 20052
061 SYRMEP - MSB : 20061
062 Gas Phase : 20062
072 ALOISA : 20072
081 Lilit - BEAR : 20081
082 Bach : 20082
092 APE : 20092
101 Microfabrication : 20101
102 Iuvs BaDElph : 20102
111 Exsafs : 20111
112 Xrd2 : 20112 (previsto ma non attivato, ci sara' un srver tango diretto)
\ No newline at end of file
# parse,check,translate TCPS to tango
# and exec tabled actions
import string
import sys
import PyTango
#module wide constants
okmsg = 'Command execution OK'
errmsg_header = '*** ERROR'
term = "\r\n"
#################################################################################################
#utilities - taken from tangoclient.py to prpperly convert/assign types to command and attributes
#from strings
def convertToAttributeValue(pars, info, logger):
logger.debug( 'ConvertToAttribute() entering...')
#val = PyTango.AttributeValue()
#val.name = info.name
logger.debug( 'ConvertToAttribute() entered...')
if info.data_format == PyTango.SCALAR:
if info.data_type == PyTango.DevBoolean:
if pars[0] == '0' or pars[0].lower() == 'false':
value = False
else:
value = True