1 import MobHub
2 import MashTimer
3 Class IndivaController
4
5 global curr_frame
6 set curr_frame 0
7
8 IndivaController instproc init { mobs imgr } {
9 $self instvar imgr_ lb_ frames_
10 set imgr_ $imgr
11 set w [$self init_gui]
12
13 $self add_guis $mobs $imgr $w
14 }
15
16 IndivaController instproc add_guis {mobs imgr w} {
17 $self instvar lb_ frames_
18 set count 0
19 foreach mob [join $mobs] {
20 set path [$imgr path $mob]
21
22 set from [lindex $path 0]
23 set tos [lrange $path 1 end]
24 if {$tos == ""} {
25 # make sure we enter the for loop at least once.
26 set tos {""}
27 }
28 foreach to $tos {
29 if {[MobHub is_hub $to]} {
30 continue
31 }
32 set dev [$imgr info $from -device]
33 if {![info exists processed($dev,$from)]} {
34 set processed($dev,$from) 1
35 set label [lindex [$imgr info $dev -friendlyname] 0]
36 set servicename [$imgr info service $from $to -friendlyname]
37 if {$servicename != ""} {
38 set label "$label ($servicename)"
39 }
40 set str [$imgr gui $from $to $w.$count -tk]
41 if {$str != ""} {
42 frame $w.$count
43 lappend frames_($dev,$servicename) $w.$count
44 if {[llength $frames_($dev,$servicename)] == 1} {
45 radiobutton $lb_.$count -text $label \
46 -anchor nw \
47 -variable dev \
48 -value $dev \
49 -indicatoron 0 \
50 -selectcolor white \
51 -relief flat \
52 -bd 0 \
53 -command "$self switch_frame $dev \"$servicename\""
54 pack $lb_.$count -expand 1 -fill x
55 }
56 if [catch {$self add_gui $from $to $str} err] {
57 global errorInfo
58 puts "ERROR when adding GUI :$err"
59 puts $errorInfo
60 }
61 }
62 }
63 incr count
64 set from $to
65 }
66 }
67 }
68
69 IndivaController instproc refresh { mobs imgr } {
70 $self instvar frames_ mainframe_ lb_
71 set w $mainframe_
72 foreach key [array names frames_] {
73 foreach frame $frames_($key) {
74 destroy $frame
75 }
76 unset frames_($key)
77 }
78 destroy $lb_
79 set lb_ [frame $w.lb -relief sunken -bd 3]
80 pack $w -expand 1 -fill both
81 pack $lb_ -expand 1 -fill x
82
83 $self add_guis $mobs $imgr $w
84 }
85
86 IndivaController instproc init_gui { } {
87 $self instvar lb_ topframe_ mainframe_
88 toplevel .top
89 wm title .top "Indiva Controller"
90 set topframe_ [frame .top.topframe -class IndivaControl]
91 set f [frame $topframe_.main]
92 set lb_ [frame $f.lb -relief sunken -bd 3]
93 pack $topframe_ $f -expand 1 -fill both
94 pack $lb_ -expand 1 -fill both
95
96 set mainframe_ $f
97
98 global tcl_platform
99 if {$tcl_platform(platform) == "windows"} {
100 set font Tahoma
101 } else {
102 set font Lucida
103 }
104 option add *IndivaControl*font "$font 11 normal"
105 option add *IndivaControl*Label.Relief groove
106 option add *IndivaControl*Label.Font "$font 9 bold"
107 option add *IndivaControl*Scale.Relief groove
108 option add *IndivaControl*Scale.Font "$font 9 normal"
109
110 return $f
111 }
112
113
114 IndivaController instproc add_gui { from to str } {
115 set layout [lindex $str 0]
116 set commands [lindex $str 1]
117 eval $layout
118 $self instvar imgr_
119 foreach {type object cmd} $commands {
120 switch $type {
121 widget {
122 # If the object is a scale, we delay sending the command
123 # until t ms user stop sliding. Otherwise we will be
124 # sending unnecessary messages to $imgr_.
125 set cls [winfo class $object]
126 switch $cls {
127 Scale {
128 $object configure -command "$self on_scale_changed $object $imgr_ control $from $to $cmd"
129 }
130 default {
131 $object configure -command "$self control $from $to $cmd"
132 }
133 }
134 }
135 variable {
136 set traceproc "
137 proc ${object}_trace {var index op} {
138 global $object
139 $imgr_ control $from $to $cmd
140 }"
141 uplevel #0 $traceproc
142 trace variable $object w ${object}_trace
143 #for tcl >= 8.4
144 #trace add variable $object w "$imgr_ control $from $to $cmd"
145 }
146 default {
147 puts "WARNING: unknown command type $type"
148 }
149 }
150 }
151 }
152
153 IndivaController instproc control { from to args } {
154 set args [join $args]
155 $self instvar imgr_
156 if {[catch {$imgr_ control $from $to $args} err]} {
157 puts stderr "Unable to control $from $to. Tcl encountered an error\n$err"
158 }
159 }
160
161 IndivaController public topframe { } {
162 $self instvar topframe_
163 return $topframe_
164 }
165
166
167 IndivaController private on_scale_changed { scale args } {
168 $self instvar after_ids_
169 if [info exists after_ids_($scale)] {
170 after cancel $after_ids_($scale)
171 }
172 set after_ids_($scale) [after 300 eval $args]
173 }
174
175 IndivaController private switch_frame {dev name} {
176 $self instvar frames_ curr_frames_
177 catch {eval pack forget $curr_frames_}
178 eval pack [set curr_frames_ $frames_($dev,$name)]
179 }
180
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.