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 ago) by wischi
Branches: MAIN
CVS tags: HEAD
new version

import os

def liseScript(mainobj, idclicked="0"):
	""" liseScript """
		
		
	pictid = int(idclicked) - 1
	if pictid < 0:
		pictid = 0

	session = mainobj.REQUEST.SESSION
	pagelist = mainobj.pagelist
	pagelistlen = len(pagelist)

	openchaplist = session.get("openchaplist", [])
	newopenchaplist = 0
	if len(openchaplist) < 1:
		newopenchaplist = 1
		for i in pagelist:
			if i.level == 0:
				openchaplist.append(1)
			else:
				openchaplist.append(0)
		
#	openchaplist = []
#	newopenchaplist = 1
	
	pagelist = mainobj.pagelist
	filelist = mainobj.filenames
	filelistlen = len(filelist)
#	baseurl = mainobj.baseurl
	filelistindex = 0;
	
	# fetch the current picture
	pictfile = ''
	if IsStr(pagelist[pictid].picturelink):
		if len(pagelist[pictid].picturelink) > 0:
			pictfile = pagelist[pictid].picturelink
		else:
			if IsInt(pagelist[pictid].pictindex):
				filelistindex = int(pagelist[pictid].pictindex)
				if filelistindex < filelistlen:
					pictfile = filelist[filelistindex]
				else:
					pictfile = 'this_is the_no_fucking_picture_error_from_script_1'
			else:
				pictfile = 'this_is the_no_fucking_picture_error_from_script_2'
	else:
		if IsInt(pagelist[pictid].pictindex):
			filelistindex = int(pagelist[pictid].pictindex)
			if filelistindex < filelistlen:
				pictfile = filelist[filelistindex]
			else:
				pictfile = 'this_is the_no_fucking_picture_error_from_script_3'
		else:
			pictfile = 'this_is the_no_fucking_picture_error_from_script_4'
	mainobj.currpict = '<img src="' + pictfile + '" border="0">'

	thelength = len(pagelist)
	counter = 0
	currlevel = 0;
	
	# build the list which is used to open / close the chapters
	if pagelist[pictid].type == 'C':
		for i in pagelist:
			if newopenchaplist == 0:
				if counter == pictid:
					currlevel = pagelist[counter + 1].level
					if openchaplist[counter + 1] == 0:
						for j in range(counter + 1, thelength):
							if pagelist[j].level < currlevel:
								break;
							else:
								if pagelist[j].level == currlevel:
									openchaplist[j] = 1
					else:
						if openchaplist[counter + 1] == 1:
							for j in range(counter + 1, thelength):
								if pagelist[j].level < currlevel:
									break;
								else:
									openchaplist[j] = 0
	
			counter = counter + 1
		
#	return str(counter)
			
	bid = session.getBrowserIdManager().getBrowserId()
	outtext = ""
	counter = 0
	for i in pagelist:
		if openchaplist[counter] == 1:
			for j in range(0, i.level):
					outtext = outtext + "&nbsp;&nbsp;&nbsp;"		
			outtext = outtext + "<a href=\"main?theid=" + str(i.id) +"\">" + i.name + "</a><br>"
		counter = counter + 1
		
	outtext = outtext + "</p>"
		
	# write back list of open pages to session
	session["openchaplist"] = openchaplist
	
	return outtext
	


########################################################################################
def IsInt(str):
	""" Is the given string an Integer? """
	try: int(str)
	except ValueError:
		return 0
	else:
		return 1


########################################################################################
def IsStr(str):
	""" Is the given string really a string? """
	try: str + ''
	except: return 0
	else: return 1

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