Annotation of lise/Extensions/liseScript Kopie.py, revision 1.2
1.1 wischi 1: import os
2:
3: def liseScript(mainobj, idclicked="0"):
4: """ liseScript """
5:
1.2 ! wischi 6:
1.1 wischi 7: pictid = int(idclicked) - 1
8: if pictid < 0:
9: pictid = 0
10:
11: session = mainobj.REQUEST.SESSION
1.2 ! wischi 12: pagelist = mainobj.pagelist
! 13: pagelistlen = len(pagelist)
! 14:
1.1 wischi 15: openchaplist = session.get("openchaplist", [])
16: newopenchaplist = 0
17: if len(openchaplist) < 1:
18: newopenchaplist = 1
1.2 ! wischi 19: for i in pagelist:
! 20: if i.level == 0:
! 21: openchaplist.append(1)
! 22: else:
! 23: openchaplist.append(0)
! 24:
1.1 wischi 25: # openchaplist = []
26: # newopenchaplist = 1
27:
28: pagelist = mainobj.pagelist
29: filelist = mainobj.filenames
1.2 ! wischi 30: filelistlen = len(filelist)
! 31: # baseurl = mainobj.baseurl
1.1 wischi 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)
1.2 ! wischi 42: if filelistindex < filelistlen:
! 43: pictfile = filelist[filelistindex]
! 44: else:
! 45: pictfile = 'this_is the_no_fucking_picture_error_from_script_1'
1.1 wischi 46: else:
1.2 ! wischi 47: pictfile = 'this_is the_no_fucking_picture_error_from_script_2'
1.1 wischi 48: else:
49: if IsInt(pagelist[pictid].pictindex):
50: filelistindex = int(pagelist[pictid].pictindex)
1.2 ! wischi 51: if filelistindex < filelistlen:
! 52: pictfile = filelist[filelistindex]
! 53: else:
! 54: pictfile = 'this_is the_no_fucking_picture_error_from_script_3'
1.1 wischi 55: else:
1.2 ! wischi 56: pictfile = 'this_is the_no_fucking_picture_error_from_script_4'
! 57: mainobj.currpict = '<img src="' + pictfile + '" border="0">'
1.1 wischi 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:
1.2 ! wischi 66: if newopenchaplist == 0:
1.1 wischi 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
1.2 ! wischi 83:
1.1 wischi 84: counter = counter + 1
85:
1.2 ! wischi 86: # return str(counter)
1.1 wischi 87:
88: bid = session.getBrowserIdManager().getBrowserId()
1.2 ! wischi 89: outtext = "pictnum" + str(pictid) + "<br>" + "pict: " + pagelist[pictid].picturelink + "<br>"
1.1 wischi 90: counter = 0
91: for i in pagelist:
92: if openchaplist[counter] == 1:
93: for j in range(0, i.level):
94: outtext = outtext + " "
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>