-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathepicsMotorEntry.py.precon
executable file
·109 lines (84 loc) · 3.46 KB
/
epicsMotorEntry.py.precon
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
"""
This module provides a class library for a GUI entry field widget bound to an Epics motor record instance. The motor RBV is monitored
and the field is updated and lit up green when the motor is moving.
Author: John Skinner
Created: Nov, 2 2009
Modifications:
"""
import epicsPV
from Tkinter import *
import Pmw
from beamline_support import *
class epicsMotorEntry:
"""
This module provides a class library for a GUI entry field widget bound to an Epics motor record instance. The motor RBV is monitored
and the field is updated and lit up green when the motor is moving.
"""
is_drawn = 0
def __init__(self, pvname,parent,input_width,type_string,precision = 2):
"""
Inputs:
pvname:
The name of the epics motor.
parent:
The container to place the entry widget.
input_width:
type_string:
'real' or 'int' or 'none'
precision
Example:
beam_width = epicsMotorEntry("x12c:beam_width",aperature_width_frame,8,'real',0)
beam_width.pack(side=LEFT)
"""
self.precision = precision
self.entry_var = StringVar()
self.entry_pv = pvCreate(pvname+".RBV")
self._set_entry_var_with_precision(pvGet(self.entry_pv))
if (type_string == "none"):
self._set_entry_var_with_precision(pvGet(self.entry_pv))
else:
self.entry = Pmw.EntryField(parent,value=str(pvGet(self.entry_pv)),validate = {'validator':type_string})
self.entry.component('entry').configure(width=input_width,textvariable=self.entry_var)
add_callback(self.entry_pv,self._entry_pv_movingCb,"")
self.entry_dmov_pv = pvCreate(pvname+".DMOV")
add_callback(self.entry_dmov_pv,self._entry_pv_dmovCb,"")
def _entry_pv_movingCb(self,epics_args, user_args):
# print "in callback " + str(epics_args['pv_value'])
if not (epicsMotorEntry.is_drawn):
return
self._set_entry_var_with_precision(epics_args['pv_value'])
def _entry_pv_dmovCb(self,epics_args, user_args):
if not (epicsMotorEntry.is_drawn):
return
if (epics_args['pv_value'] == 1):
self.entry.component('entry').configure(background="#729fff")
else:
self.entry.component('entry').configure(background="green")
def _set_entry_var_with_precision(self,inval):
try:
val = float(inval)
if (self.precision == 0):
self.entry_var.set("%.0f" % val)
elif (self.precision == 1):
self.entry_var.set("%.1f" % val)
elif (self.precision == 2):
self.entry_var.set("%.2f" % val)
elif (self.precision == 3):
self.entry_var.set("%.3f" % val)
elif (self.precision == 4):
self.entry_var.set("%.4f" % val)
else:
self.entry_var.set("%.5f" % val)
except TypeError:
print "type error"
self.entry_var.set(waveform_to_string(val))
def pack(self,side=LEFT,padx=0,pady=0): #pass the params in
self.entry.pack(side=side,padx=padx,pady=pady)
def getEntry(self):
return self.entry
def getField(self):
return self.entry_var.get()
def setField(self,value):
self.entry_var.set(value)
def setColor(self,color_string):
self.entry.component('entry').configure(background=color_string)