Example #1
0
def mouse_script_item( srcid, val, images_dct ):
	anim = val.split(":")
        a = anim[0]
        b = anim[1]
        if (b=="show"):
                nm = a
                info = images_dct.has_key(nm)
                fpath = os.path.join( info['path'], info['filename'] )
		fpath = common.path_replace(fpath)
		fpath = common.get_path( fpath )
                script = "document.getElementById('%s').style.visibility='visible';document.getElementById('%s').src='%s'" % (nm,nm,fpath)
		return script
        elif ( b=="hide"):
                nm = a
                script = "document.getElementById('%s').style.visibility='hidden';" % nm
		return script
        elif ( b=="replace" ):
                nm = a
                info = images_dct[nm][0]
                fpath = os.path.join( info['path'], info['filename'] )
		fpath = common.path_replace( fpath )
                script = "document.getElementById('%s').style.visibility='visible';document.getElementById('%s').src='%s'" % (srcid,srcid,fpath)
        	return script
	else:
		print "WARNING: Nothing for mouse script item"
		return ""
Example #2
0
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 = common.path_replace(fpath)
	return fpath
Example #3
0
def click_script_item( target, operation, src, images_dct ):
        info = images_dct[ src ][0]
        fpath = os.path.join( info['path'], info['filename'] )
	fpath = common.path_replace(fpath)
	fpath = common.create_path( fpath )
        script = "document.getElementById('%s').src='%s';document.getElementById('%s').style.visibility='visible';" % (target,fpath,target)
        return script
Example #4
0
def get_item_path( name, images_dct ):
	print "GIP->", name, images_dct.keys()
        item_def = images_dct[name][0]
	print "ID->", item_def
        path = item_def['path']
        fname = item_def['filename']
	print "PARTS->", path, fname
        fpath = os.path.join(path,fname)
        fpath = common.path_replace(fpath)
        return fpath
Example #5
0
def expand_pinterest( accum_ids, asset_def, embeds_dct, images_dct = None, override_link=None, override_image=None ):

        asset_name = asset_def["asset_name"]

        # get id...
        htmlid = common.get_id(asset_name,accum_ids)
        accum_ids.append( htmlid )

        # get parms...
        x = get_attr( 'x', asset_name, asset_def, embeds_dct )
        y = get_attr( 'y', asset_name, asset_def, embeds_dct )
        z = get_attr( 'z', asset_name, asset_def, embeds_dct,'0')
        if override_link:
                link = override_link
        else:
                link = get_attr( 'link', asset_name, asset_def, embeds_dct,'http://www.pinterest.com')
                link = common.site_replace(link)


        if override_image:
                image = override_image
        else:
		image = get_attr( 'image', asset_name, asset_def, embeds_dct, 'http://thestudio.codetodesign.com/content_7_6_2012/main_logo4.png' )
		image = common.site_replace( image )

	# possibly use img path...
	br1 = image.find("[") 
	br2 = image.find("]")
	if (br1>=0) and (br2>=0):
		imgref = image[br1:(br2+1)]
		imgref = imgref[1:-1]	
		print images_dct
		pathimg = get_img_path( imgref, images_dct )
		image = image[0:br1] + pathimg + image[br2+1:]
		print "ref->",imgref, pathimg, image
	else:
		image = common.path_replace( image)
	
        f = open("embeds/pinterest.txt",'r')
        tmpl = f.read()
        f.close()
        txt = tmpl.replace("HTMLID",htmlid)
	link = urllib2.quote(link)
	link = link.replace( "/", "%2F" )
        txt = txt.replace("LINK",link)
	image = urllib2.quote(image)
	image = image.replace( "/", "%2F" )
	txt = txt.replace("IMAGE", image)

        style = "#%s { position:absolute;top:%dpx;left:%dpx;z-index:%d;} " % (asset_name, int(y), int(x), int(z) )
        content = txt
        scriptlet_dct = { "on":"", "off":"", "init":"" }
        return [ style, content, "", scriptlet_dct ]
