File:  [Repository] / lise / Extensions / liseScript.py
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Fri Apr 23 16:25:09 2004 UTC (20 years, 2 months ago) by wischi
Branches: MAIN
CVS tags: HEAD
new version

    1: import os
    2: 
    3: def liseScript(mainobj, idclicked="0"):
    4: 	""" liseScript """
    5: 		
    6: 		
    7: 	pictid = int(idclicked) - 1
    8: 	if pictid < 0:
    9: 		pictid = 0
   10: 
   11: 	session = mainobj.REQUEST.SESSION
   12: 	pagelist = mainobj.pagelist
   13: 	pagelistlen = len(pagelist)
   14: 
   15: 	openchaplist = session.get("openchaplist", [])
   16: 	newopenchaplist = 0
   17: 	if len(openchaplist) < 1:
   18: 		newopenchaplist = 1
   19: 		for i in pagelist:
   20: 			if i.level == 0:
   21: 				openchaplist.append(1)
   22: 			else:
   23: 				openchaplist.append(0)
   24: 		
   25: #	openchaplist = []
   26: #	newopenchaplist = 1
   27: 	
   28: 	pagelist = mainobj.pagelist
   29: 	filelist = mainobj.filenames
   30: 	filelistlen = len(filelist)
   31: #	baseurl = mainobj.baseurl
   32: 	filelistindex = 0;
   33: 	
   34: 	# fetch the current picture
   35: 	pictfile = ''
   36: 	if IsStr(pagelist[pictid].picturelink):
   37: 		if len(pagelist[pictid].picturelink) > 0:
   38: 			pictfile = pagelist[pictid].picturelink
   39: 		else:
   40: 			if IsInt(pagelist[pictid].pictindex):
   41: 				filelistindex = int(pagelist[pictid].pictindex)
   42: 				if filelistindex < filelistlen:
   43: 					pictfile = filelist[filelistindex]
   44: 				else:
   45: 					pictfile = 'this_is the_no_fucking_picture_error_from_script_1'
   46: 			else:
   47: 				pictfile = 'this_is the_no_fucking_picture_error_from_script_2'
   48: 	else:
   49: 		if IsInt(pagelist[pictid].pictindex):
   50: 			filelistindex = int(pagelist[pictid].pictindex)
   51: 			if filelistindex < filelistlen:
   52: 				pictfile = filelist[filelistindex]
   53: 			else:
   54: 				pictfile = 'this_is the_no_fucking_picture_error_from_script_3'
   55: 		else:
   56: 			pictfile = 'this_is the_no_fucking_picture_error_from_script_4'
   57: 	mainobj.currpict = '<img src="' + pictfile + '" border="0">'
   58: 
   59: 	thelength = len(pagelist)
   60: 	counter = 0
   61: 	currlevel = 0;
   62: 	
   63: 	# build the list which is used to open / close the chapters
   64: 	if pagelist[pictid].type == 'C':
   65: 		for i in pagelist:
   66: 			if newopenchaplist == 0:
   67: 				if counter == pictid:
   68: 					currlevel = pagelist[counter + 1].level
   69: 					if openchaplist[counter + 1] == 0:
   70: 						for j in range(counter + 1, thelength):
   71: 							if pagelist[j].level < currlevel:
   72: 								break;
   73: 							else:
   74: 								if pagelist[j].level == currlevel:
   75: 									openchaplist[j] = 1
   76: 					else:
   77: 						if openchaplist[counter + 1] == 1:
   78: 							for j in range(counter + 1, thelength):
   79: 								if pagelist[j].level < currlevel:
   80: 									break;
   81: 								else:
   82: 									openchaplist[j] = 0
   83: 	
   84: 			counter = counter + 1
   85: 		
   86: #	return str(counter)
   87: 			
   88: 	bid = session.getBrowserIdManager().getBrowserId()
   89: 	outtext = ""
   90: 	counter = 0
   91: 	for i in pagelist:
   92: 		if openchaplist[counter] == 1:
   93: 			for j in range(0, i.level):
   94: 					outtext = outtext + "&nbsp;&nbsp;&nbsp;"		
   95: 			outtext = outtext + "<a href=\"main?theid=" + str(i.id) +"\">" + i.name + "</a><br>"
   96: 		counter = counter + 1
   97: 		
   98: 	outtext = outtext + "</p>"
   99: 		
  100: 	# write back list of open pages to session
  101: 	session["openchaplist"] = openchaplist
  102: 	
  103: 	return outtext
  104: 	
  105: 
  106: 
  107: ########################################################################################
  108: def IsInt(str):
  109: 	""" Is the given string an Integer? """
  110: 	try: int(str)
  111: 	except ValueError:
  112: 		return 0
  113: 	else:
  114: 		return 1
  115: 
  116: 
  117: ########################################################################################
  118: def IsStr(str):
  119: 	""" Is the given string really a string? """
  120: 	try: str + ''
  121: 	except: return 0
  122: 	else: return 1

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>