-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_click_panels.py
425 lines (347 loc) · 15.4 KB
/
gen_click_panels.py
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#
# Configuration...
#
CLICK_PANEL_DEFS = { "photos":"https://docs.google.com/spreadsheet/pub?key=0AvPzUVdJ7YGedEFLTGNNcHNhNmRCWHljUzlzN01SZ2c&output=csv", \
"previs":"https://docs.google.com/spreadsheet/pub?key=0AuRz1oxD7nNEdGh4NEQ4Q195dlM0Y3hIX2M5enZvcUE&output=csv" }
#
# Library...
#
import common
import os
import gen_images
import sys
MOVIES1_PREFIX = "../phil_assets"
PHIL_PREFIX = "../phil_assets"
MOVIES2_PREFIX = "../videos"
VIDEOS_PREFIX = "../videos"
POSTERS_PREFIX = "../posters"
def get_dct(pagekeys):
print "cp getdct->", pagekeys
if pagekeys==None:
pagekeys = CLICK_PANEL_DEFS.keys()
newdct = {}
for code in pagekeys:
if not CLICK_PANEL_DEFS.has_key(code): continue
items = common.parse_spreadsheet1( CLICK_PANEL_DEFS[code], "click panels->%s" % str(pagekeys) )
dct = common.dct_join( items,'name')
for ky in dct.keys():
newdct[ky] = dct[ky]
return newdct
def get_item_path( name, movies_dct ):
item_def = movies_dct[name][0]
path = item_def['path']
fname = item_def['filename']
fpath = os.path.join(path,fname)
fpath = fpath.replace("MOVIES1",MOVIES1_PREFIX)
fpath = fpath.replace("MOVIES2",MOVIES2_PREFIX)
return fpath
def cpo_expand_preview_item( accum_ids, parent, asset_def, cp_dct, cpo_dct, images_dct, init_item, action_scripts ):
print "CPO EXPAND PREVIEW->", asset_def, cpo_dct.keys()
typ = asset_def["type"]
x = int(asset_def['x'])
y = int(asset_def['y'])
z = int(asset_def['z'])
name = asset_def['asset_name']
hid = common.get_id( name, accum_ids )
# get the individual images and create ids...
img_init_asset = images_dct[init_item][0]
path = img_init_asset['path']
fname = img_init_asset['filename']
src = os.path.join(path,fname)
src = common.path_replace( src )
src = common.create_path( src )
# style...
style = ""
style += common.emit_line("#%s {" % hid )
style += common.emit_line(" position: absolute;")
style += common.emit_line(" top: %dpx;" % y )
style += common.emit_line(" left: %dpx;" % x )
style += common.emit_line(" z-index: %d;" % (z+1) )
style += common.emit_line(" border:none;" )
style += common.emit_line(" visibility: hidden;" )
style += common.emit_line("}")
# content...
content = "<img id=\"%s\" src=\"%s\" alt=\"TheStudio\" />\n" % (hid, src)
# scriptlet dct...
scriptlet_dct = {}
scriptlet_dct['on'] = "document.getElementById('%s').style.visibility='visible';" % hid
scriptlet_dct['off'] = "document.getElementById('%s').style.visibility='hidden';" % hid
scriptlet_dct['init'] = "document.getElementById('%s').style.visibility='visible';" % hid
return [ style, content, scriptlet_dct ]
def cpo_expand_caption_item( accum_ids, parent, asset_def, cp_dct, cpo_dct, images_dct, init_item, action_scripts ):
print "CPO EXPAND CAPTION->", asset_def, cpo_dct.keys()
typ = asset_def["type"]
x = int(asset_def['x'])
y = int(asset_def['y'])
z = int(asset_def['z'])
name = asset_def['asset_name']
hid = common.get_id( name, accum_ids )
# get the individual images and create ids...
img_init_asset = images_dct[init_item][0]
path = img_init_asset['path']
fname = img_init_asset['filename']
src = os.path.join(path,fname)
src = common.path_replace( src )
src = common.create_path( src )
print "init src->", src
# style...
style = ""
style += common.emit_line("#%s {" % hid )
style += common.emit_line(" position: absolute;")
style += common.emit_line(" top: %dpx;" % y )
style += common.emit_line(" left: %dpx;" % x )
style += common.emit_line(" z-index: %d;" % (z+1) )
style += common.emit_line(" border:none;" )
style += common.emit_line(" visibility: hidden;" )
style += common.emit_line("}")
# content...
content = "<img id=\"%s\" src=\"%s\" alt=\"TheStudio\" />\n" % (hid, src)
# scriptlet dct...
scriptlet_dct = {}
scriptlet_dct['on'] = "document.getElementById('%s').style.visibility='visible';" % hid
scriptlet_dct['off'] = "document.getElementById('%s').style.visibility='hidden';" % hid
scriptlet_dct['init'] = "document.getElementById('%s').style.visibility='visible';" % hid
return [ style, content, scriptlet_dct ]
def cpo_expand_option_item( accum_ids, parent, asset_def, cpo_dct, images_dct, init_option, action_scripts ):
print "CPO EXPAND->", asset_def, cpo_dct.keys()
typ = asset_def["type"]
x = int(asset_def['x'])
y = int(asset_def['y'])
z = int(asset_def['z'])
name = asset_def['asset_name']
hid = common.get_id( name, accum_ids )
# get the option asset...
cpo_asset = cpo_dct[ name ][0]
# get the individual images and create ids...
img_desel = cpo_asset['deselected']
desel_id = "%s_desel" % hid
img_sel = cpo_asset['selected']
sel_id = "%s_sel" % hid
img_preview = cpo_asset['preview']
# desel style...
style = ""
style += common.emit_line("#%s {" % desel_id )
style += common.emit_line(" position: absolute;")
style += common.emit_line(" top: %dpx;" % y )
style += common.emit_line(" left: %dpx;" % x )
style += common.emit_line(" z-index: %d;" % (z+1) )
style += common.emit_line(" border:none;" )
style += common.emit_line(" visibility: hidden;" )
style += common.emit_line("}")
# sel style...
style += common.emit_line("#%s {" % sel_id )
style += common.emit_line(" position: absolute;")
style += common.emit_line(" top: %dpx;" % y )
style += common.emit_line(" left: %dpx;" % x )
style += common.emit_line(" z-index: %d;" % z )
style += common.emit_line(" border:none;" )
style += common.emit_line(" visibility: hidden;" )
style += common.emit_line("}")
# create scriptlet dcts...
master_scr_dct = []
scriptlet_dct = {}
scriptlet_dct['on'] = "document.getElementById('%s').style.visibility='visible';" % desel_id
scriptlet_dct['off'] = "document.getElementById('%s').style.visibility='hidden';" % desel_id
scriptlet_dct['init'] = "document.getElementById('%s').style.visibility='visible';" % desel_id
master_scr_dct.append( scriptlet_dct )
scriptlet_dct = {}
scriptlet_dct['on'] = "document.getElementById('%s').style.visibility='visible';" % sel_id
scriptlet_dct['off'] = "document.getElementById('%s').style.visibility='hidden';" % sel_id
scriptlet_dct['init'] = "document.getElementById('%s').style.visibility='visible';" % sel_id
master_scr_dct.append( scriptlet_dct )
# create the content...
content = ""
# desel...
img_desel_asset = images_dct[img_desel][0]
path = img_desel_asset['path']
fname = img_desel_asset['filename']
src = os.path.join(path,fname)
src = common.path_replace( src )
content += "<a href=\"#\" >\n"
#content += "<img id=\"%s\" src=\"%s\" alt=\"TheStudio\" onclick=\"%s;\" onmouseover=\"%s;\" onmouseout=\"%s;\" />\n" % \
#(desel_id, src, "%s_click()" % desel_id, "%s_mouseover()" % desel_id, "%s_mouseout()" % desel_id )
content += "<img id=\"%s\" src=\"%s\" alt=\"TheStudio\" onclick=\"%s;\" />\n" % \
(desel_id, src, "%s_click()" % desel_id )
content += "</a>\n"
# sel...
img_sel_asset = images_dct[img_sel][0]
path = img_sel_asset['path']
fname = img_sel_asset['filename']
src = os.path.join(path,fname)
src = common.path_replace( src )
content += "<a href=\"#\" >\n"
#content += "<img id=\"%s\" src=\"%s\" alt=\"TheStudio\" onclick=\"%s;\" onmouseover=\"%s;\" onmouseout=\"%s;\" />\n" % \
#(sel_id, src, "%s_click()" % sel_id, "%s_mouseover()" % sel_id, "%s_mouseout()" % sel_id )
content += "<img id=\"%s\" src=\"%s\" alt=\"TheStudio\" onclick=\"%s;\" />\n" % \
(sel_id, src, "%s_click()" % sel_id )
content += "</a>\n"
return [ style, content, master_scr_dct ]
def expand_item( accum_ids, asset_def, images_dct, movies_dct, movie_panels_dct, click_panels_dct, cpo_dct ):
print "CLICK PANELS EXPAND->", asset_def, asset_def["asset_name"], "cp->",click_panels_dct.keys(), "cpo->", cpo_dct.keys()
asset_name = asset_def["asset_name"]
item_def = click_panels_dct[asset_name]
print "ITEM DEF->", item_def
tot_style = ""
tot_content = ""
tot_on = ""
tot_off = ""
init_script = ""
# get the init option...
init_option = asset_def['init']
print "init_option->", init_option
# find the main preview item...
preview_def = None
for item in item_def:
asn = item["asset_name"]
typ = item["type"]
if asn.startswith("cpo") and (typ=="preview"):
preview_def = item
break
if not preview_def:
print "ERROR: gen_click_panels: Could not find preview item"
sys.exit(1)
preview_id = preview_def['asset_name']
# find the main caption item...
caption_def = None
for item in item_def:
asn = item["asset_name"]
typ = item["type"]
if asn.startswith("cpo") and (typ=="caption"):
caption_def = item
break
if not caption_def:
print "ERROR: gen_click_panels: Could not find caption item"
sys.exit(1)
caption_id = caption_def['asset_name']
# prepare an array which has all the sel/desel assets...
sel_arr = "var %s_sel_arr = [ " % asset_name
desel_arr = "var %s_desel_arr = [ " % asset_name
f_arr = "var %s_func_arr = [ " % asset_name
for item in item_def:
asn = item["asset_name"]
typ = item["type"]
if asn.startswith("cpo") and (typ=="option"):
sel_arr += " '%s_sel'" % asn + ","
desel_arr += " '%s_desel'" % asn + ","
f_arr += "%s_desel_click" % asn + ","
sel_arr = sel_arr[:-1]
desel_arr = desel_arr[:-1]
f_arr = f_arr[:-1]
sel_arr += " ];"
desel_arr += " ];"
f_arr += " ]";
# prepare action script dct...
action_scripts = {}
action_scripts['sel_arr'] = sel_arr
action_scripts['desel_arr'] = desel_arr
action_scripts['func_arr'] = f_arr
action_scripts['common_next'] = "function %s_cp_next() { var nidx = %s_idx +1; if (nidx == %s_sel_arr.length) nidx = 0; %s_cp_select(nidx); }" % \
(asset_name, asset_name, asset_name, asset_name )
action_scripts['common_prev'] = "function %s_cp_prev() { var nidx = %s_idx-1; if (nidx<0) nidx= %s_sel_arr.length-1; " % (asset_name, asset_name, asset_name ) + \
"%s_cp_select(nidx); }" % (asset_name)
action_scripts['common_select'] = "function %s_cp_select(idx) {\n" % asset_name + \
" %s_func_arr[ idx ]();\n" % asset_name + \
" %s_idx = idx;\n" % asset_name + \
"}"
#action_scripts['common_select'] = "function %s_cp_select(idx) { " % asset_name + \
# "hide(%s_sel);show(%s_desel);\n" % (asset_name, asset_name) + \
# "%s_sel = %s_sel_arr[idx];%s_desel = %s_desel_arr[idx];" % (asset_name, asset_name, asset_name, asset_name ) + \
# "hide(%s_desel);show(%s_sel);\n" % (asset_name,asset_name) + \
#"%s_idx = idx;" % (asset_name) + \
#"} "
action_scripts['common_show'] = "function show(id) { if (id!=null) document.getElementById(id).style.visibility='visible';}"
action_scripts['common_hide'] = "function hide(id) { if (id!=null) document.getElementById(id).style.visibility='hidden';}"
action_scripts['common_preview'] = "function preview(id,path,capid,cappath) { document.getElementById(id).src = path; document.getElementById(capid).src=cappath;}"
action_scripts['global'] = "var %s_sel = null; var %s_desel = null; var %s_idx = 0;" % (asset_name, asset_name, asset_name)
for item in item_def:
asn = item["asset_name"]
if asn.startswith("cpo"):
typ = item["type"]
if typ != "option": continue
asn_def= cpo_dct[asn][0]
img_desel = asn_def['deselected']
img_sel = asn_def['selected']
img_preview = asn_def['preview']
img_caption = asn_def['caption']
# get path to img preview...
print "IMAGES->", asn, item, images_dct.keys()
img_preview_asset = images_dct[img_preview][0]
path = img_preview_asset['path']
fname = img_preview_asset['filename']
src = os.path.join(path,fname)
src = common.path_replace( src )
# get path to caption...
img_caption_asset = images_dct[img_caption][0]
print "img->",img_caption_asset
path = img_caption_asset['path']
fname = img_caption_asset['filename']
capsrc = os.path.join(path,fname)
capsrc = common.path_replace( capsrc )
# get the index...
cp_idx = asn_def['index']
desel_id = "%s_desel" % asn
sel_id = "%s_sel" % asn
# do desel scripts...
action_scripts["%s_desel_click" % asn] = "function %s_desel_click() " % asn + \
"{ show( %s_desel ); hide( %s_sel ); show( '%s' ); hide( '%s' ); " % \
( asset_name, asset_name, sel_id, desel_id ) + \
" %s_sel = '%s'; %s_desel = '%s'; " % ( asset_name, sel_id, asset_name, desel_id ) + \
"preview( '%s','%s','%s','%s');} " % (preview_id, src, caption_id, capsrc)
# do sel scripts...
action_scripts["%s_sel_click" % asn] = "function %s_sel_click() {} " % asn
for item in item_def:
asn = item["asset_name"]
typ = item["type"]
if asn.startswith("cpo") and (typ=="option"):
# expand the cpo item...
style, content, master_dct = cpo_expand_option_item( accum_ids, asset_name, item, cpo_dct, images_dct, init_option, action_scripts )
tot_style += style
tot_content += content
# desel...
tot_on += master_dct[0]['on']
tot_off += master_dct[0]['off']
init_script += master_dct[0]['init']
# sel...
tot_on += master_dct[1]['on']
tot_off += master_dct[1]['off']
init_script += master_dct[1]['init']
elif asn.startswith("cpo") and (typ=="preview"):
init_img = item['init']
# expand the cpo item...
style, content, scriptlet_dct = \
cpo_expand_preview_item( accum_ids, asset_name, item, click_panels_dct, cpo_dct, images_dct, init_img, action_scripts )
tot_style += style
tot_content += content
# desel...
tot_on += scriptlet_dct['on']
tot_off += scriptlet_dct['off']
init_script += scriptlet_dct['init']
elif asn.startswith("cpo") and (typ=="caption"):
init_img = item['init']
# expand the cpo item...
style, content, scriptlet_dct = \
cpo_expand_caption_item( accum_ids, asset_name, item, click_panels_dct, cpo_dct, images_dct, init_img, action_scripts )
tot_style += style
tot_content += content
# desel...
tot_on += scriptlet_dct['on']
tot_off += scriptlet_dct['off']
init_script += scriptlet_dct['init']
else:
print "ERROR: Click_Panel: Cannot process asset->", item
sys.exit(0)
scriptlet_dct = {}
scriptlet_dct['on'] = tot_on
scriptlet_dct['off'] = tot_off
scriptlet_dct['init'] = init_script
if init_option:
scriptlet_dct['init'] += "show('%s');hide('%s');" % ( '%s_sel' % init_option, '%s_desel' % init_option ) + \
"cp_photos_sel = '%s'; cp_photos_desel = '%s';" % ( '%s_sel' % init_option, '%s_desel' % init_option )
print scriptlet_dct['init']
load_script = ""
for key in action_scripts.keys():
load_script += action_scripts[key] + "\n"
return [ tot_style, tot_content, load_script, scriptlet_dct ]
if __name__ == "__main__":
dct = get_dct()
print dct