Example #6
0
def expand_caption( accum_ids, asset_def ):

        print "IMAGE SET EXPAND CAPTION", asset_def

        # get the asset definition...
        asset_name = asset_def["asset_name"] + "_cap"
        item_def = asset_def

        # get id...
        htmlid = common.get_id(asset_name,accum_ids)
        accum_ids.append( htmlid )
	
	# get cap path...
	cap_path = asset_def['cap_path']
	capfile = asset_def['cap_file']
	print "caps->", cap_path, capfile
	capsrc = os.path.join( cap_path, capfile )
	capsrc = common.path_replace(capsrc)

	# compute the coord...
	centerx = 1067
	centery = 371
	capw = asset_def['cap_width']
	caph = asset_def['cap_height']
	x = centerx - (int)(capw*1.0/2)
	y = centery - (int)(caph*1.0/2)

	# get z...
	z = 3

        # style...
        style  = ""
        style += common.emit_line( "#%s {" % htmlid )
        style += common.emit_line( "position: absolute;")
        style += common.emit_line( "left: %dpx;" % int(x) )
        style += common.emit_line( "top: %dpx;" % int(y) )
        style += common.emit_line( "z-index: %d;" % int(z) )
        style += common.emit_line( "}" )

        # content...
        content = ""
	content += common.emit_line( "<img id=%s src=\"%s\" alt=\"TheStudio\" >" % (htmlid, capsrc) )

        scriptlet_dct = {}
        scriptlet_dct['on'] = "document.getElementById('%s').style.visibility = '%s';" % (htmlid, 'visible' )
        scriptlet_dct['off']  = "document.getElementById('%s').style.visibility = '%s';" % (htmlid, 'hidden' )
        scriptlet_dct['init'] = "document.getElementById('%s').style.visibility = '%s';" % (htmlid, 'visible' )

        return [ style, content, "", scriptlet_dct ]
Example #7
0
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 ]
Example #8
0
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]
Example #9
0
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 action script dct...
        action_scripts = {}
	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;" % (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 )

			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 ]
Example #10
0
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 gen_page_set( multipage_def, multipage_style, multipage_content, mp_dct, movies_dct, img_dct, is_dct, embeds_dct ):

	#print "GEN_PAGE_SET"

	# find the is and the rest...
	is_def = None
	remaining_defs = []
	for page_def in multipage_def:
                if page_def['asset_name'].startswith("is"):
                        is_def = page_def
		else:
			remaining_defs.append( page_def )

	#print "MPC->", multipage_content
	#sys.exit(1)

	# expand the IS...
	asset_defs = gen_image_set.expand_def( is_dct, is_def )
	for asset in asset_defs:
			
		accum_ids = []

		# intialize page style and content from template...
		tot_style = multipage_style
		tot_content = multipage_content
		tot_on = ""
		tot_off = ""

		cur_page_name = asset['page_name']
		cur_asset_path = os.path.join( asset['path'], asset['filename'] )
		cur_asset_path = common.path_replace( cur_asset_path )
		print  cur_asset_path
	
		alldefs = remaining_defs + [ asset ]
		for page_def in alldefs:

                	# expand each asset...
                	if page_def['asset_name'].startswith("img"):
				# determine the script, if any...
                        	script = None
                        	ahref = None
				exturl = None

				aname = page_def["asset_name"]
				#print "ANAME=", aname
				if aname == "img_jsr":
					print "JSR!"
					sys.exit(1)

				#print "MSS IMG DEF->", page_def
                        	if page_def.has_key("link") and page_def["link"]!="":
                                	link = page_def["link"]
					#print "LINK PAGE DEF->", link, page_def.keys(), page_def['asset_name'], page_def['link']
                                	if link.startswith("option:"):
                                        	ltype,parm = link.split(":")
                                        	funcname = "func_%s_%s" % (menu_name, parm)
                                        	test = action_scripts[funcname]
                                        	script = "%s ();" % funcname
                                	elif link.startswith("url:"):
                                        	idx = link.find(":") + 1
                                        	ahref = link[idx:]
                                	elif link.startswith("nurl:"):
                                        	idx = link.find(":") + 1
                                        	ahref = link[idx:]
                                        	exturl = True
					elif link.startswith("mss"):
                                        	idx = link.find(":") + 1
						directive = link[idx:]
						ahref = get_link( page_def, is_dct, directive, cur_page_name )
						#print "MS LINK->", ahref
						if ( ahref == "sarah11.html" ):
							exit(1)
                                	else:
                                        	print "ERROR: multipage_slide_show: Unknown link type", page_def
						sys.exit(1)

                        	style, content, foo, scriptlet_dct = gen_images.expand_item( accum_ids, page_def, img_dct, script, None, ahref, exturl )

                        	tot_style += style
                        	tot_content += content
				tot_on += scriptlet_dct["on"]
				tot_off += scriptlet_dct["off"]

			elif page_def.has_key('type') and page_def['type'] == "image_set":

				# Note, we are requiring a valid cap file...
                                if page_def.has_key('cap_file') and page_def['cap_file']!=None:
					print "WARNING: Got cap file->", page_def['cap_file']	
				else:	
					print "WARNING: No cap file->", page_def
					time.sleep(2)
					continue

				style, content, foo, scriptlet_dct = gen_image_set.expand_item( accum_ids, page_def, is_dct, None, None, None )
				#print "CONTENT->", content

                        	tot_style += style
                        	tot_content += content
				tot_on += scriptlet_dct["on"]
				tot_off += scriptlet_dct["off"]

				# expand the caption too...
                                if page_def.has_key('cap_path'):
					style, content, foo, scriptlet_dct = \
						gen_image_set.expand_caption( accum_ids, page_def )
                                	tot_style += style
                                	tot_content += content
                                	tot_on += scriptlet_dct["on"]
                                	tot_off += scriptlet_dct["off"]

			elif page_def['asset_name'].startswith("embed"):

				#print cur_page_name
				#print page_def

				override_link = common.SITE + "/" + cur_page_name + ".html"
				override_image = common.SITE + "/" + cur_asset_path
				#print override_link, override_image

				style, content, foo, scriptlet_dct = gen_embeds.expand_item( accum_ids, page_def, embeds_dct, img_dct, override_link, override_image )
                                tot_style += style
                                tot_content += content
                                tot_on += scriptlet_dct["on"]
                                tot_off += scriptlet_dct["off"]

			else:
				print "ERROR: gen_multipage_slideshow: Cannot process this asset type->", page_def
				sys.exit(1)

		# create all the html content...
		style = "%s" % (tot_style)
		content = tot_content
		head_script = "" #subpage_head_script
		load_script  = tot_on #subpage_load_script

		# get the page name...
		page_name = asset['page_name']

		# write the file...
		common.gen_page( "%s.html" % page_name, style, "", content, head_script, load_script )
