-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepicsTypeNGo.tcl
130 lines (109 loc) · 3.34 KB
/
epicsTypeNGo.tcl
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
#
# This software is Copyright by the Board of Trustees of Michigan
# State University (c) Copyright 2005.
#
# You may use this software under the terms of the GNU public license
# (GPL) ir the Tcl BSD derived license The terms of these licenses
# are described at:
#
# GPL: http://www.gnu.org/licenses/gpl.txt
# Tcl: http://www.tcl.tk/softare/tcltk/license.html
# Start with the second paragraph under the Tcl/Tk License terms
# as ownership is solely by Board of Trustees at Michigan State University.
#
# Author:
# Ron Fox
# NSCL
# Michigan State University
# East Lansing, MI 48824-1321
#
#
# Implements a typeNGo widget that is specialized to epics.
# In particular, the label part of the typeNGo tracks an epics
# channel value and the click/<Return> binding will
# map to setting the value of the channel from the entry widget.
#
# OPTIONS:
# -channel - Specifies the epics channel to control/monitor.
# All other options other than -command are delegated to the
# typeNGo widget we are based on.
#
# METHODS:
# All typeNGo methods are supported.
#
package provide epicsTypeNGo 1.0
package require Tk
package require snit
package require typeNGo
package require epics
package require bindDown
namespace eval controlwidget {
namespace export epicsTypeNGo
}
snit::widget controlwidget::epicsTypeNGo {
delegate option * to basewidget except -command
delegate method * to basewidget
option -channel {}
variable timerId -1
constructor args {
# We need to figure out which are our options
# and which are the base widget's We're going to
# take -channel and -command:
set myargs [list]
set baseargs [list]
foreach {option value} $args {
if {[lsearch -exact $option "-channel"] != -1} {
lappend myargs $option $value
} else {
lappend baseargs $option $value
}
}
eval install basewidget as controlwidget::typeNGo $win.tng \
-command {[mymethod onChanged]} $baseargs
$self configurelist $myargs
# Now deal with getting/binding the channel to the widget.
#
set channel $options(-channel)
if {$channel eq "" } {
error "controlwdiget::epicsTypeNGo must have a -channel specification"
}
epicschannel $channel
$channel link ::controlwidget::$channel
$win.tng configure -textvariable ::controlwidget::$channel
pack $win.tng -fill both -expand 1
# try to preload the entry with the setv...
# Don't try for modicon points.. they don't have a SETV.
#
if {[string range $channel 0 1] ne "P#"} {
epicschannel $channel.SETV
set timerId [after 100 [mymethod loadEntry]]
}
bindDown $win $win
}
destructor {
if {$timerId != -1} {
after cancel $timerId
}
}
# Called when the entry has been comitted.. we just need to set the epics
# channel value:
method onChanged {} {
set newValue [$win.tng Get]
set channel $options(-channel)
$channel set $newValue; # The label will track readback changes.
}
#
# Called to attempt to load the entry widget with the value of SETV at
# start time. On failure reschedules self.
#
method loadEntry {} {
set channel $options(-channel).SETV
if {[catch {$channel get} value] || ($value eq "")} {
set timerId [after 100 [mymethod loadEntry]]
return
}
# value is the current setv value:
$win.tng Set $value
set timerId -1
}
}