Annotation of lise/Extensions/liseScript Kopie.py, revision 1.1.1.1

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

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