| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
from warnings import warnpy3k |
| 10 |
warnpy3k("the panel module has been removed in Python 3.0", stacklevel=2) |
| 11 |
del warnpy3k |
| 12 |
|
| 13 |
|
| 14 |
import pnl |
| 15 |
|
| 16 |
|
| 17 |
debug = 0 |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
def is_list(x): |
| 23 |
return type(x) == type([]) |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
def reverse(list): |
| 29 |
res = [] |
| 30 |
for item in list: |
| 31 |
res.insert(0, item) |
| 32 |
return res |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
def getattrlist(list, name): |
| 39 |
for item in list: |
| 40 |
if item and is_list(item) and item[0] == name: |
| 41 |
return item[1:] |
| 42 |
return [] |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
def getproplist(list, name): |
| 48 |
for item in list: |
| 49 |
if item and is_list(item) and item[0] == 'prop': |
| 50 |
if len(item) > 1 and item[1] == name: |
| 51 |
return item[2:] |
| 52 |
return [] |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
def is_endgroup(list): |
| 58 |
x = getproplist(list, 'end-of-group') |
| 59 |
return (x and x[0] == '#t') |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
def show_actuator(prefix, a): |
| 66 |
for item in a: |
| 67 |
if not is_list(item): |
| 68 |
print prefix, item |
| 69 |
elif item and item[0] == 'al': |
| 70 |
print prefix, 'Subactuator list:' |
| 71 |
for a in item[1:]: |
| 72 |
show_actuator(prefix + ' ', a) |
| 73 |
elif len(item) == 2: |
| 74 |
print prefix, item[0], '=>', item[1] |
| 75 |
elif len(item) == 3 and item[0] == 'prop': |
| 76 |
print prefix, 'Prop', item[1], '=>', |
| 77 |
print item[2] |
| 78 |
else: |
| 79 |
print prefix, '?', item |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
def show_panel(prefix, p): |
| 85 |
for item in p: |
| 86 |
if not is_list(item): |
| 87 |
print prefix, item |
| 88 |
elif item and item[0] == 'al': |
| 89 |
print prefix, 'Actuator list:' |
| 90 |
for a in item[1:]: |
| 91 |
show_actuator(prefix + ' ', a) |
| 92 |
elif len(item) == 2: |
| 93 |
print prefix, item[0], '=>', item[1] |
| 94 |
elif len(item) == 3 and item[0] == 'prop': |
| 95 |
print prefix, 'Prop', item[1], '=>', |
| 96 |
print item[2] |
| 97 |
else: |
| 98 |
print prefix, '?', item |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
panel_error = 'panel error' |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
def dummy_callback(arg): |
| 109 |
pass |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
def assign_members(target, attrlist, exclist, prefix): |
| 117 |
for item in attrlist: |
| 118 |
if is_list(item) and len(item) == 2 and item[0] not in exclist: |
| 119 |
name, value = item[0], item[1] |
| 120 |
ok = 1 |
| 121 |
if value[0] in '-0123456789': |
| 122 |
value = eval(value) |
| 123 |
elif value[0] == '"': |
| 124 |
value = value[1:-1] |
| 125 |
elif value == 'move-then-resize': |
| 126 |
|
| 127 |
ok = 0 |
| 128 |
else: |
| 129 |
print 'unknown value', value, 'for', name |
| 130 |
ok = 0 |
| 131 |
if ok: |
| 132 |
lhs = 'target.' + prefix + name |
| 133 |
stmt = lhs + '=' + repr(value) |
| 134 |
if debug: print 'exec', stmt |
| 135 |
try: |
| 136 |
exec stmt + '\n' |
| 137 |
except KeyboardInterrupt: |
| 138 |
raise KeyboardInterrupt |
| 139 |
except: |
| 140 |
print 'assign failed:', stmt |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
def build_actuator(descr): |
| 147 |
namelist = getattrlist(descr, 'name') |
| 148 |
if namelist: |
| 149 |
|
| 150 |
actuatorname = namelist[0][1:-1] |
| 151 |
else: |
| 152 |
actuatorname = '' |
| 153 |
type = descr[0] |
| 154 |
if type[:4] == 'pnl_': type = type[4:] |
| 155 |
act = pnl.mkact(type) |
| 156 |
act.downfunc = act.activefunc = act.upfunc = dummy_callback |
| 157 |
|
| 158 |
assign_members(act, descr[1:], ['al', 'data', 'name'], '') |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
datalist = getattrlist(descr, 'data') |
| 163 |
prefix = '' |
| 164 |
if type[-4:] == 'puck': |
| 165 |
prefix = 'puck_' |
| 166 |
elif type == 'mouse': |
| 167 |
prefix = 'mouse_' |
| 168 |
assign_members(act, datalist, [], prefix) |
| 169 |
|
| 170 |
return act, actuatorname |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
def build_subactuators(panel, super_act, al): |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
for a in al: |
| 187 |
act, name = build_actuator(a) |
| 188 |
act.addsubact(super_act) |
| 189 |
if name: |
| 190 |
stmt = 'panel.' + name + ' = act' |
| 191 |
if debug: print 'exec', stmt |
| 192 |
exec stmt + '\n' |
| 193 |
if is_endgroup(a): |
| 194 |
panel.endgroup() |
| 195 |
sub_al = getattrlist(a, 'al') |
| 196 |
if sub_al: |
| 197 |
build_subactuators(panel, act, sub_al) |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
super_act.fixact() |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
def build_panel(descr): |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
if (not descr) or descr[0] != 'panel': |
| 214 |
raise panel_error, 'panel description must start with "panel"' |
| 215 |
|
| 216 |
if debug: show_panel('', descr) |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
panel = pnl.mkpanel() |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
assign_members(panel, descr[1:], ['al'], '') |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
al = getattrlist(descr, 'al') |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
al = reverse(al) |
| 236 |
|
| 237 |
for a in al: |
| 238 |
act, name = build_actuator(a) |
| 239 |
act.addact(panel) |
| 240 |
if name: |
| 241 |
stmt = 'panel.' + name + ' = act' |
| 242 |
exec stmt + '\n' |
| 243 |
if is_endgroup(a): |
| 244 |
panel.endgroup() |
| 245 |
sub_al = getattrlist(a, 'al') |
| 246 |
if sub_al: |
| 247 |
build_subactuators(panel, act, sub_al) |
| 248 |
|
| 249 |
return panel |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
def my_dopanel(): |
| 255 |
|
| 256 |
a, down, active, up = pnl.dopanel()[:4] |
| 257 |
if down: |
| 258 |
down.downfunc(down) |
| 259 |
if active: |
| 260 |
active.activefunc(active) |
| 261 |
if up: |
| 262 |
up.upfunc(up) |
| 263 |
return a |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
def defpanellist(file): |
| 270 |
import panelparser |
| 271 |
descrlist = panelparser.parse_file(open(file, 'r')) |
| 272 |
panellist = [] |
| 273 |
for descr in descrlist: |
| 274 |
panellist.append(build_panel(descr)) |
| 275 |
return panellist |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
from pnl import * |
| 283 |
|
| 284 |
dopanel = my_dopanel |