-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncPanel.py
More file actions
executable file
·107 lines (101 loc) · 2.75 KB
/
syncPanel.py
File metadata and controls
executable file
·107 lines (101 loc) · 2.75 KB
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
from sys import argv,stdout
from os import path
from shutil import copy
from os import unlink
def ncr(s):
return s.split('\n')[0]
try:
srcfile=path.split(argv[0])[1]
except IndexError:
srcfile='thisfile'
try:
pnlfile=argv[1]
except IndexError:
pnlfile='simple.pnl'
try:
incfile=argv[2]
except IndexError:
incfile='parameters.inc'
pnl=file(pnlfile,'r')
tmp=file('tmppanel.pnl','w')
inc=file(incfile,'r')
pnlDict={}
infileDict={}
#read pnl and get list of variables
newpnl=False
readItems=False
defines={}
#crfeate deictionary of defines and their values
while True:
line=inc.readline()
if not line:
break
if line=='\n':
continue
sline=line.split()
defines[sline[1]]=sline[2]
inc.close()
updateRequired=False
while True:
line=pnl.readline()
if not line:
break
if line.find('pver')==-1:
break
#read details of this file
tmp.write(line) # pver
line=pnl.readline()
tmp.write(line)# name
line=pnl.readline()
tmp.write(line)#associate
line=pnl.readline()
tmp.write(line)#trigger
items=int(ncr(pnl.readline().split('items: ')[1]))
tmp.write('items: %i\n' % (items))
for i in range(0,items):
line=pnl.readline()
ptype=line.split('type: ')[1]
tmp.write(line)#type
if ptype.find('SLIDER')<>-1:
line=pnl.readline()
tmp.write(line)# name
line=pnl.readline()
tmp.write(line)# colors
line=pnl.readline()
tmp.write(line)# origin
line=pnl.readline()
tmp.write(line)# min/max
vline=pnl.readline() # value line and check if it has changed
value=int(vline.split('value: ')[1])
mline=pnl.readline()
sline=mline.split()
pname=sline[2]#take parameter name from message
scale=int(sline[4])
try:
newvalue=int(defines[pname])*scale
except ValueError: #must be a float
newvalue=int(float(defines[pname])*scale)
if value<>newvalue:
updateRequired=True
print 'updating value for %s from %i to %i' % (pname,value,newvalue)
tmp.write('value: %i\n' % (newvalue))
else:
tmp.write(vline)
tmp.write(mline)#message
if ptype.find('LABEL')<>-1:
line=pnl.readline()
tmp.write(line)# name
line=pnl.readline()
tmp.write(line)# color
line=pnl.readline()
tmp.write(line)# origin
tmp.write('\n')
cr=pnl.readline()
pnl.close()
tmp.close()
if updateRequired:
#copy pnlfile to old
copy(pnlfile,pnlfile+'.old')
#copy tmp to pnlfile
copy('tmppanel.pnl',pnlfile)
unlink('tmppanel.pnl')