Example #12
0
def expand_def( dct, item_def ):
	asset_name = item_def['asset_name']
	deff = dct[ asset_name ][0]

	#print "EXPAND DEF->", item_def, asset_name, dct.keys(), deff
	path = deff["path"]

	# get alt entries...
	altpath = deff["alt_path"]
	altfiles = {}
	if (altpath!=""):
		altfiles = deff["alt_files"].split(";")
		pairs = [ a.split(":") for a in altfiles ]
		print "expand def->", pairs
		altfiles = dict( pairs )
		altpath = common.path_replace( altpath )

	# fixup path...
	spath = path.replace("PHIL",PHIL_PREFIX)

	if os.path.exists(spath):
		fnames = os.listdir(spath)
		#print "FNAMES->", fnames

		asset_defs = []
		for f in fnames:
			if f.startswith(".B"): continue
			if f.endswith("pdf"): continue
			ad = copy.deepcopy( item_def )
			
			ad['path'] = path
			ad['filename'] = f

			# possibly use an altpath...
			if f in altfiles.keys():
				substf = altfiles[f]
				substp = altpath
				print "WARNING: substitute->", f,substf
				ad['path'] = substp
				ad['filename'] = substf

			ad['page_name'] = ad['filename'].split(".")[0]
			ad['asset_name'] = ad['page_name']
			ad['type'] = 'image_set'

			# caption?...
			if deff.has_key('cap_path'):
				cap_path = deff["cap_path"]
				info = gen_lookup.get_cap_file(f)
				if info!=None:
					print info
					[ capfile, width, height ] = info
					ad['cap_width'] = width
					ad['cap_height'] = height
					ad['cap_path'] = cap_path
					ad['cap_file'] = capfile

					# check for subst...
					alt_cap_path = deff['alt_cap_path']
					_alt_cap_files = deff['alt_cap_files']
					if _alt_cap_files != "":
						alt_cap_files = _alt_cap_files.split(";")
						alt_cap_files = [ a.split(":") for a in alt_cap_files ]
						print alt_cap_files
						alt_cap_files = dict( alt_cap_files )
						alt_cap_path = common.path_replace( alt_cap_path )
						if capfile in alt_cap_files.keys():
							ad['cap_file'] = alt_cap_files[ capfile ]
							ad['cap_path'] = alt_cap_path
							print ad

			asset_defs.append( ad )

		return asset_defs

	else:
		filename = deff["filename"]
		fidx = filename.find("[")
		eidx = filename.find("]")
		regexpr = filename[0:fidx] + "%02d" + filename[eidx+1:]	
		seg = filename[fidx+1:eidx]
		parts = seg.split("-")
		start = int( parts[0] )
		end = int( parts[1] )
		asset_defs = []
		for i in range(start,end+1):
			ad = copy.deepcopy( item_def )
			ad['path'] = path
			ad['filename'] = regexpr % i
			ad['page_name'] = ad['filename'].split(".")[0]
			ad['asset_name'] = ad['page_name']
			ad['type'] = 'image_set'
			asset_defs.append( ad )
		return asset_defs
Example #13
0
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]